(manifest: Manifest)
| 21 | import type { IDResponse } from './types'; |
| 22 | |
| 23 | export const downloadFile = async (manifest: Manifest) => { |
| 24 | const { id, subset, weight, style, extension, version, url } = manifest; |
| 25 | |
| 26 | const res = await fetch(url); |
| 27 | info(`Downloading ${url}`); |
| 28 | |
| 29 | if (!res.ok) { |
| 30 | throw new StatusError(500, `Could not fetch ${url}`); |
| 31 | } |
| 32 | |
| 33 | const buffer = await res.arrayBuffer(); |
| 34 | |
| 35 | // Add to bucket |
| 36 | await putBucket(bucketPath(manifest), buffer); |
| 37 | |
| 38 | // If woff, decompress and add to ttf folder |
| 39 | if (extension === 'woff') { |
| 40 | let ttfBuffer: ArrayBuffer | undefined; |
| 41 | try { |
| 42 | ttfBuffer = await woff2ttf.toSfnt(new Uint8Array(buffer)); |
| 43 | } catch (error) { |
| 44 | throw new StatusError( |
| 45 | 500, |
| 46 | `Could not convert woff to ttf ${String(error)}`, |
| 47 | ); |
| 48 | } |
| 49 | if (!ttfBuffer) throw new StatusError(500, 'Could not convert woff to ttf'); |
| 50 | |
| 51 | // Add to bucket |
| 52 | await putBucket( |
| 53 | bucketPath({ |
| 54 | id, |
| 55 | subset, |
| 56 | weight, |
| 57 | style, |
| 58 | extension: 'ttf', |
| 59 | version, |
| 60 | }), |
| 61 | ttfBuffer, |
| 62 | ); |
| 63 | } |
| 64 | }; |
| 65 | |
| 66 | export const downloadVariableFile = async (manifest: ManifestVariable) => { |
| 67 | const { url } = manifest; |
no test coverage detected