-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLifeLog Url Finish.js
58 lines (47 loc) · 1.62 KB
/
LifeLog Url Finish.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
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: deep-green; icon-glyph: flag-checkered;
// share-sheet-inputs: url;
///<reference path="./types/lifeLog.d.ts" />
// @ts-ignore
// eslint-disable-next-line
try { require; } catch(e) { require = importModule; }
const { getInput, output, error, string } = require('./lib/lib.js');
const {
pathLog, pathActivities,
makeActivityId, getActivityTitle, getKeyFromUrl,
readLog, readActivities, writeLifeLogData
} = require('./lib/lifelog.js');
const help = `Marks a particular URL-based activity as finished.
LifeLog JSON Path: ${pathLog}
LifeLog JSON Type: $/types/lifeLog.d.ts::LifeLog
LifeLog Activities JSON Path: ${pathActivities}
LifeLog Activities JSON Type: $/types/lifeLog.d.ts::LifeLogActivities`;
const main = async () => {
const log = await readLog();
const acts = await readActivities();
const input = await getInput({
name: 'LifeLog URL Finish',
help,
inScriptable: false,
args: [{
name: 'url',
shortName: 'u',
type: 'string',
share: true,
help: 'The URL to finish.'
}]
});
if (!input) { return; }
const { key } = getKeyFromUrl(string(input.url));
if (!key) {
return error('LifeLog URL Finish', 'Invalid URL.');
}
const time = (new Date()).getTime();
const id = makeActivityId(key, log);
log.finish[time] = id;
await writeLifeLogData(log, acts);
const title = getActivityTitle(key, acts);
output('LifeLog URL Finish', `Finished activity: ${title}`);
};
main();