Add config module

Also toast for chikin ID
This commit is contained in:
Paul Mathieu 2022-09-11 12:45:48 +02:00
parent 0e67d30c7d
commit 675e060089
3 changed files with 29 additions and 14 deletions

View File

@ -9,6 +9,9 @@ let token = localStorage.getItem('token');
async function getBandz() { async function getBandz() {
const uri = `${backend_api}/bandz`; const uri = `${backend_api}/bandz`;
const res = await $.ajax(uri, {headers: {Authorization: `Bearer ${token}`}}); const res = await $.ajax(uri, {headers: {Authorization: `Bearer ${token}`}});
// if (res.statusCode !== 200) {
// throw res;
// }
return res.bandz; return res.bandz;
} }
@ -66,7 +69,7 @@ $(document).ready(() => {
const action = $('<div class="section">') const action = $('<div class="section">')
.append( .append(
$('<a class="btn" id="send">wrap-a-chikin<i class="material-icons right">send</i></a>') $('<a class="btn disabled" id="send">wrap-a-chikin<i class="material-icons right">send</i></a>')
.click(async () => { .click(async () => {
loader.show(); loader.show();
$('#send').addClass("disabled"); $('#send').addClass("disabled");
@ -79,6 +82,7 @@ $(document).ready(() => {
try { try {
const chikinId = await wrapAChikin(req); const chikinId = await wrapAChikin(req);
M.toast({html: `Wrapped chikin ID ${chikinId}`});
printLabel(chikinId); printLabel(chikinId);
} finally { } finally {
loader.hide(); loader.hide();
@ -101,13 +105,17 @@ $(document).ready(() => {
) )
; ;
appbody.append(block); appbody.append(block);
if (!token || token == 'undefined') {
$('#send').addClass("disabled");
};
getBandz().then(bandz => { getBandz().then(bandz => {
$('select').append(bandz.map(band => `<option value="${band.id}">${band.name}</option>`)); $('select').append(bandz.map(band => `<option value="${band.id}">${band.name}</option>`));
$('select').formSelect(); $('select').formSelect();
$('#send').removeClass("disabled");
}).catch(xhr => {
console.log(xhr);
console.log('blarg');
if (xhr.statusCode === 403) {
M.toast({html: 'Authentication failed.'});
}
}); });
const authBlock = $('<div id="authBlock">').hide() const authBlock = $('<div id="authBlock">').hide()

13
config.js Normal file
View File

@ -0,0 +1,13 @@
const path = require('path');
const accessTokenSecret = 'cecinestpasunecledauthentificationjwt';
const dbFile = path.join(__dirname, "data", "chikinz.db");
const catclient = '/Users/paul/scratch/printer/catclient.py';
const authPassword = 'goldchocoboisbestchocobo.goldchocoboisonlychocobo';
module.exports = {
accessTokenSecret,
dbFile,
catclient,
authPassword,
};

View File

@ -7,10 +7,9 @@ const jwt = require('jsonwebtoken');
const path = require('path'); const path = require('path');
const sqlite3 = require('sqlite3').verbose(); const sqlite3 = require('sqlite3').verbose();
const accessTokenSecret = 'cecinestpasunecledauthentificationjwt'; const {authPassword, accessTokenSecret, dbFile, catclient} = require('./config');
const db_name = path.join(__dirname, "data", "chikinz.db"); const db = new sqlite3.Database(dbFile, err => {
const db = new sqlite3.Database(db_name, err => {
if (err) { if (err) {
return console.error(err.message); return console.error(err.message);
} }
@ -133,7 +132,7 @@ app.get('/bandz', authenticateJWT, async (req, res) => {
app.post('/toktok', (req, res) => { app.post('/toktok', (req, res) => {
const {password} = req.body; const {password} = req.body;
if (password != 'goldchocoboisbestchocobo.goldchocoboisonlychocobo') { if (password != authPassword) {
return res.json({message: 'This is not the way.'}); return res.json({message: 'This is not the way.'});
} }
@ -164,12 +163,7 @@ app.post('/print', authenticateJWT, async (req, res) => {
const price = weight * pricePerKg; const price = weight * pricePerKg;
const line2 = `${pricePerKg.toFixed(2)} €/kg - ${price.toFixed(2)}`; const line2 = `${pricePerKg.toFixed(2)} €/kg - ${price.toFixed(2)}`;
// const args = ['/Users/paul/scratch/printer/catprint.py', const args = [catclient,
// '--address', '0DE203E8-0E8F-4361-9E80-D9C3794612A4',
// '--template0', [qr_url, line0, line1, line2].join(';'),
// '--feed',
// ];
const args = ['/Users/paul/scratch/printer/catclient.py',
'--template0', [qr_url, line0, line1, line2].join(';'), '--template0', [qr_url, line0, line1, line2].join(';'),
'--feed', '--feed',
]; ];