| 135 | }; |
| 136 | |
| 137 | export const validateVCSSFilename = ( |
| 138 | file: string, |
| 139 | variableMeta: VariableMetadata, |
| 140 | ) => { |
| 141 | const [filename, extension] = file.split('.'); |
| 142 | if (!extension || extension !== 'css') { |
| 143 | throw new StatusError(400, 'Bad Request. Invalid file extension.'); |
| 144 | } |
| 145 | |
| 146 | const { axes } = variableMeta; |
| 147 | // Accept index.css |
| 148 | if (filename === 'index') { |
| 149 | return; |
| 150 | } |
| 151 | |
| 152 | // Accept standard.css and full.css |
| 153 | if (filename === 'standard' || filename === 'full') { |
| 154 | return; |
| 155 | } |
| 156 | |
| 157 | // Accept axes.css |
| 158 | const axesKeys = Object.keys(axes); |
| 159 | if (axesKeys.includes(filename)) { |
| 160 | return; |
| 161 | } |
| 162 | |
| 163 | // Accept axes-italic.css |
| 164 | const [axesKey, italic] = filename.split('-'); |
| 165 | if (italic === 'italic' && axesKeys.includes(axesKey)) { |
| 166 | return; |
| 167 | } |
| 168 | |
| 169 | throw new StatusError(404, 'Not Found. Invalid filename.'); |
| 170 | }; |