Spaces:
Configuration error
Configuration error
Download src/security/validation.js from UUUZCX/video-optimizer-bot: direct link, hf CLI and curl.
- Browser
- Download file 1.25 kB
-
https://huggingface.co/spaces/UUUZCX/video-optimizer-bot/resolve/main/src/security/validation.js
- Command line
-
hf download hf://spaces/UUUZCX/video-optimizer-bot/src/security/validation.js
-
curl -L -o validation.js https://huggingface.co/spaces/UUUZCX/video-optimizer-bot/resolve/main/src/security/validation.js
1.25 kB
| const fs = require("node:fs"); | |
| const { config } = require("../config/env"); | |
| const { AppError } = require("../utils/errors"); | |
| const allowedDomains = [ | |
| "youtube.com", | |
| "youtu.be", | |
| "m.youtube.com", | |
| "www.youtube.com", | |
| "tiktok.com", | |
| "www.tiktok.com", | |
| "instagram.com", | |
| "www.instagram.com", | |
| "x.com", | |
| "twitter.com", | |
| "www.twitter.com", | |
| "facebook.com", | |
| "www.facebook.com", | |
| "fb.watch" | |
| ]; | |
| function validateFileSize(filePath) { | |
| const stat = fs.statSync(filePath); | |
| const max = config.limits.maxFileSizeMb * 1024 * 1024; | |
| if (stat.size > max) { | |
| throw new AppError(`File is too large. Maximum allowed size is ${config.limits.maxFileSizeMb} MB.`, "FILE_TOO_LARGE"); | |
| } | |
| return stat.size; | |
| } | |
| function validateUrl(raw) { | |
| let url; | |
| try { | |
| url = new URL(raw); | |
| } catch { | |
| throw new AppError("This does not look like a valid link.", "INVALID_URL"); | |
| } | |
| const host = url.hostname.toLowerCase().replace(/^www\./, ""); | |
| const ok = allowedDomains.some((domain) => host === domain || host.endsWith(`.${domain}`)); | |
| if (!ok) throw new AppError("This link is not from a supported video site.", "UNSUPPORTED_DOMAIN", { host }); | |
| return url.toString(); | |
| } | |
| module.exports = { validateFileSize, validateUrl, allowedDomains }; | |