@@ -116,7 +116,7 @@ export async function GET(request, context) {
116
116
maxWidth = 650 ;
117
117
}
118
118
119
- console . log ( { url, size, imageFormat, cacheBuster} ) ;
119
+ console . log ( "Request" , { url, size, imageFormat, cacheBuster} ) ;
120
120
121
121
// short circuit circular requests
122
122
if ( isFullUrl ( url ) && ( new URL ( url ) ) . hostname . endsWith ( ".opengraph.11ty.dev" ) ) {
@@ -138,14 +138,29 @@ export async function GET(request, context) {
138
138
// TODO: when requests to https://v1.screenshot.11ty.dev/ show an error (the default SVG image)
139
139
// this service should error with _that_ image and the error message headers.
140
140
141
- let stats = await Promise . any ( imageUrls . map ( url => {
141
+ let settled = await Promise . allSettled ( imageUrls . map ( url => {
142
142
return og . optimizeImage ( url , imageFormat || FALLBACK_IMAGE_FORMAT , maxWidth ) ;
143
143
} ) ) ;
144
144
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
+ }
147
161
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 } ) ;
149
164
150
165
return new Response ( stat . buffer , {
151
166
code : 200 ,
0 commit comments