(jsonData: any)
| 119 | } |
| 120 | |
| 121 | export function validateTaskRequest(jsonData: any): [string, any, any, any] { |
| 122 | ensureJsonBodyIsDict(jsonData); |
| 123 | |
| 124 | const scraperName = jsonData.scraper_name; |
| 125 | const data = jsonData.data; |
| 126 | |
| 127 | const validatedScraperName = validateScraperName(scraperName); |
| 128 | |
| 129 | if (isNullish(data)) { |
| 130 | throw new JsonHTTPResponseWithMessage("'data' key must be provided"); |
| 131 | } |
| 132 | |
| 133 | if (!isObject(data)) { |
| 134 | throw new JsonHTTPResponseWithMessage("'data' key must be a valid JSON object"); |
| 135 | } |
| 136 | |
| 137 | const controls = Server.getControls(validatedScraperName); |
| 138 | |
| 139 | const result = controls.getBackendValidationResult(data); |
| 140 | |
| 141 | const errors = result.errors; |
| 142 | |
| 143 | if (isNotEmptyObject(errors)) { |
| 144 | throw new JsonHTTPResponseWithMessage(dictToString(errors)); |
| 145 | } |
| 146 | // use default if not provided |
| 147 | let enableCache = jsonData.enable_cache ?? Server.cache; |
| 148 | if (typeof enableCache !== 'boolean') { |
| 149 | throw new JsonHTTPResponseWithMessage("'enable_cache' must be a boolean"); |
| 150 | } |
| 151 | |
| 152 | |
| 153 | const validatedData = result.data; |
| 154 | const metadata = result.metadata; |
| 155 | return [validatedScraperName, validatedData, metadata, enableCache]; |
| 156 | } |
| 157 | |
| 158 | |
| 159 |
no test coverage detected