( tag: string, req: Request, env: Env, )
| 24 | ACCEPTED_EXTENSIONS.includes(extension as AcceptedExtension); |
| 25 | |
| 26 | export const splitTag = async ( |
| 27 | tag: string, |
| 28 | req: Request, |
| 29 | env: Env, |
| 30 | ): Promise<Tag> => { |
| 31 | // Parse tag for version e.g roboto@1.1.1 |
| 32 | const [idTag, versionTag] = tag.split('@'); |
| 33 | const [id, isVariable] = idTag.split(':'); |
| 34 | |
| 35 | if (!id) { |
| 36 | throw new StatusError( |
| 37 | 400, |
| 38 | 'Bad Request. Unable to parse font ID from tag.', |
| 39 | ); |
| 40 | } |
| 41 | if (!versionTag) { |
| 42 | throw new StatusError( |
| 43 | 400, |
| 44 | 'Bad Request. Unable to parse version tag from tag.', |
| 45 | ); |
| 46 | } |
| 47 | if (isVariable && isVariable !== 'vf') { |
| 48 | throw new StatusError( |
| 49 | 400, |
| 50 | 'Bad Request. Invalid variable font tag. Must appended with :vf.', |
| 51 | ); |
| 52 | } |
| 53 | |
| 54 | // Don't support version tags below v5 |
| 55 | if (!versionTag.startsWith('5') && versionTag !== 'latest') { |
| 56 | throw new StatusError( |
| 57 | 400, |
| 58 | 'Bad Request. Version tags below @5 are not supported.', |
| 59 | ); |
| 60 | } |
| 61 | |
| 62 | // Validate version tag |
| 63 | const { |
| 64 | static: staticVar, |
| 65 | variable, |
| 66 | latest, |
| 67 | latestVariable, |
| 68 | } = await getVersion(id, req, env); |
| 69 | |
| 70 | if (versionTag === 'latest') { |
| 71 | if (isVariable) { |
| 72 | if (!latestVariable) { |
| 73 | throw new StatusError( |
| 74 | 404, |
| 75 | `Not found. Version ${versionTag} not found for ${id}.`, |
| 76 | ); |
| 77 | } |
| 78 | return { id, version: latestVariable, isVariable: Boolean(isVariable) }; |
| 79 | } |
| 80 | |
| 81 | return { id, version: latest, isVariable: Boolean(isVariable) }; |
| 82 | } |
| 83 |
no test coverage detected