Cache embed thumbnails in download mode
This commit is contained in:
@@ -220,12 +220,24 @@ export class ScrapeEngine {
|
||||
await this.sleep(this.gapMs());
|
||||
}
|
||||
|
||||
if (meta.state === "done" && meta.mode === "download") {
|
||||
await this.runDownloads(store, dir, meta);
|
||||
}
|
||||
if (meta.state === "done" && (meta.mode === "download" || this.options.previews !== false)) {
|
||||
// Keep the job running until post-processing finishes, so a client never
|
||||
// treats a half-archived scrape as complete.
|
||||
meta.state = "running";
|
||||
this.persist(dir, meta);
|
||||
|
||||
if (meta.state === "done" && this.options.previews !== false) {
|
||||
await this.runPreviews(store, dir, meta);
|
||||
if (meta.mode === "download") {
|
||||
await this.runDownloads(store, dir, meta);
|
||||
}
|
||||
|
||||
if (this.options.previews !== false && !this.stopRequested.has(meta.id)) {
|
||||
await this.runPreviews(store, dir, meta);
|
||||
}
|
||||
|
||||
if (meta.state === "running") {
|
||||
meta.state = "done";
|
||||
}
|
||||
this.persist(dir, meta);
|
||||
}
|
||||
} catch (error) {
|
||||
meta.state = "failed";
|
||||
@@ -271,10 +283,11 @@ export class ScrapeEngine {
|
||||
}
|
||||
}
|
||||
|
||||
/** Cache small previews for Discord-hosted images. Runs in both modes. */
|
||||
/** Cache small previews. In download mode this includes embed thumbnails. */
|
||||
private async runPreviews(store: ScrapeStore, dir: string, meta: ScrapeMeta): Promise<void> {
|
||||
const options = this.options.download ?? {};
|
||||
const pending = store.pendingPreviews();
|
||||
const embedPreviews = meta.mode === "download";
|
||||
const options = { ...(this.options.download ?? {}), embedPreviews };
|
||||
const pending = store.pendingPreviews(5000, embedPreviews);
|
||||
|
||||
for (const row of pending) {
|
||||
if (this.stopRequested.has(meta.id)) {
|
||||
|
||||
Reference in New Issue
Block a user