MCPcopy Index your code
hub / github.com/fontsource/fontsource / updateCss

Function updateCss

api/cdn/src/css.ts:43–98  ·  view source on GitHub ↗
(
	tag: string,
	file: string,
	metadata: IDResponse,
	env: Env,
	ctx: ExecutionContext,
)

Source from the content-addressed store, hash-verified

41 `variable:${tag}:${filename}`;
42
43export 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
100export const updateVariableCSS = async (

Callers 1

router.tsFile · 0.90

Calls 7

generateIconStaticCSSFunction · 0.90
generateV1CSSFunction · 0.90
generateV2CSSFunction · 0.90
keyGenFunction · 0.85
nowMethod · 0.80
waitUntilMethod · 0.65
putMethod · 0.65

Tested by

no test coverage detected