load image fallback
This commit is contained in:
@@ -116,6 +116,10 @@ App.favorites = App.favorites || {};
|
||||
${uploaderText ? `<p><button class="uploader-link" type="button" data-uploader="${uploaderText}">${uploaderText}</button></p>` : ''}
|
||||
</div>
|
||||
`;
|
||||
const thumb = card.querySelector('img');
|
||||
if (App.videos && typeof App.videos.attachNoReferrerRetry === 'function') {
|
||||
App.videos.attachNoReferrerRetry(thumb);
|
||||
}
|
||||
card.onclick = () => App.player.open(item.url);
|
||||
const favoriteBtn = card.querySelector('.favorite-btn');
|
||||
if (favoriteBtn) {
|
||||
|
||||
@@ -28,6 +28,36 @@ App.videos = App.videos || {};
|
||||
return `${minutes}m`;
|
||||
};
|
||||
|
||||
App.videos.buildImageProxyUrl = function(imageUrl) {
|
||||
if (!imageUrl) return '';
|
||||
try {
|
||||
return `/api/image?url=${encodeURIComponent(imageUrl)}&ts=${Date.now()}`;
|
||||
} catch (err) {
|
||||
return '';
|
||||
}
|
||||
};
|
||||
|
||||
App.videos.attachNoReferrerRetry = function(img) {
|
||||
if (!img) return;
|
||||
if (!img.dataset.originalSrc) {
|
||||
img.dataset.originalSrc = img.currentSrc || img.src || '';
|
||||
}
|
||||
img.dataset.noReferrerRetry = '0';
|
||||
img.addEventListener('error', () => {
|
||||
if (img.dataset.noReferrerRetry === '1') return;
|
||||
img.dataset.noReferrerRetry = '1';
|
||||
img.referrerPolicy = 'no-referrer';
|
||||
img.removeAttribute('crossorigin');
|
||||
const original = img.dataset.originalSrc || img.currentSrc || img.src || '';
|
||||
const proxyUrl = App.videos.buildImageProxyUrl(original);
|
||||
if (proxyUrl) {
|
||||
img.src = proxyUrl;
|
||||
} else if (original) {
|
||||
img.src = original;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// Fetches the next page of videos and renders them into the grid.
|
||||
App.videos.loadVideos = async function() {
|
||||
const session = App.storage.getSession();
|
||||
@@ -108,6 +138,8 @@ App.videos = App.videos || {};
|
||||
${uploaderText ? `<p class="video-meta"><button class="uploader-link" type="button" data-uploader="${uploaderText}">${uploaderText}</button></p>` : ''}
|
||||
${durationText ? `<p class="video-duration">${durationText}</p>` : ''}
|
||||
`;
|
||||
const thumb = card.querySelector('img');
|
||||
App.videos.attachNoReferrerRetry(thumb);
|
||||
const favoriteBtn = card.querySelector('.favorite-btn');
|
||||
if (favoriteBtn && favoriteKey) {
|
||||
App.favorites.setButtonState(favoriteBtn, favoritesSet.has(favoriteKey));
|
||||
|
||||
Reference in New Issue
Block a user