Skip to content

Commit 607968a

Browse files
committed
add attempt retries for thumbnails
1 parent b46a322 commit 607968a

1 file changed

Lines changed: 42 additions & 7 deletions

File tree

src/ssg/quickplayData.ts

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,46 @@ import { fetchCache } from "./fetchCache";
77

88
let quickplayData: any = null;
99

10+
async function optimizeThumbnailWithRetry(src: string, maxAttempts: number = 2): Promise<string> {
11+
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
12+
try {
13+
const optimizedImage = await getImage({
14+
src,
15+
inferSize: true,
16+
format: "webp",
17+
});
18+
return optimizedImage.src;
19+
} catch (e) {
20+
if (attempt === maxAttempts) {
21+
console.warn(`[Thumbnail Optimize] inferSize failed for ${src} after ${maxAttempts} attempts`);
22+
} else {
23+
await new Promise((r) => setTimeout(r, 1000 * attempt));
24+
}
25+
}
26+
}
27+
28+
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
29+
try {
30+
const optimizedImage = await getImage({
31+
src,
32+
width: 800,
33+
height: 600,
34+
format: "webp",
35+
});
36+
return optimizedImage.src;
37+
} catch (e) {
38+
if (attempt === maxAttempts) {
39+
console.warn(`[Thumbnail Optimize] explicit size failed for ${src} after ${maxAttempts} attempts`);
40+
} else {
41+
await new Promise((r) => setTimeout(r, 1000 * attempt));
42+
}
43+
}
44+
}
45+
46+
console.warn(`[Thumbnail Optimize] Falling back to raw URL for ${src}`);
47+
return src;
48+
}
49+
1050
export async function getQuickplayData() {
1151
if (!quickplayData) {
1252
const rawData = await fetchCache(
@@ -16,17 +56,12 @@ export async function getQuickplayData() {
1656
},
1757
);
1858
const thumbnails = rawData.map_thumbnails;
19-
const newThumbnails = {};
59+
const newThumbnails: Record<string, string> = {};
2060
for (const [map, thumbnail] of Object.entries(thumbnails)) {
2161
if (!map || !thumbnail) {
2262
continue;
2363
}
24-
const optimizedImage = await getImage({
25-
src: thumbnail,
26-
inferSize: true,
27-
format: "webp",
28-
});
29-
newThumbnails[map] = optimizedImage.src;
64+
newThumbnails[map] = await optimizeThumbnailWithRetry(thumbnail as string);
3065
}
3166
quickplayData = {
3267
map_thumbnails: newThumbnails,

0 commit comments

Comments
 (0)