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"); const args = cliArgs.parse<{ id?: number; enqueue?: number[]; dequeue?: number[]; help?: boolean; }>( { id: { type: Number, optional: true }, enqueue: { type: Number, optional: true, multiple: true }, dequeue: { type: Number, optional: true, multiple: 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) { for (const id of args.enqueue) { console.log(`Enqueueing post ${id}...`); await queueDb.insertIfNotExists({ provider: "e926", id }); } } else if (args.dequeue) { for (const id of args.dequeue) { console.log(`Dequeueing post ${id}...`); await queueDb.remove({ provider: "e926", id }); } } else { console.log("Reading queue..."); const queued = await queueDb.takeFirst(); if (queued) { await jobs.postSpecificPicture(queued.id); } else { await jobs.postRandomPicture(); } } })();