(file: string, metadata: IDResponse)
| 8 | !Number.isNaN(Number(num)); |
| 9 | |
| 10 | export const validateFontFilename = (file: string, metadata: IDResponse) => { |
| 11 | const [filename, extension] = file.split('.'); |
| 12 | if (!extension || !isAcceptedExtension(extension)) { |
| 13 | throw new StatusError(400, 'Bad Request. Invalid file extension.'); |
| 14 | } |
| 15 | |
| 16 | if (file === 'download.zip') { |
| 17 | return; |
| 18 | } |
| 19 | |
| 20 | const { weights, styles, subsets } = metadata; |
| 21 | |
| 22 | const filenameArr = filename.split('-'); |
| 23 | const style = filenameArr.pop(); |
| 24 | const weight = filenameArr.pop(); |
| 25 | const subset = filenameArr.join('-'); |
| 26 | |
| 27 | // Accept id-subset-weight-style |
| 28 | if ( |
| 29 | style && |
| 30 | // It could also be a numbered subset |
| 31 | (subsets.includes(subset) || isNumeric(subset)) && |
| 32 | weights.includes(Number(weight)) && |
| 33 | styles.includes(style) |
| 34 | ) { |
| 35 | return; |
| 36 | } |
| 37 | |
| 38 | throw new StatusError(404, 'Not Found. Invalid filename.'); |
| 39 | }; |
| 40 | |
| 41 | export const validateVariableFontFileName = ( |
| 42 | file: string, |
no test coverage detected