| 39 | }; |
| 40 | |
| 41 | export const validateVariableFontFileName = ( |
| 42 | file: string, |
| 43 | metadata: IDResponse, |
| 44 | variableMeta?: VariableMetadata, |
| 45 | ) => { |
| 46 | if (!variableMeta) { |
| 47 | throw new StatusError(400, 'Bad Request. Variable font not found.'); |
| 48 | } |
| 49 | |
| 50 | const [filename, extension] = file.split('.'); |
| 51 | if (!extension || extension !== 'woff2') { |
| 52 | throw new StatusError(400, 'Bad Request. Invalid file extension.'); |
| 53 | } |
| 54 | |
| 55 | const { subsets, styles } = metadata; |
| 56 | const { axes } = variableMeta; |
| 57 | |
| 58 | const filenameArr = filename.split('-'); |
| 59 | const style = filenameArr.pop(); |
| 60 | const axesKey = filenameArr.pop(); |
| 61 | const subset = filenameArr.join('-'); |
| 62 | |
| 63 | const isValidAxesKey = |
| 64 | Boolean(axesKey && axes[axesKey]) || |
| 65 | axesKey === 'standard' || |
| 66 | axesKey === 'full'; |
| 67 | |
| 68 | // Accept id-subset-axes-style |
| 69 | if ( |
| 70 | (subsets.includes(subset) || isNumeric(subset)) && |
| 71 | isValidAxesKey && |
| 72 | style && |
| 73 | styles.includes(style) |
| 74 | ) { |
| 75 | return; |
| 76 | } |
| 77 | |
| 78 | throw new StatusError(404, 'Not Found. Invalid filename.'); |
| 79 | }; |
| 80 | |
| 81 | export const validateCSSFilename = (file: string, metadata: IDResponse) => { |
| 82 | const [filename, extension] = file.split('.'); |