Skip to content

Commit 1a179a4

Browse files
committedFeb 24, 2025
Upgrade deps, fix for youtube (search multiple urls)
1 parent d984173 commit 1a179a4

File tree

4 files changed

+24
-28
lines changed

4 files changed

+24
-28
lines changed
 

‎api/og.js

+20-5
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export async function GET(request, context) {
116116
maxWidth = 650;
117117
}
118118

119-
console.log( {url, size, imageFormat, cacheBuster} );
119+
console.log( "Request", {url, size, imageFormat, cacheBuster} );
120120

121121
// short circuit circular requests
122122
if(isFullUrl(url) && (new URL(url)).hostname.endsWith(".opengraph.11ty.dev")) {
@@ -138,14 +138,29 @@ export async function GET(request, context) {
138138
// TODO: when requests to https://v1.screenshot.11ty.dev/ show an error (the default SVG image)
139139
// this service should error with _that_ image and the error message headers.
140140

141-
let stats = await Promise.any(imageUrls.map(url => {
141+
let settled = await Promise.allSettled(imageUrls.map(url => {
142142
return og.optimizeImage(url, imageFormat || FALLBACK_IMAGE_FORMAT, maxWidth);
143143
}));
144144

145-
let format = Object.keys(stats).pop();
146-
let stat = stats[format][0];
145+
let promises = settled.filter(p => {
146+
if(p.status === "fulfilled" && p.value) {
147+
return Object.keys(p.value).length > 0;
148+
}
149+
return false;
150+
}).map(p => {
151+
let format = Object.keys(p.value).pop();
152+
return p.value[format][0];
153+
}).sort((a, b) => {
154+
// descending
155+
return b.width - a.width;
156+
});
157+
158+
if(promises.length === 0) {
159+
throw new Error("No image found.");
160+
}
147161

148-
console.log( "Found match", url, format, stat );
162+
let stat = promises[0];
163+
console.log( "Found match", url, { format: stat.format, width: stat.width, height: stat.height, size: stat.size } );
149164

150165
return new Response(stat.buffer, {
151166
code: 200,

‎ogImageHtml.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,9 @@ class OgImageHtml {
7575
// results.add(`https://i.ytimg.com/vi/${videoId}/hqdefault.jpg`);
7676
}
7777
}
78+
// TODO youtu.be style https://github.com/11ty/api-opengraph-image/issues/8
7879

79-
console.log( "Found:", Array.from(results) );
80+
console.log( "Found urls:", Array.from(results) );
8081

8182
return Array.from(results);
8283
}

‎package.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"version": "1.0.0",
44
"description": "A runtime service to extract avatar images from the HTML on a web site.",
55
"scripts": {
6-
"test": "node test/test.js",
76
"start": "npx vercel dev"
87
},
98
"type": "module",
@@ -24,10 +23,10 @@
2423
},
2524
"homepage": "https://github.com/11ty/indieweb-avatar#readme",
2625
"dependencies": {
27-
"@11ty/eleventy-img": "5.0.0-beta.6",
26+
"@11ty/eleventy-img": "^6.0.1",
2827
"cheerio": "^1.0.0"
2928
},
3029
"devDependencies": {
31-
"vercel": "^37.1.2"
30+
"vercel": "^41.2.0"
3231
}
3332
}

‎test/test.js

-19
This file was deleted.

0 commit comments

Comments
 (0)