diff --git a/public/js/main.js b/public/js/main.js index 7da5271..fafe3d3 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -94,6 +94,7 @@ document.addEventListener('DOMContentLoaded', () => { let managedSubtitleTracks = []; let selectedSubtitleTrackId = 'off'; let pendingAutoPlayAfterDownload = false; + let lastPolledProgressSignature = ''; if (videoPlayer) { videoPlayer.controls = false; @@ -1377,10 +1378,22 @@ document.addEventListener('DOMContentLoaded', () => { const pollProgress = async () => { if (!currentVideoKey) return; try { - const res = await fetch(`/api/progress?key=${encodeURIComponent(currentVideoKey)}`); + const res = await fetch(`/api/progress?key=${encodeURIComponent(currentVideoKey)}&_=${Date.now()}`, { + cache: 'no-store' + }); if (!res.ok) return; const data = await res.json(); if (data?.progress) { + const nextSignature = `${data.progress.status}:${typeof data.progress.percent === 'number' ? data.progress.percent : 'na'}`; + if (lastPolledProgressSignature !== nextSignature) { + lastPolledProgressSignature = nextSignature; + console.log('[progress-poll]', { + status: data.progress.status, + percent: data.progress.percent, + downloadedBytes: data.progress.downloadedBytes, + totalBytes: data.progress.totalBytes + }); + } handleProgress(data.progress); if (typeof data.progress.duration === 'number' && data.progress.duration > 0) { videoDuration = data.progress.duration; diff --git a/server.js b/server.js index d979d6f..2894228 100644 --- a/server.js +++ b/server.js @@ -91,6 +91,7 @@ const createS3Client = (credentials) => { const progressMap = {}; const transcodeProcesses = new Map(); const wsSubscriptions = new Map(); +const progressApiLogMap = new Map(); const AVAILABLE_VIDEO_ENCODERS = [ { value: 'h264_rkmpp', label: 'h264_rkmpp (RKMPP H.264)' }, @@ -822,6 +823,16 @@ app.get('/api/progress', (req, res) => { const progressKey = getProgressKey(key); const progress = progressMap[progressKey] || null; + const observedState = progress + ? `${progress.status}:${typeof progress.percent === 'number' ? progress.percent : 'na'}` + : 'null'; + if (progressApiLogMap.get(progressKey) !== observedState) { + progressApiLogMap.set(progressKey, observedState); + console.log(`[progress-api] key=${key} status=${progress?.status || 'null'} percent=${typeof progress?.percent === 'number' ? progress.percent : 'na'}`); + } + res.setHeader('Cache-Control', 'no-store, no-cache, must-revalidate, proxy-revalidate'); + res.setHeader('Pragma', 'no-cache'); + res.setHeader('Expires', '0'); res.json({ progress }); } catch (error) { console.error('Error fetching progress:', error);