-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
42 lines (35 loc) · 849 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
'use strict';
const alfy = require('alfy');
const qr = require('qr-image');
const fs = require('fs');
const input = alfy.input;
let id = (new Date()).getTime();
function file(name) {
return fs.createWriteStream(__dirname + '/img/' + name);
}
function delImg(path) {
let files = [];
if( fs.existsSync(path) ) {
files = fs.readdirSync(path);
files.forEach((file,index)=>{
var curPath = path + "/" + file;
fs.unlinkSync(curPath);
});
}
};
delImg(__dirname + '/img/');
function output() {
let qrcode = qr.image(input, { type: 'png', parse_url: false, margin: 1}).pipe(file(id + '.png'));
qrcode.on('finish', () => {
alfy.output([{
type: 'file',
title: input,
arg: input,
"icon": {
"path":__dirname + '/img/' + id + ".png"
}
}]);
});
return qrcode;
}
output();