@@ -6,6 +6,8 @@ import { getRequestURL } from 'h3'
66import { useRuntimeConfig } from 'nitropack/runtime'
77import { join } from 'pathe'
88import { withBase } from 'ufo'
9+ import { getFetchTimeout } from '../../../util/fetchTimeout'
10+ import { useOgImageRuntimeConfig } from '../../../utils'
911
1012let fontUrlMapping : Record < string , string > | undefined
1113
@@ -19,6 +21,7 @@ async function loadFontUrlMapping(): Promise<Record<string, string>> {
1921
2022export async function resolve ( event : H3Event , font : FontConfig ) : Promise < Buffer > {
2123 const path = font . src || font . localPath
24+ const timeout = getFetchTimeout ( useOgImageRuntimeConfig ( ) )
2225
2326 // Static bundled fonts — read directly from absolute path
2427 if ( font . absolutePath ) {
@@ -48,7 +51,7 @@ export async function resolve(event: H3Event, font: FontConfig): Promise<Buffer>
4851
4952 const mapping = await loadFontUrlMapping ( )
5053 if ( mapping [ filename ] ) {
51- const res = await fetch ( mapping [ filename ] ) . catch ( ( ) => null )
54+ const res = await fetch ( mapping [ filename ] , { signal : AbortSignal . timeout ( timeout ) } ) . catch ( ( ) => null )
5255 if ( res ?. ok )
5356 return Buffer . from ( await res . arrayBuffer ( ) )
5457 }
@@ -78,7 +81,7 @@ export async function resolve(event: H3Event, font: FontConfig): Promise<Buffer>
7881 const filename = path . slice ( '/_fonts/' . length )
7982 const mapping = await loadFontUrlMapping ( )
8083 if ( mapping [ filename ] ) {
81- const res = await fetch ( mapping [ filename ] ) . catch ( ( ) => null )
84+ const res = await fetch ( mapping [ filename ] , { signal : AbortSignal . timeout ( timeout ) } ) . catch ( ( ) => null )
8285 if ( res ?. ok )
8386 return Buffer . from ( await res . arrayBuffer ( ) )
8487 }
@@ -99,7 +102,7 @@ export async function resolve(event: H3Event, font: FontConfig): Promise<Buffer>
99102 const reqUrl = getRequestURL ( event )
100103 const origin = `${ reqUrl . protocol } //${ reqUrl . host } `
101104 const url = new URL ( withBase ( path , app . baseURL ) , origin ) . href
102- const res = await fetch ( url ) . catch ( ( ) => null )
105+ const res = await fetch ( url , { signal : AbortSignal . timeout ( timeout ) } ) . catch ( ( ) => null )
103106 if ( res ?. ok ) {
104107 return Buffer . from ( await res . arrayBuffer ( ) )
105108 }
@@ -108,6 +111,7 @@ export async function resolve(event: H3Event, font: FontConfig): Promise<Buffer>
108111 // @ts -expect-error excessive stack depth from Nuxt typed routes
109112 const arrayBuffer = await event . $fetch ( fullPath , {
110113 responseType : 'arrayBuffer' ,
114+ timeout,
111115 } ) as ArrayBuffer
112116 return Buffer . from ( arrayBuffer )
113117}
0 commit comments