fin control panel
This commit is contained in:
parent
0aad260946
commit
0ff6508d2f
@ -65,6 +65,8 @@ router.post('/api/print', KoaBody(), async (c, n) => {
|
|||||||
c.async = true
|
c.async = true
|
||||||
let arr = c.request.body
|
let arr = c.request.body
|
||||||
if (!arr.data) throw 'print data empty'
|
if (!arr.data) throw 'print data empty'
|
||||||
|
if (config.api.secret && !arr.key) throw 'access key enpty'
|
||||||
|
if (config.api.secret !== arr.key.trim()) throw 'access key error'
|
||||||
|
|
||||||
let status = await Printer.printerString(arr.data)
|
let status = await Printer.printerString(arr.data)
|
||||||
|
|
||||||
@ -117,6 +119,8 @@ router.post('/api/print', KoaBody(), async (c, n) => {
|
|||||||
json.printer.serial = arr.tty
|
json.printer.serial = arr.tty
|
||||||
json.printer.feed = feed
|
json.printer.feed = feed
|
||||||
|
|
||||||
|
json.api.secret = arr.secret || ''
|
||||||
|
|
||||||
let wconfig = await new Promise((resolve, reject) => {
|
let wconfig = await new Promise((resolve, reject) => {
|
||||||
fs.writeFile(path.resolve(process.env.PROJECT_ROOT, 'config.json'), JSON.stringify(json, null, 2), {
|
fs.writeFile(path.resolve(process.env.PROJECT_ROOT, 'config.json'), JSON.stringify(json, null, 2), {
|
||||||
mode: 0o664,
|
mode: 0o664,
|
||||||
|
@ -103,10 +103,12 @@ let systemStatus = {
|
|||||||
feed: 0
|
feed: 0
|
||||||
},
|
},
|
||||||
pcount: 0,
|
pcount: 0,
|
||||||
lastprint: ''
|
lastprint: '',
|
||||||
|
secret: ''
|
||||||
}
|
}
|
||||||
|
|
||||||
systemStatus.ble.enable = config.ble.enable
|
systemStatus.ble.enable = config.ble.enable
|
||||||
|
systemStatus.secret = config.api.secret
|
||||||
if (config.ble.enable) {
|
if (config.ble.enable) {
|
||||||
systemStatus.ble.mac = await getBTAddr()
|
systemStatus.ble.mac = await getBTAddr()
|
||||||
systemStatus.ble.service = config.ble.uuid.service
|
systemStatus.ble.service = config.ble.uuid.service
|
||||||
|
@ -27,6 +27,12 @@
|
|||||||
<label for="en-ble">啟用藍芽</label>
|
<label for="en-ble">啟用藍芽</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<h3 class="ui dividing header">WebAPI設定</h3>
|
||||||
|
<div class="field">
|
||||||
|
<label for="api-secret">API密鑰</label>
|
||||||
|
<input type="text" name="api-secret" placeholder="請輸入密鑰,空白不設定" id="api-secret">
|
||||||
|
</div>
|
||||||
|
|
||||||
<div style="margin-top: 40px; text-align: right;">
|
<div style="margin-top: 40px; text-align: right;">
|
||||||
<button class="ui button blue" type="submit">送出設定</button>
|
<button class="ui button blue" type="submit">送出設定</button>
|
||||||
@ -75,7 +81,8 @@
|
|||||||
let json = {
|
let json = {
|
||||||
tty: '',
|
tty: '',
|
||||||
feed: 0,
|
feed: 0,
|
||||||
ble: ''
|
ble: '',
|
||||||
|
secret: ''
|
||||||
}
|
}
|
||||||
let dev = getValue(document.querySelector('select#tty'))
|
let dev = getValue(document.querySelector('select#tty'))
|
||||||
let feed = getValue(document.querySelector('input#feed'))
|
let feed = getValue(document.querySelector('input#feed'))
|
||||||
@ -85,10 +92,13 @@
|
|||||||
|
|
||||||
if(!dev) return alert('請選擇印表機連接埠')
|
if(!dev) return alert('請選擇印表機連接埠')
|
||||||
if (!isFinite(feed) || feed < 0) return alert('切紙前空行請輸入整數')
|
if (!isFinite(feed) || feed < 0) return alert('切紙前空行請輸入整數')
|
||||||
|
|
||||||
|
let secret = getValue(document.querySelector('input#api-secret'))
|
||||||
|
|
||||||
json.tty = dev
|
json.tty = dev
|
||||||
json.feed = Math.floor(parseInt(feed))
|
json.feed = Math.floor(parseInt(feed))
|
||||||
json.ble = ble
|
json.ble = ble
|
||||||
|
json.secret = secret
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: '/api/write_config',
|
url: '/api/write_config',
|
||||||
|
@ -2,33 +2,47 @@
|
|||||||
<div class="ui grid">
|
<div class="ui grid">
|
||||||
<div class="column sixteen wide t-right">
|
<div class="column sixteen wide t-right">
|
||||||
<div class="ui segment">
|
<div class="ui segment">
|
||||||
<button class="ui button mini" type="button" id="gen-qr">GenerateQR</button>
|
<button class="ui button mini" type="button" id="gen-api-qr">Generate API QR</button>
|
||||||
|
<button class="ui button mini" type="button" id="gen-ble-qr">Generate BLE QR</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="column eight wide">
|
<div class="column sixteen wide">
|
||||||
<div class="segment ui">
|
<div class="segment ui">
|
||||||
<h4 class="ui header dividing">藍芽狀態</h4>
|
<h4 class="ui header dividing">系統狀態</h4>
|
||||||
<div class="ui divided list">
|
<div class="ui divided list">
|
||||||
<div class="item">
|
<div class="item">
|
||||||
<div class="ui horizontal label basic">啟用狀態</div>
|
<div class="ui horizontal label basic">API Key</div>
|
||||||
<div class="description t-right" id="en-ble">On</div>
|
<div class="description t-right" id="apikey"></div>
|
||||||
</div>
|
|
||||||
<div class="item">
|
|
||||||
<div class="ui horizontal label basic">Mac Address</div>
|
|
||||||
<div class="description t-right" id="ble-mac">00:11:22:33:44:55:66</div>
|
|
||||||
</div>
|
|
||||||
<div class="item">
|
|
||||||
<div class="ui horizontal label basic">ServiceUUID</div>
|
|
||||||
<div class="description t-right" id="ble-service">37B2975E-1A4B-4975-9211-9D47142B8183</div>
|
|
||||||
</div>
|
|
||||||
<div class="item">
|
|
||||||
<div class="ui horizontal label basic">CharacteristicUUID</div>
|
|
||||||
<div class="description t-right" id="ble-character">37B2975E-1A4B-4975-9211-9D47142B8183</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="column eight wide">
|
||||||
|
<div class="segment ui">
|
||||||
|
<h4 class="ui header dividing">藍芽狀態</h4>
|
||||||
|
<div class="ui divided list">
|
||||||
|
<div class="item">
|
||||||
|
<div class="ui horizontal label basic">啟用狀態</div>
|
||||||
|
<div class="description t-right" id="en-ble">On</div>
|
||||||
|
</div>
|
||||||
|
<div class="item">
|
||||||
|
<div class="ui horizontal label basic">Mac Address</div>
|
||||||
|
<div class="description t-right" id="ble-mac">00:11:22:33:44:55:66</div>
|
||||||
|
</div>
|
||||||
|
<div class="item">
|
||||||
|
<div class="ui horizontal label basic">ServiceUUID</div>
|
||||||
|
<div class="description t-right" id="ble-service">37B2975E-1A4B-4975-9211-9D47142B8183</div>
|
||||||
|
</div>
|
||||||
|
<div class="item">
|
||||||
|
<div class="ui horizontal label basic">CharacteristicUUID</div>
|
||||||
|
<div class="description t-right" id="ble-character">37B2975E-1A4B-4975-9211-9D47142B8183</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="column eight wide">
|
<div class="column eight wide">
|
||||||
<div class="segment ui">
|
<div class="segment ui">
|
||||||
<h4 class="ui header dividing">印表機狀態</h4>
|
<h4 class="ui header dividing">印表機狀態</h4>
|
||||||
@ -83,6 +97,8 @@
|
|||||||
characteristic: ''
|
characteristic: ''
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var apikey = ''
|
||||||
|
|
||||||
var ws = new WebSocket('ws://' + location.host)
|
var ws = new WebSocket('ws://' + location.host)
|
||||||
ws.onmessage = msg => {
|
ws.onmessage = msg => {
|
||||||
// console.log(msg)
|
// console.log(msg)
|
||||||
@ -106,6 +122,9 @@
|
|||||||
setting.service = d.ble.service
|
setting.service = d.ble.service
|
||||||
setting.characteristic = d.ble.characteristic
|
setting.characteristic = d.ble.characteristic
|
||||||
|
|
||||||
|
apikey = d.secret
|
||||||
|
$('#apikey').text(apikey)
|
||||||
|
|
||||||
$('#prt-con').text(d.printer.connect ? 'Connected' : 'Disconnected')
|
$('#prt-con').text(d.printer.connect ? 'Connected' : 'Disconnected')
|
||||||
$('#prt-port').text(d.printer.serial)
|
$('#prt-port').text(d.printer.serial)
|
||||||
$('#prt-feed').text(d.printer.feed)
|
$('#prt-feed').text(d.printer.feed)
|
||||||
@ -117,11 +136,11 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$('#gen-qr').click(function () {
|
$('#gen-ble-qr, #gen-api-qr').click(function () {
|
||||||
let qrdiv = document.querySelector('div#qr')
|
let qrdiv = document.querySelector('div#qr')
|
||||||
qrdiv.innerHTML = ''
|
qrdiv.innerHTML = ''
|
||||||
let qr = new QRCode(qrdiv, {
|
let qr = new QRCode(qrdiv, {
|
||||||
text: JSON.stringify(setting, null, 2),
|
text: this.id === 'gen-ble-qr' ? JSON.stringify(setting, null, 2) : JSON.stringify({apikey}, null, 2),
|
||||||
colorDark: "#000000",
|
colorDark: "#000000",
|
||||||
colorLight: "#ffffff",
|
colorLight: "#ffffff",
|
||||||
correctLevel: QRCode.CorrectLevel.L
|
correctLevel: QRCode.CorrectLevel.L
|
||||||
|
@ -29,6 +29,12 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<h3 class="ui dividing header">WebAPI設定</h3>
|
||||||
|
<div class="field">
|
||||||
|
<label for="api-secret">API密鑰</label>
|
||||||
|
<input type="text" name="api-secret" placeholder="請輸入密鑰,空白不設定" id="api-secret">
|
||||||
|
</div>
|
||||||
|
|
||||||
<div style="margin-top: 40px; text-align: right;">
|
<div style="margin-top: 40px; text-align: right;">
|
||||||
<button class="ui button blue" type="submit">送出設定</button>
|
<button class="ui button blue" type="submit">送出設定</button>
|
||||||
</div>
|
</div>
|
||||||
@ -76,7 +82,8 @@
|
|||||||
let json = {
|
let json = {
|
||||||
tty: '',
|
tty: '',
|
||||||
feed: 0,
|
feed: 0,
|
||||||
ble: ''
|
ble: '',
|
||||||
|
secret: ''
|
||||||
}
|
}
|
||||||
let dev = getValue(document.querySelector('select#tty'))
|
let dev = getValue(document.querySelector('select#tty'))
|
||||||
let feed = getValue(document.querySelector('input#feed'))
|
let feed = getValue(document.querySelector('input#feed'))
|
||||||
@ -87,9 +94,12 @@
|
|||||||
if(!dev) return alert('請選擇印表機連接埠')
|
if(!dev) return alert('請選擇印表機連接埠')
|
||||||
if (!isFinite(feed) || feed < 0) return alert('切紙前空行請輸入整數')
|
if (!isFinite(feed) || feed < 0) return alert('切紙前空行請輸入整數')
|
||||||
|
|
||||||
|
let secret = getValue(document.querySelector('input#api-secret'))
|
||||||
|
|
||||||
json.tty = dev
|
json.tty = dev
|
||||||
json.feed = Math.floor(parseInt(feed))
|
json.feed = Math.floor(parseInt(feed))
|
||||||
json.ble = ble
|
json.ble = ble
|
||||||
|
json.secret = secret
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: '/install/write_config',
|
url: '/install/write_config',
|
||||||
|
Loading…
Reference in New Issue
Block a user