| 57 | }; |
| 58 | |
| 59 | export const updateAxisRegistry = async (env: Env, ctx: ExecutionContext) => { |
| 60 | const resp = await fetch(AXIS_REGISTRY_URL); |
| 61 | if (!resp.ok) { |
| 62 | const text = await resp.text(); |
| 63 | throw new StatusError( |
| 64 | resp.status, |
| 65 | `Failed to fetch axis registry metadata. ${text}`, |
| 66 | ); |
| 67 | } |
| 68 | const data = (await resp.json()) as AxisRegistryDownload; |
| 69 | |
| 70 | const registry: AxisRegistry = {}; |
| 71 | // Remove tag property from all fonts and use it as a key |
| 72 | for (const item of data) { |
| 73 | const { tag, ...rest } = item; |
| 74 | registry[tag] = rest; |
| 75 | } |
| 76 | |
| 77 | // Save entire metadata into KV first |
| 78 | ctx.waitUntil( |
| 79 | env.METADATA.put(METADATA_KEYS.axisRegistry, JSON.stringify(registry)), |
| 80 | ); |
| 81 | |
| 82 | return registry; |
| 83 | }; |