This commit is contained in:
2026-09-14 22:30:09 +02:00
parent 22ffc3b51a
commit 912deeb28e
42 changed files with 2998 additions and 618 deletions
+57 -26
View File
@@ -454,6 +454,17 @@ window.initUploadForm = (selector) => {
const statusDiv = form.querySelector('.upload-status');
const thumbSection = form.querySelector('#custom-thumbnail-section');
const thumbInput = form.querySelector('#upload-thumbnail-input');
const redirectCheckbox = form.querySelector('input[name="redirect_to_item"], #upload-redirect-checkbox');
if (redirectCheckbox) {
const savedRedirect = localStorage.getItem('upload_redirect_to_item');
if (savedRedirect !== null) {
redirectCheckbox.checked = (savedRedirect === 'true' || savedRedirect === '1');
}
redirectCheckbox.addEventListener('change', () => {
localStorage.setItem('upload_redirect_to_item', redirectCheckbox.checked ? 'true' : 'false');
});
}
// Capture the SSR-translated initial button text so updateSubmitButton
// always uses the correct language regardless of window.f0ckI18n state.
@@ -3061,7 +3072,14 @@ window.initUploadForm = (selector) => {
});
}
const targetUrl = res.slug ? `/${res.slug}` : (res.itemid ? `/${res.itemid}` : '/');
const shouldRedirectToItem = redirectCheckbox
? redirectCheckbox.checked
: (localStorage.getItem('upload_redirect_to_item') !== 'false');
const targetUrl = shouldRedirectToItem
? (res.slug ? `/${res.slug}` : (res.itemid ? `/${res.itemid}` : '/'))
: '/';
if (typeof window.loadPageAjax === 'function') {
window.loadPageAjax(targetUrl, true, { bypassCache: true });
} else {
@@ -3285,36 +3303,43 @@ window.initUploadForm = (selector) => {
}
}
// Seamless live injection without hard reload
if (window.location.pathname === '/upload') {
const shouldRedirectToItem = redirectCheckbox
? redirectCheckbox.checked
: (localStorage.getItem('upload_redirect_to_item') !== 'false');
// Prepend items to live grid seamlessly
if (window.NotificationSystemInstance && typeof window.NotificationSystemInstance.handleNewItem === 'function') {
for (const up of uploadedResults) {
if (!up.manual_approval && !up.pending && up.itemid) {
window.NotificationSystemInstance.handleNewItem({
id: up.itemid,
dest: up.dest,
mime: up.mime,
username: up.username || window.f0ckSession?.user || '',
display_name: up.display_name || window.f0ckSession?.display_name || null,
tag_id: up.tag_id ?? 0,
is_oc: !!up.is_oc,
slug: up.slug,
visibility: up.visibility || 0
});
}
}
}
if (shouldRedirectToItem) {
const targetItem = lastData || (uploadedResults && uploadedResults[0]);
const targetUrl = targetItem ? (targetItem.slug ? `/${targetItem.slug}` : (targetItem.itemid ? `/${targetItem.itemid}` : '/')) : '/';
if (typeof window.loadPageAjax === 'function') {
window.loadPageAjax(targetUrl, true, { bypassCache: true });
} else {
window.location.href = targetUrl;
}
} else {
if (typeof window.loadPageAjax === 'function') {
window.loadPageAjax('/', true, { bypassCache: true });
} else {
window.location.href = '/';
}
} else {
// Prepend items to live grid seamlessly
if (window.NotificationSystemInstance && typeof window.NotificationSystemInstance.handleNewItem === 'function') {
for (const up of uploadedResults) {
if (!up.manual_approval && !up.pending && up.itemid) {
window.NotificationSystemInstance.handleNewItem({
id: up.itemid,
dest: up.dest,
mime: up.mime,
username: up.username || window.f0ckSession?.user || '',
display_name: up.display_name || window.f0ckSession?.display_name || null,
tag_id: up.tag_id ?? 0,
is_oc: !!up.is_oc,
slug: up.slug,
visibility: up.visibility || 0
});
}
}
}
// Refresh grid & pagination seamlessly in background without reload
if (typeof window.loadPageAjax === 'function') {
window.loadPageAjax(window.location.pathname + window.location.search, true, { bypassCache: true, skipPush: true });
}
}
}
} else {
@@ -3334,6 +3359,12 @@ window.initUploadForm = (selector) => {
reset: () => {
isUploading = false;
form.reset();
if (redirectCheckbox) {
const savedRedirect = localStorage.getItem('upload_redirect_to_item');
if (savedRedirect !== null) {
redirectCheckbox.checked = (savedRedirect === 'true' || savedRedirect === '1');
}
}
tags = [];
selectedFiles = [];
if (albumChoiceContainer) albumChoiceContainer.style.display = 'none';