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
|
import config from "./config";
import * as jobs from "./services/jobs";
import * as cliArgs from "ts-command-line-args";
import PostDatabase from "./services/postDatabase";
export const queueDb = new PostDatabase("queue.json", 50);
const args = cliArgs.parse<{
id?: number;
enqueue?: number;
dequeue?: number;
help?: boolean;
}>(
{
id: { type: Number, optional: true },
enqueue: { type: Number, optional: true },
dequeue: { type: Number, optional: true },
help: { type: Boolean, optional: true, alias: "h" },
},
{
helpArg: "help",
}
);
(async () => {
if (!config.mastodon.token) {
console.error("MASTODON_TOKEN not set");
return;
}
if (args.id) {
await jobs.postSpecificPicture(args.id);
} else if (args.enqueue) {
console.log(`Enqueueing post ${args.enqueue}...`);
await queueDb.insertIfNotExists({ provider: "e926", id: args.enqueue });
} else if (args.dequeue) {
console.log(`Dequeueing post ${args.dequeue}...`);
await queueDb.remove({ provider: "e926", id: args.dequeue });
} else {
console.log("Reading queue...");
const queued = await queueDb.takeFirst();
if (queued) {
await jobs.postSpecificPicture(queued.id);
} else {
await jobs.postRandomPicture();
}
}
})();
|