diff --git a/src/upload_handler.mjs b/src/upload_handler.mjs index 4a81631..e2be31b 100644 --- a/src/upload_handler.mjs +++ b/src/upload_handler.mjs @@ -167,9 +167,15 @@ export const handleUpload = async (req, res, self) => { } // Validate required fields - const file = parts.file; + let file = (typeof parts.file === 'object' && parts.file !== null && parts.file.data) ? parts.file : null; let inputUrl = (typeof parts.url === 'string' && parts.url.trim()) ? parts.url.trim() : null; + + if (!inputUrl && typeof parts.file === 'string' && /^https?:\/\//i.test(parts.file.trim())) { + inputUrl = parts.file.trim(); + } + if (inputUrl) { + file = null; try { const parsed = new URL(inputUrl); if (parsed.searchParams.has('igsh')) { @@ -178,6 +184,7 @@ export const handleUpload = async (req, res, self) => { } } catch (e) {} } + const rating = parts.rating; const tagsRaw = parts.tags; const comment = parts.comment ? String(parts.comment).trim() : ''; @@ -187,7 +194,7 @@ export const handleUpload = async (req, res, self) => { const is_oc = (parts.is_oc === true || parts.is_oc === 'true' || parts.is_oc === '1'); const is_shitpost = (parts.is_shitpost === true || parts.is_shitpost === 'true' || parts.is_shitpost === '1') || cfg.websrv.shitpost_mode === true; - if ((!file || !file.data) && !inputUrl) { + if (!file && !inputUrl) { return sendJson(res, { success: false, msg: 'No file or URL provided' }, 400); } @@ -276,7 +283,7 @@ export const handleUpload = async (req, res, self) => { ) : Object.keys(cfg.mimes); - if (file) { + if (file && !inputUrl) { let mime = file.contentType; if ((mime === 'application/octet-stream' || !mime || mime === 'application/x-www-form-urlencoded') && file.filename && file.filename.toLowerCase().endsWith('.swf')) {