This commit is contained in:
2026-09-18 00:32:53 +02:00
parent c8cfe07c70
commit 74f7884525
19 changed files with 1996 additions and 483 deletions
+96 -52
View File
@@ -1266,40 +1266,70 @@ window.initUploadForm = (selector) => {
badge.innerHTML = index === 0 ? '<i class="fa-solid fa-star"></i> Cover' : `#${index + 1}`;
card.appendChild(badge);
const isVideo = (file.type && file.type.startsWith('video/')) || /\.(mp4|webm|mov|mkv)$/i.test(file.name || '');
const isAudio = (file.type && file.type.startsWith('audio/')) || /\.(mp3|ogg|wav|flac|m4a|aac)$/i.test(file.name || '');
if (isVideo) {
const video = document.createElement('video');
video.src = URL.createObjectURL(file);
video.muted = true;
video.playsInline = true;
video.autoplay = false;
video.preload = 'metadata';
card.appendChild(video);
const mimeBadge = document.createElement('span');
mimeBadge.className = 'album-stage-mime-badge';
mimeBadge.innerHTML = '<i class="fa-solid fa-play"></i>';
card.appendChild(mimeBadge);
} else if (isAudio) {
const audioPreview = document.createElement('div');
audioPreview.className = 'album-stage-audio-preview';
audioPreview.innerHTML = `
<i class="fa-solid fa-music"></i>
<span class="album-stage-audio-name" title="${file.name || 'Audio'}">${file.name || 'Audio'}</span>
`;
card.appendChild(audioPreview);
const mimeBadge = document.createElement('span');
mimeBadge.className = 'album-stage-mime-badge';
mimeBadge.innerHTML = '<i class="fa-solid fa-music"></i>';
card.appendChild(mimeBadge);
// URL items (YouTube links etc.) — no File/Blob available
if (item.type === 'url') {
const urlStr = item.url || '';
const ytMatch = urlStr.match(/(?:youtube\.com\/watch\?v=|youtu\.be\/)([A-Za-z0-9_-]{11})/);
if (ytMatch) {
const thumb = document.createElement('img');
thumb.src = `https://img.youtube.com/vi/${ytMatch[1]}/mqdefault.jpg`;
thumb.alt = 'YouTube thumbnail';
thumb.style.cssText = 'width:100%;height:100%;object-fit:cover;';
card.appendChild(thumb);
const mimeBadge = document.createElement('span');
mimeBadge.className = 'album-stage-mime-badge';
mimeBadge.innerHTML = '<i class="fa-brands fa-youtube"></i>';
card.appendChild(mimeBadge);
} else {
const urlPreview = document.createElement('div');
urlPreview.className = 'album-stage-audio-preview';
const shortUrl = urlStr.replace(/^https?:\/\//, '').substring(0, 40);
urlPreview.innerHTML = `
<i class="fa-solid fa-link"></i>
<span class="album-stage-audio-name" title="${urlStr}">${shortUrl}</span>
`;
card.appendChild(urlPreview);
const mimeBadge = document.createElement('span');
mimeBadge.className = 'album-stage-mime-badge';
mimeBadge.innerHTML = '<i class="fa-solid fa-link"></i>';
card.appendChild(mimeBadge);
}
} else {
const img = document.createElement('img');
img.src = URL.createObjectURL(file);
img.alt = file.name || `Subf0ck ${index + 1}`;
card.appendChild(img);
const isVideo = (file.type && file.type.startsWith('video/')) || /\.(mp4|webm|mov|mkv)$/i.test(file.name || '');
const isAudio = (file.type && file.type.startsWith('audio/')) || /\.(mp3|ogg|wav|flac|m4a|aac)$/i.test(file.name || '');
if (isVideo) {
const video = document.createElement('video');
video.src = URL.createObjectURL(file);
video.muted = true;
video.playsInline = true;
video.autoplay = false;
video.preload = 'metadata';
card.appendChild(video);
const mimeBadge = document.createElement('span');
mimeBadge.className = 'album-stage-mime-badge';
mimeBadge.innerHTML = '<i class="fa-solid fa-play"></i>';
card.appendChild(mimeBadge);
} else if (isAudio) {
const audioPreview = document.createElement('div');
audioPreview.className = 'album-stage-audio-preview';
audioPreview.innerHTML = `
<i class="fa-solid fa-music"></i>
<span class="album-stage-audio-name" title="${file.name || 'Audio'}">${file.name || 'Audio'}</span>
`;
card.appendChild(audioPreview);
const mimeBadge = document.createElement('span');
mimeBadge.className = 'album-stage-mime-badge';
mimeBadge.innerHTML = '<i class="fa-solid fa-music"></i>';
card.appendChild(mimeBadge);
} else {
const img = document.createElement('img');
img.src = URL.createObjectURL(file);
img.alt = file.name || `Subf0ck ${index + 1}`;
card.appendChild(img);
}
}
const actions = document.createElement('div');
@@ -2972,8 +3002,21 @@ window.initUploadForm = (selector) => {
}
}
// URL uploads: always stay on current page — tracker panel shows progress
// (no redirect here; the file upload path below handles its own redirect)
// URL uploads: redirect or stay based on user preference (pending/async jobs skip redirect)
if (!lastData?.pending && !lastData?.manual_approval) {
const shouldRedirectToItem = redirectCheckbox
? redirectCheckbox.checked
: (localStorage.getItem('upload_redirect_to_item') !== 'false');
if (shouldRedirectToItem && lastData?.itemid) {
const targetUrl = lastData.slug ? `/${lastData.slug}` : `/${lastData.itemid}`;
if (typeof window.loadPageAjax === 'function') {
window.loadPageAjax(targetUrl, true, { bypassCache: true });
} else {
window.location.href = targetUrl;
}
}
// else: stay on current page
}
} else {
restoreBtn();
}
@@ -3006,9 +3049,15 @@ window.initUploadForm = (selector) => {
if (comment) formData.append('comment', comment);
for (let i = 0; i < selectedFiles.length; i++) {
const f = selectedFiles[i].file || selectedFiles[i];
formData.append('files', f);
const subTags = selectedFiles[i].subTags || '';
const item = selectedFiles[i];
if (item.type === 'url') {
// URL items (YouTube links etc.) — send as a URL field, not a binary file
formData.append(`subf0ck_url_${i}`, item.url || '');
} else {
const f = item.file || item;
formData.append('files', f);
}
const subTags = item.subTags || '';
if (subTags) {
formData.append(`subf0ck_tags_${i}`, subTags);
}
@@ -3080,15 +3129,15 @@ window.initUploadForm = (selector) => {
? 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 {
window.location.href = targetUrl;
if (shouldRedirectToItem) {
const targetUrl = res.slug ? `/${res.slug}` : (res.itemid ? `/${res.itemid}` : '/');
if (typeof window.loadPageAjax === 'function') {
window.loadPageAjax(targetUrl, true, { bypassCache: true });
} else {
window.location.href = targetUrl;
}
}
// else: stay on current page
return;
} else {
const errMsg = res.msg || 'Upload failed';
@@ -3340,13 +3389,8 @@ window.initUploadForm = (selector) => {
} else {
window.location.href = targetUrl;
}
} else {
if (typeof window.loadPageAjax === 'function') {
window.loadPageAjax('/', true, { bypassCache: true });
} else {
window.location.href = '/';
}
}
// else: stay on current page
}
} else {
restoreBtn();