* Recursively scans an object for File type fields and validates their URLs. * @param {any} obj - The object to scan. * @param {Object} config - The Parse Server config object. * @throws {Parse.Error} If any File URL is not allowed.
(obj, config)
| 44 | * @throws {Parse.Error} If any File URL is not allowed. |
| 45 | */ |
| 46 | function validateFileUrlsInObject(obj, config) { |
| 47 | if (obj == null || typeof obj !== 'object') { |
| 48 | return; |
| 49 | } |
| 50 | if (Array.isArray(obj)) { |
| 51 | for (const item of obj) { |
| 52 | validateFileUrlsInObject(item, config); |
| 53 | } |
| 54 | return; |
| 55 | } |
| 56 | if (obj.__type === 'File' && obj.url) { |
| 57 | validateFileUrl(obj.url, config); |
| 58 | return; |
| 59 | } |
| 60 | for (const key of Object.keys(obj)) { |
| 61 | const value = obj[key]; |
| 62 | if (value && typeof value === 'object') { |
| 63 | validateFileUrlsInObject(value, config); |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | module.exports = { validateFileUrl, validateFileUrlsInObject }; |
no test coverage detected