( tag: string, file: string, metadata: IDResponse, env: Env, ctx: ExecutionContext, )
| 41 | `variable:${tag}:${filename}`; |
| 42 | |
| 43 | export const updateCss = async ( |
| 44 | tag: string, |
| 45 | file: string, |
| 46 | metadata: IDResponse, |
| 47 | env: Env, |
| 48 | ctx: ExecutionContext, |
| 49 | ): Promise<string> => { |
| 50 | let css: string | undefined; |
| 51 | const { category, type } = metadata; |
| 52 | |
| 53 | // Icons are handled differently |
| 54 | if (category === 'icons' && type === 'google') { |
| 55 | // Static |
| 56 | const cssGenerate = generateIconStaticCSS(metadata, makeFontFilePath, tag); |
| 57 | for (const item of cssGenerate) { |
| 58 | // Cache return value early as KV has slow writes |
| 59 | if (item.filename === file) { |
| 60 | css = item.css; |
| 61 | |
| 62 | ctx.waitUntil( |
| 63 | env.CSS.put(keyGen(tag, item.filename), item.css, { |
| 64 | metadata: { |
| 65 | ttl: Date.now() / 1000 + CSS_TTL, |
| 66 | }, |
| 67 | }), |
| 68 | ); |
| 69 | } |
| 70 | } |
| 71 | } else { |
| 72 | const cssGenerate = [ |
| 73 | ...generateV1CSS(metadata, makeFontFilePath, tag), |
| 74 | ...generateV2CSS(metadata, makeFontFilePath, tag), |
| 75 | ]; |
| 76 | |
| 77 | for (const item of cssGenerate) { |
| 78 | // Cache return value early as KV has slow writes |
| 79 | if (item.filename === file) { |
| 80 | css = item.css; |
| 81 | |
| 82 | ctx.waitUntil( |
| 83 | env.CSS.put(keyGen(tag, item.filename), item.css, { |
| 84 | metadata: { |
| 85 | ttl: Date.now() / 1000 + CSS_TTL, |
| 86 | }, |
| 87 | }), |
| 88 | ); |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | if (!css) { |
| 94 | throw new StatusError(404, 'Not Found. Unable to find filename.'); |
| 95 | } |
| 96 | |
| 97 | return css; |
| 98 | }; |
| 99 | |
| 100 | export const updateVariableCSS = async ( |
no test coverage detected