@@ -35,20 +35,31 @@ async function handler(req: NextRequest) {
35
35
const imageType = searchParams . get ( "type" ) ;
36
36
37
37
try {
38
- const [ calFontData , interFontData , interFontMediumData ] = await Promise . all ( [
38
+ const fontResults = await Promise . allSettled ( [
39
39
fetch ( new URL ( "/fonts/cal.ttf" , WEBAPP_URL ) ) . then ( ( res ) => res . arrayBuffer ( ) ) ,
40
40
fetch ( new URL ( "/fonts/Inter-Regular.ttf" , WEBAPP_URL ) ) . then ( ( res ) => res . arrayBuffer ( ) ) ,
41
41
fetch ( new URL ( "/fonts/Inter-Medium.ttf" , WEBAPP_URL ) ) . then ( ( res ) => res . arrayBuffer ( ) ) ,
42
42
] ) ;
43
+
44
+ const fonts : SatoriOptions [ "fonts" ] = [ ] ;
45
+
46
+ if ( fontResults [ 1 ] . status === "fulfilled" ) {
47
+ fonts . push ( { name : "inter" , data : fontResults [ 1 ] . value , weight : 400 } ) ;
48
+ }
49
+
50
+ if ( fontResults [ 2 ] . status === "fulfilled" ) {
51
+ fonts . push ( { name : "inter" , data : fontResults [ 2 ] . value , weight : 500 } ) ;
52
+ }
53
+
54
+ if ( fontResults [ 0 ] . status === "fulfilled" ) {
55
+ fonts . push ( { name : "cal" , data : fontResults [ 0 ] . value , weight : 400 } ) ;
56
+ fonts . push ( { name : "cal" , data : fontResults [ 0 ] . value , weight : 600 } ) ;
57
+ }
58
+
43
59
const ogConfig = {
44
60
width : 1200 ,
45
61
height : 630 ,
46
- fonts : [
47
- { name : "inter" , data : interFontData , weight : 400 } ,
48
- { name : "inter" , data : interFontMediumData , weight : 500 } ,
49
- { name : "cal" , data : calFontData , weight : 400 } ,
50
- { name : "cal" , data : calFontData , weight : 600 } ,
51
- ] as SatoriOptions [ "fonts" ] ,
62
+ fonts,
52
63
} ;
53
64
54
65
switch ( imageType ) {
0 commit comments