@@ -9,7 +9,6 @@ import { getAssetURL } from '@/lib/assets';
9
9
import { filterOutNullable } from '@/lib/typescript' ;
10
10
import { getCacheTag } from '@gitbook/cache-tags' ;
11
11
import type { GitBookSiteContext } from '@v2/lib/context' ;
12
- import { getCloudflareContext } from '@v2/lib/data/cloudflare' ;
13
12
import { getResizedImageURL } from '@v2/lib/images' ;
14
13
15
14
const googleFontsMap : { [ fontName in CustomizationDefaultFont ] : string } = {
@@ -322,24 +321,6 @@ function logOnCloudflareOnly(message: string) {
322
321
}
323
322
}
324
323
325
- /**
326
- * Fetch a resource from the function itself.
327
- * To avoid error with worker to worker requests in the same zone, we use the `WORKER_SELF_REFERENCE` binding.
328
- */
329
- async function fetchSelf ( url : string ) {
330
- const cloudflare = getCloudflareContext ( ) ;
331
- if ( cloudflare ?. env . WORKER_SELF_REFERENCE ) {
332
- logOnCloudflareOnly ( `Fetching self: ${ url } ` ) ;
333
- return await cloudflare . env . WORKER_SELF_REFERENCE . fetch (
334
- // `getAssetURL` can return a relative URL, so we need to make it absolute
335
- // the URL doesn't matter, as we're using the worker-self-reference binding
336
- new URL ( url , 'https://worker-self-reference/' )
337
- ) ;
338
- }
339
-
340
- return await fetch ( url ) ;
341
- }
342
-
343
324
/**
344
325
* Read an image from a response as a base64 encoded string.
345
326
*/
@@ -363,6 +344,7 @@ const staticImagesCache = new Map<string, string>();
363
344
* Read a static image and cache it in memory.
364
345
*/
365
346
async function readStaticImage ( url : string ) {
347
+ logOnCloudflareOnly ( `Reading static image: ${ url } , cache size: ${ staticImagesCache . size } ` ) ;
366
348
const cached = staticImagesCache . get ( url ) ;
367
349
if ( cached ) {
368
350
return cached ;
@@ -377,7 +359,7 @@ async function readStaticImage(url: string) {
377
359
* Read an image from GitBook itself.
378
360
*/
379
361
async function readSelfImage ( url : string ) {
380
- const response = await fetchSelf ( url ) ;
362
+ const response = await fetch ( url ) ;
381
363
const image = await readImage ( response ) ;
382
364
return image ;
383
365
}
0 commit comments