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(); } } })();