Skip to content

Commit

Permalink
Fix only one server-rendered thumbnail working in submission menu
Browse files Browse the repository at this point in the history
  • Loading branch information
ajayyy committed Oct 24, 2024
1 parent e118700 commit 7e77404
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/dataFetching.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,10 @@ export async function waitForThumbnailCache(videoID: VideoID): Promise<void> {
await activeRequest.currentRequest;
}

export function isActiveThumbnailCacheRequest(videoID: VideoID): boolean {
return !!activeThumbnailCacheRequests[videoID];
}

export function getNumberOfThumbnailCacheRequests(): number {
return Object.keys(activeThumbnailCacheRequests).length;
}
Expand Down
13 changes: 11 additions & 2 deletions src/thumbnails/thumbnailRenderer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Format, fetchChannelnfo, fetchVideoMetadata, getPlaybackFormats, isLiveOrUpcoming } from "./thumbnailData";
import { VideoID } from "../../maze-utils/src/video";
import { getNumberOfThumbnailCacheRequests, getThumbnailUrl, getVideoThumbnailIncludingUnsubmitted, isFetchingFromThumbnailCache, queueThumbnailCacheRequest, waitForThumbnailCache } from "../dataFetching";
import { getNumberOfThumbnailCacheRequests, getThumbnailUrl, getVideoThumbnailIncludingUnsubmitted, isActiveThumbnailCacheRequest, isFetchingFromThumbnailCache, queueThumbnailCacheRequest, waitForThumbnailCache } from "../dataFetching";
import { log, logError } from "../utils/logger";
import { BrandingLocation, ShowCustomBrandingInfo, getActualShowCustomBranding } from "../videoBranding/videoBranding";
import { isFirefoxOrSafari, timeoutPomise, waitFor } from "../../maze-utils/src";
Expand Down Expand Up @@ -310,7 +310,16 @@ function handleThumbnailRenderFailure(videoID: VideoID, width: number, height: n

if (!thumbnailFailed && Config.config!.thumbnailCacheUse !== ThumbnailCacheOption.Disable && !CompileConfig.debug) {
// Force the thumbnail to be generated by the server
queueThumbnailCacheRequest(videoID, timestamp, undefined, false, true);
// Generate it one-by-one because of how callbacks are handled
(async () => {
let tries = 0;
while (isActiveThumbnailCacheRequest(videoID) && tries < 10) {
await waitForThumbnailCache(videoID);
tries++;
}

queueThumbnailCacheRequest(videoID, timestamp, undefined, false, true)
})().catch(logError);

videoCache.failures.push({
timestamp,
Expand Down

0 comments on commit 7e77404

Please sign in to comment.