From 163d8119c109c42e64ab37b01dec131f2cb5bf61 Mon Sep 17 00:00:00 2001 From: Volpeon Date: Tue, 19 Oct 2021 19:25:03 +0200 Subject: Code improvements, support a manual post queue --- src/index.ts | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'src/index.ts') diff --git a/src/index.ts b/src/index.ts index 5558540..86d55ed 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,13 +1,20 @@ 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" }, }, { @@ -23,7 +30,23 @@ const args = cliArgs.parse<{ 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 { - await jobs.postRandomPicture(); + console.log("Reading queue..."); + + const queued = await queueDb.takeFirst(); + + if (queued) { + await jobs.postSpecificPicture(queued.id); + } else { + await jobs.postRandomPicture(); + } } })(); -- cgit v1.2.3-70-g09d2