|
1 | 1 | #!/usr/bin/env node
|
2 | 2 | // make jwt tokens
|
3 | 3 |
|
4 |
| -import { readFileSync, appendFileSync } from 'fs'; |
| 4 | +import { readFileSync, appendFileSync, writeFileSync } from 'fs'; |
5 | 5 | import url from 'url';
|
6 | 6 | import jwt from 'jsonwebtoken';
|
7 | 7 | import { unix_seconds } from './util.mjs';
|
@@ -50,21 +50,28 @@ export function make(sub, nbf = null, exp = null) {
|
50 | 50 | }
|
51 | 51 |
|
52 | 52 | // 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') { |
54 | 54 | const payload = verify(jwt);
|
55 | 55 | let f = filename_prefix;
|
56 | 56 | if (payload.sub != undefined) f += payload.sub;
|
57 | 57 | if (payload.nbf != undefined) f += ' from ' + (nbf_string || payload.nbf);
|
58 | 58 | if (payload.exp != undefined) f += ' to ' + (exp_string || payload.nbf);
|
59 | 59 | f = f.trim();
|
60 | 60 | f = f.replace(/:/g, '-');
|
61 |
| - f += '.svg'; |
62 | 61 | 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 | + } |
68 | 75 | return url;
|
69 | 76 | }
|
70 | 77 |
|
|
0 commit comments