fdfsa
This commit is contained in:
@@ -11480,6 +11480,125 @@ document.addEventListener('click', (e) => {
|
||||
return;
|
||||
}
|
||||
|
||||
// Info Modal: Regenerate Thumbnail button
|
||||
const rethumbBtn = e.target.closest('#info-rethumb-btn');
|
||||
if (rethumbBtn) {
|
||||
e.preventDefault();
|
||||
const itemId = rethumbBtn.dataset.itemId || document.getElementById('info-title-input')?.dataset.itemId;
|
||||
if (!itemId) return;
|
||||
|
||||
rethumbBtn.disabled = true;
|
||||
const origText = rethumbBtn.innerHTML;
|
||||
rethumbBtn.innerHTML = '<i class="fa-solid fa-spinner fa-spin"></i> Regenerating...';
|
||||
|
||||
const csrf = window.f0ckSession?.csrf_token;
|
||||
fetch(`/api/v2/items/${itemId}/rethumb`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRF-Token': csrf
|
||||
}
|
||||
})
|
||||
.then(r => r.json())
|
||||
.then(data => {
|
||||
rethumbBtn.disabled = false;
|
||||
rethumbBtn.innerHTML = origText;
|
||||
if (data.success) {
|
||||
if (window.flashMessage) window.flashMessage('THUMBNAIL REGENERATED');
|
||||
else if (window.showFlash) window.showFlash('Thumbnail regenerated');
|
||||
// Cache-bust thumbnails on page
|
||||
const timestamp = Date.now();
|
||||
document.querySelectorAll(`img[src*="/t/${itemId}.webp"]`).forEach(img => {
|
||||
const url = new URL(img.src, window.location.origin);
|
||||
url.searchParams.set('t', timestamp);
|
||||
img.src = url.toString();
|
||||
});
|
||||
document.querySelectorAll(`.thumb[data-bg*="/t/${itemId}.webp"]`).forEach(thumb => {
|
||||
const bg = thumb.dataset.bg;
|
||||
if (bg) {
|
||||
const url = new URL(bg, window.location.origin);
|
||||
url.searchParams.set('t', timestamp);
|
||||
thumb.style.setProperty('--thumb-bg', `url('${url.toString()}')`);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if (window.flashError) window.flashError(data.msg || 'Regeneration failed');
|
||||
else alert(data.msg || 'Regeneration failed');
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
rethumbBtn.disabled = false;
|
||||
rethumbBtn.innerHTML = origText;
|
||||
console.error('Error regenerating thumbnail:', err);
|
||||
if (window.flashError) window.flashError('Network error');
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// Info Modal: Set Expiry button
|
||||
const setExpiryBtn = e.target.closest('#info-set-expiry-btn');
|
||||
if (setExpiryBtn) {
|
||||
e.preventDefault();
|
||||
const select = document.getElementById('info-expiry-select');
|
||||
const itemId = setExpiryBtn.dataset.itemId || select?.dataset.itemId || document.getElementById('info-title-input')?.dataset.itemId;
|
||||
if (!itemId || !select) return;
|
||||
|
||||
const selectedExpiry = select.value;
|
||||
|
||||
setExpiryBtn.disabled = true;
|
||||
select.disabled = true;
|
||||
const origText = setExpiryBtn.innerHTML;
|
||||
setExpiryBtn.innerHTML = '<i class="fa-solid fa-spinner fa-spin"></i>';
|
||||
|
||||
const csrf = window.f0ckSession?.csrf_token;
|
||||
fetch(`/api/v2/items/${itemId}/expiry`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRF-Token': csrf
|
||||
},
|
||||
body: JSON.stringify({ expiry: selectedExpiry })
|
||||
})
|
||||
.then(r => r.json())
|
||||
.then(data => {
|
||||
setExpiryBtn.disabled = false;
|
||||
select.disabled = false;
|
||||
setExpiryBtn.innerHTML = origText;
|
||||
if (data.success) {
|
||||
const label = document.getElementById('info-expiry-label');
|
||||
if (label) {
|
||||
if (data.expires_at) {
|
||||
label.innerHTML = `<i class="fa-solid fa-clock"></i> ${data.expires_in || ('in ' + new Date(data.expires_at * 1000).toLocaleString())}`;
|
||||
label.setAttribute('title', new Date(data.expires_at * 1000).toLocaleString());
|
||||
label.style.color = '#ffaa00';
|
||||
} else {
|
||||
label.innerHTML = '<i class="fa-solid fa-clock-slash" style="color: var(--text-muted, #888);"></i> Never';
|
||||
label.removeAttribute('title');
|
||||
label.style.color = '';
|
||||
}
|
||||
}
|
||||
if (data.purged) {
|
||||
if (window.flashMessage) window.flashMessage('ITEM EXPIRED AND PURGED');
|
||||
setTimeout(() => {
|
||||
window.location.href = '/';
|
||||
}, 1200);
|
||||
} else {
|
||||
if (window.flashMessage) window.flashMessage('EXPIRATION UPDATED');
|
||||
}
|
||||
} else {
|
||||
if (window.flashError) window.flashError(data.msg || 'Failed to update expiry');
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
setExpiryBtn.disabled = false;
|
||||
select.disabled = false;
|
||||
setExpiryBtn.innerHTML = origText;
|
||||
console.error('Error setting expiry:', err);
|
||||
if (window.flashError) window.flashError('Network error');
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// Close when clicking outside modal content
|
||||
const infoModal = document.getElementById('info-modal');
|
||||
if (infoModal && e.target === infoModal) {
|
||||
|
||||
@@ -1491,6 +1491,7 @@ window.initUploadForm = (selector) => {
|
||||
|
||||
let ratingSwitch = '';
|
||||
let visibilitySwitch = '';
|
||||
let expirySwitch = '';
|
||||
let tagsUI = '';
|
||||
let ocUI = '';
|
||||
let commentUI = '';
|
||||
@@ -1543,6 +1544,31 @@ window.initUploadForm = (selector) => {
|
||||
visibilitySwitch = '';
|
||||
}
|
||||
|
||||
const globalExpiryEl = form.querySelector('select[name="expiry"], input[name="expiry"]');
|
||||
const hasExpirySection = !!globalExpiryEl || window.f0ckEnableExpiringUploads !== false;
|
||||
if (hasExpirySection && globalExpiryEl) {
|
||||
const globalExpiry = globalExpiryEl.value || 'permanent';
|
||||
const expiryValue = (item.expiry !== undefined && item.expiry !== '') ? item.expiry : globalExpiry;
|
||||
item.expiry = expiryValue;
|
||||
|
||||
expirySwitch = `
|
||||
<div class="item-expiry-container" style="margin-top: 4px;">
|
||||
<select class="item-expiry-select" style="width: 100%; padding: 4px 8px; background: rgba(0,0,0,0.3); color: #fff; border: 1px solid var(--nav-border-color, rgba(255,255,255,0.1)); border-radius: 4px; font-size: 0.85em; cursor: pointer;">
|
||||
<option value="permanent" ${expiryValue === 'permanent' ? 'selected' : ''}>Permanent (Never expires)</option>
|
||||
<option value="30minutes" ${expiryValue === '30minutes' ? 'selected' : ''}>30 Minutes</option>
|
||||
<option value="1hour" ${expiryValue === '1hour' ? 'selected' : ''}>1 Hour</option>
|
||||
<option value="24hours" ${expiryValue === '24hours' ? 'selected' : ''}>24 Hours</option>
|
||||
<option value="1week" ${expiryValue === '1week' ? 'selected' : ''}>1 Week</option>
|
||||
<option value="1month" ${expiryValue === '1month' ? 'selected' : ''}>1 Month</option>
|
||||
</select>
|
||||
</div>
|
||||
`;
|
||||
} else {
|
||||
expirySwitch = '';
|
||||
}
|
||||
|
||||
|
||||
|
||||
const tagsPlaceholder = window.f0ckI18n?.upload_tags_placeholder || 'Tags...';
|
||||
const minTagsHint = shitpostMinTags > 0 ? ` (min ${shitpostMinTags})` : '';
|
||||
tagsUI = `
|
||||
@@ -1587,6 +1613,7 @@ window.initUploadForm = (selector) => {
|
||||
${titleUI}
|
||||
${ratingSwitch}
|
||||
${visibilitySwitch}
|
||||
${expirySwitch}
|
||||
${tagsUI}
|
||||
${commentUI}
|
||||
`;
|
||||
@@ -1607,6 +1634,15 @@ window.initUploadForm = (selector) => {
|
||||
};
|
||||
});
|
||||
|
||||
// Handle Expiry
|
||||
const expirySelect = infoRow.querySelector('.item-expiry-select');
|
||||
if (expirySelect) {
|
||||
expirySelect.onchange = () => {
|
||||
item.expiry = expirySelect.value;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
// Handle Comment
|
||||
const commentInput = infoRow.querySelector('.item-comment-input');
|
||||
const emojiTrigger = infoRow.querySelector('.item-emoji-trigger');
|
||||
@@ -2472,6 +2508,9 @@ window.initUploadForm = (selector) => {
|
||||
try {
|
||||
const globalVisEl = form.querySelector('input[name="visibility"]:checked');
|
||||
const visibilityVal = globalVisEl ? globalVisEl.value : '0';
|
||||
const globalExpiryEl = form.querySelector('select[name="expiry"], input[name="expiry"]');
|
||||
const expiryVal = globalExpiryEl ? globalExpiryEl.value : 'permanent';
|
||||
|
||||
const resp = await fetch('/api/v2/upload-url', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
@@ -2483,6 +2522,7 @@ window.initUploadForm = (selector) => {
|
||||
url,
|
||||
rating: globalRatingEl ? globalRatingEl.value : 'sfw',
|
||||
visibility: visibilityVal,
|
||||
expiry: expiryVal,
|
||||
tags: tags.join(','),
|
||||
comment: comment,
|
||||
is_oc: isOc,
|
||||
@@ -2590,10 +2630,12 @@ window.initUploadForm = (selector) => {
|
||||
for (let i = 0; i < selectedFiles.length; i++) {
|
||||
const item = selectedFiles[i];
|
||||
const globalVisEl = form.querySelector('input[name="visibility"]:checked');
|
||||
const globalExpiryEl = form.querySelector('select[name="expiry"], input[name="expiry"]');
|
||||
const isUrlItem = isShitpost && item.type === 'url';
|
||||
const file = !isUrlItem ? (isShitpost ? item.file : item) : null;
|
||||
const fileRating = isShitpost ? item.rating : (globalRatingEl ? globalRatingEl.value : 'sfw');
|
||||
const fileVisibility = isShitpost ? (item.visibility || globalVisEl?.value || '0') : (globalVisEl?.value || '0');
|
||||
const fileExpiry = isShitpost ? (item.expiry || globalExpiryEl?.value || 'permanent') : (globalExpiryEl?.value || 'permanent');
|
||||
const fileTags = isShitpost ? item.tags : tags;
|
||||
const fileComment = isShitpost ? item.comment : comment;
|
||||
const fileTitle = isShitpost ? (item.title || '') : titleVal;
|
||||
@@ -2611,6 +2653,7 @@ window.initUploadForm = (selector) => {
|
||||
}
|
||||
formData.append('rating', fileRating);
|
||||
formData.append('visibility', fileVisibility);
|
||||
formData.append('expiry', fileExpiry);
|
||||
formData.append('tags', fileTags.join(','));
|
||||
formData.append('is_oc', (isShitpost ? item.is_oc : isOc) ? 'true' : 'false');
|
||||
if (isShitpost) formData.append('is_shitpost', 'true');
|
||||
@@ -2663,6 +2706,7 @@ window.initUploadForm = (selector) => {
|
||||
url: item.url,
|
||||
rating: fileRating,
|
||||
visibility: fileVisibility,
|
||||
expiry: fileExpiry,
|
||||
tags: fileTags.join(','),
|
||||
is_oc: (isShitpost ? item.is_oc : isOc),
|
||||
comment: fileComment,
|
||||
|
||||
Reference in New Issue
Block a user