Skip to content

Commit 1ccff69

Browse files
committed
Generate (transparent) + txt file with link
1 parent 99f38f0 commit 1ccff69

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

make_jwt.mjs

+15-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env node
22
// make jwt tokens
33

4-
import { readFileSync, appendFileSync } from 'fs';
4+
import { readFileSync, appendFileSync, writeFileSync } from 'fs';
55
import url from 'url';
66
import jwt from 'jsonwebtoken';
77
import { unix_seconds } from './util.mjs';
@@ -50,21 +50,28 @@ export function make(sub, nbf = null, exp = null) {
5050
}
5151

5252
// Note: nbf_string, exp_string: date strings only used in filename of QR code SVG.
53-
export function save_qr(jwt, base_url='', nbf_string=null, exp_string=null, filename_prefix='qr ') {
53+
export function save_qr(jwt, base_url='', nbf_string=null, exp_string=null, filename_prefix='qr ', type='svg') {
5454
const payload = verify(jwt);
5555
let f = filename_prefix;
5656
if (payload.sub != undefined) f += payload.sub;
5757
if (payload.nbf != undefined) f += ' from ' + (nbf_string || payload.nbf);
5858
if (payload.exp != undefined) f += ' to ' + (exp_string || payload.nbf);
5959
f = f.trim();
6060
f = f.replace(/:/g, '-');
61-
f += '.svg';
6261
let url = base_url + jwt;
63-
qrcode.toFile(f, url, {type:'svg'}, (err) => {
64-
if (!err) {
65-
appendFileSync(f, `<!--\n${url}\n-->\n`); // add url to svg (as comment)
66-
}
67-
});
62+
if (type == 'txt') {
63+
writeFileSync(f + '.txt', `${url}`);
64+
} else if (type == 'transparent-png') {
65+
qrcode.toFile(f + ' transparent.png', url, {type:'png', width:2160, color:{ dark:"#000", light:"#0000" }});
66+
} else if (type == 'png') {
67+
qrcode.toFile(f + '.png', url, {type:'png', width:2160 });
68+
} else {
69+
qrcode.toFile(f + '.svg', url, {type:'svg'}, (err) => {
70+
if (!err) {
71+
appendFileSync(f + '.svg', `<!--\n${url}\n-->\n`); // add url to svg (as comment)
72+
}
73+
});
74+
}
6875
return url;
6976
}
7077

make_qr.mjs

+4-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ export function make_qr(nbf=null, exp=null, filename_prefix='qr ', subject='exhi
5353
if (payload.nbf) console.log('nbf:', from_unix_seconds(payload.nbf));
5454
if (payload.exp) console.log('exp:', from_unix_seconds(payload.exp));
5555
console.log(jwt);
56-
return save_qr(jwt, base_url, nbf, exp, filename_prefix);
56+
save_qr(jwt, base_url, nbf, exp, filename_prefix, 'txt');
57+
save_qr(jwt, base_url, nbf, exp, filename_prefix, 'transparent-png');
58+
save_qr(jwt, base_url, nbf, exp, filename_prefix, 'png');
59+
return save_qr(jwt, base_url, nbf, exp, filename_prefix, 'svg');
5760
}
5861

5962
function usage() {

qr exhibition from 2024-04-05 00-00 to 2024-08-01 00-00.svg

-4
This file was deleted.

0 commit comments

Comments
 (0)