File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- import fs from 'node:fs/promises' ;
2- import path from 'node:path' ;
31import sharp from 'sharp' ;
42import type { Blend } from './enumerations' ;
53
6- const FONT_PATH = path . resolve ( process . cwd ( ) , 'public/fonts/Inter-Bold.woff2' ) ;
4+ const GOOGLE_FONTS_INTER_BOLD_URL =
5+ 'https://fonts.gstatic.com/s/inter/v18/UcCO3FwrK3iLTeHuS_nVMrMxCp50SjIw2boKoduKmMEVuLyfAZ9hiJ-Ek-_EeA.woff2' ;
76
8- /** Module-level singleton so the file is only read once per process. */
97let _fontDataUri : Promise < string > | null = null ;
108
119const getFontDataUri = ( ) : Promise < string > => {
1210 if ( ! _fontDataUri ) {
13- _fontDataUri = fs
14- . readFile ( FONT_PATH )
15- . then ( ( buf ) => `data:font/woff2;base64,${ buf . toString ( 'base64' ) } ` )
16- . catch ( ( ) => {
17- // Font file missing — fall back to generic family names and hope
18- // for the best. Log a warning so this is visible in prod logs.
19- console . warn (
20- '[watermark] Inter-Bold.woff2 not found at' ,
21- FONT_PATH ,
22- '— text may be invisible in environments without system fonts.'
23- ) ;
11+ _fontDataUri = fetch ( GOOGLE_FONTS_INTER_BOLD_URL )
12+ . then ( async ( res ) => {
13+ if ( ! res . ok ) throw new Error ( `HTTP ${ res . status } ` ) ;
14+ const arrayBuffer = await res . arrayBuffer ( ) ;
15+ const b64 = Buffer . from ( arrayBuffer ) . toString ( 'base64' ) ;
16+ return `data:font/woff2;base64,${ b64 } ` ;
17+ } )
18+ . catch ( ( err ) => {
19+ console . warn ( '[watermark] Failed to fetch Inter Bold from Google Fonts:' , err ?. message ) ;
2420 return '' ;
2521 } ) ;
2622 }
You can’t perform that action at this time.
0 commit comments