69
This commit is contained in:
@@ -43,6 +43,10 @@ db`ALTER TABLE items ALTER COLUMN checksum TYPE character varying(255)`.catch(()
|
||||
db`ALTER TABLE items ALTER COLUMN dest TYPE character varying(60)`.catch(() => {});
|
||||
db`ALTER TABLE comment_files ALTER COLUMN dest TYPE character varying(60)`.catch(() => {});
|
||||
|
||||
// One-time migration: fix NULL visibility values and ensure NOT NULL default going forward
|
||||
db`UPDATE items SET visibility = 0 WHERE visibility IS NULL`.catch(() => {});
|
||||
db`ALTER TABLE items ALTER COLUMN visibility SET DEFAULT 0`.catch(() => {});
|
||||
|
||||
export const handleUpload = async (req, res, self) => {
|
||||
// Manual session lookup is required here because this handler is called from a
|
||||
// bypass middleware that runs in parallel with the main session middleware.
|
||||
@@ -138,6 +142,27 @@ export const handleUpload = async (req, res, self) => {
|
||||
|
||||
const is_shitpost = (parts.is_shitpost === 'true' || parts.is_shitpost === '1') || cfg.websrv.shitpost_mode === true;
|
||||
|
||||
// Parse visibility: Header 'X-Upload-Visibility' or body field 'visibility' or user default preference
|
||||
let targetVisibility = 0;
|
||||
if (cfg.enable_private_uploads !== false) {
|
||||
const rawVisHeader = req.headers['x-upload-visibility'];
|
||||
const rawVisBody = parts.visibility;
|
||||
const visVal = (rawVisHeader || rawVisBody || '').toString().trim().toLowerCase();
|
||||
|
||||
if (visVal === 'private' || visVal === '2') {
|
||||
targetVisibility = 2;
|
||||
} else if (visVal === 'unlisted' || visVal === '1') {
|
||||
targetVisibility = 1;
|
||||
} else if (visVal === 'public' || visVal === '0') {
|
||||
targetVisibility = 0;
|
||||
} else {
|
||||
targetVisibility = req.session?.default_upload_visibility || 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Generate slug if enabled
|
||||
const itemSlug = (cfg.enable_item_slugs !== false) ? lib.generateSlug(11) : null;
|
||||
|
||||
const maxLen = cfg.main.comment_max_length;
|
||||
if (comment && maxLen !== null && maxLen !== undefined && comment.length > maxLen) {
|
||||
return sendJson(res, { success: false, msg: `Comment too long (max ${maxLen} characters)` }, 400);
|
||||
@@ -456,8 +481,10 @@ export const handleUpload = async (req, res, self) => {
|
||||
original_filename: originalFilename,
|
||||
title: title,
|
||||
width: itemWidth,
|
||||
height: itemHeight
|
||||
}, 'src', 'dest', 'mime', 'size', 'checksum', 'phash', 'username', 'userchannel', 'usernetwork', 'stamp', 'active', 'is_oc', 'original_filename', 'title', 'width', 'height')}
|
||||
height: itemHeight,
|
||||
visibility: targetVisibility,
|
||||
slug: itemSlug
|
||||
}, 'src', 'dest', 'mime', 'size', 'checksum', 'phash', 'username', 'userchannel', 'usernetwork', 'stamp', 'active', 'is_oc', 'original_filename', 'title', 'width', 'height', 'visibility', 'slug')}
|
||||
`;
|
||||
|
||||
const itemid = await queue.getItemID(filename);
|
||||
@@ -768,13 +795,16 @@ export const handleUpload = async (req, res, self) => {
|
||||
: 'Upload successful! Your upload is now live.';
|
||||
|
||||
const imagesPath = cfg.websrv.paths?.images || '/b';
|
||||
const itemRoute = itemSlug ? `/${itemSlug}` : `/${itemid}`;
|
||||
return sendJson(res, {
|
||||
success: true,
|
||||
msg: successMsg,
|
||||
itemid: itemid,
|
||||
slug: itemSlug,
|
||||
visibility: targetVisibility,
|
||||
manual_approval: manualApproval,
|
||||
redirect: !manualApproval ? `/${itemid}` : null,
|
||||
url: !manualApproval ? `${cfg.main.url.full}/${itemid}` : `${cfg.main.url.full}/`,
|
||||
redirect: !manualApproval ? itemRoute : null,
|
||||
url: !manualApproval ? `${cfg.main.url.full}${itemRoute}` : `${cfg.main.url.full}/`,
|
||||
file_url: !manualApproval ? `${cfg.main.url.full}${imagesPath}/${filename}` : null,
|
||||
// Fields for immediate client-side grid injection (avoids SSE race condition)
|
||||
dest: filename,
|
||||
|
||||
Reference in New Issue
Block a user