加入狀態畫面

This commit is contained in:
Jay
2017-09-07 17:18:51 +08:00
parent 3c06bf5d8b
commit 97ee7dc6cd
8 changed files with 272 additions and 5 deletions
+40
View File
@@ -0,0 +1,40 @@
/* eslint-disable no-throw-literal */
/* eslint-disable */
const KoaRouter = require('koa-router')
const router = new KoaRouter()
const fs = require('fs')
const path = require('path')
const Printer = require('../PrinterDev')
const KoaBody = require('koa-body')
const uuid = require('uuid')
/* eslint-enable */
router.use(async (c, n) => {
c.data = {
title: 'Printer System Dashboard'
}
let status = 1
try {
await n()
} catch (err) {
status = 0
if (typeof err === 'string') {
c.body = err
} else {
c.body = err.toString()
}
}
if (c.async) {
c.body = {
status,
msg: c.body
}
}
})
router.get('/', async (c, n) => {
await c.render('dashboard/index', c.data)
})
module.exports = router
+2 -2
View File
@@ -65,7 +65,7 @@ router
Printer.feed = feed
let status = await Printer.printTestPage()
if (!status) c.body = '測試失敗'
else c.body = '測試成功'
})
@@ -103,7 +103,7 @@ router
let wconfig = await new Promise((resolve, reject) => {
fs.writeFile(path.resolve(process.env.PROJECT_ROOT, 'config.json'), JSON.stringify(json, null, 2), {
mode: 0664,
mode: 0o664,
encoding: 'utf8',
flag: 'w'
}, err => {