This commit is contained in:
2026-08-11 23:49:19 +02:00
parent fb3cbc76ec
commit ebd7855f15

View File

@@ -167,9 +167,15 @@ export const handleUpload = async (req, res, self) => {
} }
// Validate required fields // 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; 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) { if (inputUrl) {
file = null;
try { try {
const parsed = new URL(inputUrl); const parsed = new URL(inputUrl);
if (parsed.searchParams.has('igsh')) { if (parsed.searchParams.has('igsh')) {
@@ -178,6 +184,7 @@ export const handleUpload = async (req, res, self) => {
} }
} catch (e) {} } catch (e) {}
} }
const rating = parts.rating; const rating = parts.rating;
const tagsRaw = parts.tags; const tagsRaw = parts.tags;
const comment = parts.comment ? String(parts.comment).trim() : ''; 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_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; 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); 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); : Object.keys(cfg.mimes);
if (file) { if (file && !inputUrl) {
let mime = file.contentType; let mime = file.contentType;
if ((mime === 'application/octet-stream' || !mime || mime === 'application/x-www-form-urlencoded') && if ((mime === 'application/octet-stream' || !mime || mime === 'application/x-www-form-urlencoded') &&
file.filename && file.filename.toLowerCase().endsWith('.swf')) { file.filename && file.filename.toLowerCase().endsWith('.swf')) {