-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
80 lines (68 loc) · 1.76 KB
/
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import {get, curry, merge} from 'lodash/fp';
import fetch from 'node-fetch';
import fs from 'fs';
import {envelope as env} from 'littlefork';
const send = curry((u, p, e, dl) => {
const fileName = get('location', dl);
if (!fileName) { return dl; }
console.time('fsstat');
const size = fs.statSync(fileName).size;
console.timeEnd('fsstat');
const mime = 'text/plain';
const sha256 = get('sha256', dl);
const c = `${get('term', dl)}`;
const userId = e;
const url = `https://${u}:${p}@api.timebeat.com/s/timeStamp/reg?size=${size}&mime=${mime}&fileName=${fileName}&sha256=${sha256}&c=${c}&userId=${userId}`;
console.log(url);
console.time('send');
return fetch(url)
.then(r => {
console.timeEnd('send');
if (!r.ok) {
console.log(r);
throw new Error('Enigio Login Failed or resource wrong');
}
return r.json();
})
.catch((err) => {
console.error('FAILED');
console.log(err);
return {v: 'failed'};
})
.then((t) => {
const timestamp = get('v', t);
console.log(t);
return merge({timestamp}, dl);
});
});
const enigio = (envelope, {log, cfg}) => {
const u = get('enigio.name', cfg);
const p = get('enigio.password', cfg);
const e = get('enigio.email', cfg);
const s = send(u, p, e);
log.debug('running enigio plugin');
return env.fmapDownloadsAsync(s, envelope);
};
enigio.desc = 'Timestamp and store hash with enigio';
enigio.argv = {
'enigio.name': {
type: 'text',
nargs: 1,
desc: 'Enigio Username',
},
'enigio.password': {
type: 'text',
nargs: 1,
desc: 'Enigio Password',
},
'enigio.email': {
type: 'text',
nargs: 1,
desc: 'Enigio Email',
},
};
const plugins = {
enigio_timestamp: enigio,
};
export { plugins };
export default { plugins };