diff --git a/lib/db/allData.ts b/lib/db/allData.ts index 6e9c509..bf92edd 100644 --- a/lib/db/allData.ts +++ b/lib/db/allData.ts @@ -75,3 +75,13 @@ export async function setBiliVideoStatus(client: Client, aid: number, status: nu [status, aid], ); } + +export async function getBiliVideoStatus(client: Client, aid: number) { + const queryResult = await client.queryObject<{ status: number }>( + `SELECT status FROM bilibili_metadata WHERE aid = $1`, + [aid], + ); + const rows = queryResult.rows; + if (rows.length === 0) return 0; + return rows[0].status; +} diff --git a/lib/mq/exec/snapshotTick.ts b/lib/mq/exec/snapshotTick.ts index 9428ffe..14875f2 100644 --- a/lib/mq/exec/snapshotTick.ts +++ b/lib/mq/exec/snapshotTick.ts @@ -19,7 +19,7 @@ import logger from "lib/log/logger.ts"; import { SnapshotQueue } from "lib/mq/index.ts"; import { insertVideoSnapshot } from "lib/mq/task/getVideoStats.ts"; import { NetSchedulerError } from "lib/mq/scheduler.ts"; -import { setBiliVideoStatus } from "lib/db/allData.ts"; +import { getBiliVideoStatus, setBiliVideoStatus } from "lib/db/allData.ts"; import { truncate } from "lib/utils/truncate.ts"; import { lockManager } from "lib/mq/lockManager.ts"; import { getSongsPublihsedAt } from "lib/db/songs.ts"; @@ -197,13 +197,15 @@ export const takeSnapshotForVideoWorker = async (job: Job) => { if (!exists) { return; } + const status = await getBiliVideoStatus(client, aid); + if (status !== 0) return `REFUSE_WORKING_BILI_STATUS_${status}` try { await setSnapshotStatus(client, id, "processing"); const stat = await insertVideoSnapshot(client, aid, task); if (typeof stat === "number") { await setBiliVideoStatus(client, aid, stat); await setSnapshotStatus(client, id, "completed"); - return `BILI_STATUS_${stat}`; + return `GET_BILI_STATUS_${stat}`; } await setSnapshotStatus(client, id, "completed"); if (type === "normal") {