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

Function updateVariableList

api/metadata/src/variable/update.ts:15–57  ·  view source on GitHub ↗
(env: Env, ctx: ExecutionContext)

Source from the content-addressed store, hash-verified

13import type { AxisRegistry, AxisRegistryDownload } from './types';
14
15export const updateVariableList = async (env: Env, ctx: ExecutionContext) => {
16 const resp = await fetch(VARIABLE_URL);
17 if (!resp.ok) {
18 const text = await resp.text();
19 throw new StatusError(
20 resp.status,
21 `Failed to fetch variable metadata list. ${text}`,
22 );
23 }
24 const data = (await resp.json()) as Record<
25 string,
26 VariableMetadataWithVariants
27 >;
28
29 const respIcons = await fetch(VARIABLE_ICONS_URL);
30 if (!respIcons.ok) {
31 const text = await respIcons.text();
32 throw new StatusError(
33 respIcons.status,
34 `Failed to fetch variable icons metadata list. ${text}`,
35 );
36 }
37 const dataIcons = (await respIcons.json()) as Record<
38 string,
39 VariableMetadataWithVariants
40 >;
41
42 const dataMerged = { ...data, ...dataIcons };
43
44 // Remove variants property from all fonts
45 const noVariants: Record<string, VariableMetadata> = {};
46 for (const [key, value] of Object.entries(dataMerged)) {
47 const { axes, family } = value;
48 noVariants[key] = { axes, family };
49 }
50
51 // Save entire metadata into KV first
52 ctx.waitUntil(
53 env.METADATA.put(METADATA_KEYS.variable_list, JSON.stringify(noVariants)),
54 );
55
56 return noVariants;
57};
58
59export const updateAxisRegistry = async (env: Env, ctx: ExecutionContext) => {
60 const resp = await fetch(AXIS_REGISTRY_URL);

Callers 2

scheduledFunction · 0.90
getVariableListFunction · 0.90

Calls 5

jsonMethod · 0.80
textMethod · 0.65
waitUntilMethod · 0.65
putMethod · 0.65
fetchFunction · 0.50

Tested by

no test coverage detected