From c07ad9c91862c843e8204bc16466edf18defdb14 Mon Sep 17 00:00:00 2001 From: Inrixia Date: Wed, 30 Oct 2024 15:56:57 +1300 Subject: [PATCH] Fix #220 seekAndDestroy consuming subscriptions asyncIterable --- src/float.ts | 26 ++++++++++++++++++-------- src/seekAndDestroy.ts | 12 ------------ 2 files changed, 18 insertions(+), 20 deletions(-) delete mode 100644 src/seekAndDestroy.ts diff --git a/src/float.ts b/src/float.ts index c492ea4..3fe96cd 100644 --- a/src/float.ts +++ b/src/float.ts @@ -13,27 +13,37 @@ import semver from "semver"; const { gt, diff } = semver; import { Self } from "floatplane/user"; -import { seekAndDestroy } from "./seekAndDestroy.js"; +import type { ContentPost } from "floatplane/content"; /** * Main function that triggeres everything else in the script */ const downloadNewVideos = async () => { - const userSubs = fetchSubscriptions(); const inProgress = []; - for await (const contentPost of seekAndDestroy()) { - for await (const subscription of userSubs) { + + // Fetch content posts from seek and destroy guids + let contentPosts: Promise[] = []; + while (settings.floatplane.seekAndDestroy.length > 0) { + const guid = settings.floatplane.seekAndDestroy.pop(); + if (guid === undefined) continue; + console.log(chalk`Seek and Destroy: {red ${guid}}`); + contentPosts.push(fApi.content.post(guid)); + } + + for await (const subscription of fetchSubscriptions()) { + // Seek and destroy posts if the content post belongs to this subscription + for await (const contentPost of contentPosts) { if (contentPost.creator.id === subscription.creatorId) { - for await (const video of subscription.seekAndDestroy(contentPost)) inProgress.push(video.download()); + for await (const video of subscription.seekAndDestroy(contentPost)) { + inProgress.push(video.download()); + } } } - } - - for await (const subscription of userSubs) { await subscription.deleteOldVideos(); for await (const video of subscription.fetchNewVideos()) inProgress.push(video.download()); } + console.log(chalk`Queued {green ${inProgress.length}} videos...`); await Promise.all(inProgress); // Enforce search limits after searching once. diff --git a/src/seekAndDestroy.ts b/src/seekAndDestroy.ts deleted file mode 100644 index 3b5146b..0000000 --- a/src/seekAndDestroy.ts +++ /dev/null @@ -1,12 +0,0 @@ -import chalk from "chalk-template"; -import type { ContentPost } from "floatplane/content"; -import { settings, fApi } from "./lib/helpers/index.js"; - -export async function* seekAndDestroy(): AsyncGenerator { - while (settings.floatplane.seekAndDestroy.length > 0) { - const guid = settings.floatplane.seekAndDestroy.pop(); - if (guid === undefined) continue; - console.log(chalk`Seek and Destroy: {red ${guid}}`); - yield fApi.content.post(guid); - } -}