Skip to content

Commit

Permalink
Fix #220 seekAndDestroy consuming subscriptions asyncIterable
Browse files Browse the repository at this point in the history
  • Loading branch information
Inrixia committed Oct 30, 2024
1 parent b9663d0 commit c07ad9c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
26 changes: 18 additions & 8 deletions src/float.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ContentPost>[] = [];
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.
Expand Down
12 changes: 0 additions & 12 deletions src/seekAndDestroy.ts

This file was deleted.

0 comments on commit c07ad9c

Please sign in to comment.