修复问题6

This commit is contained in:
CN-JS-HuiBai
2026-04-03 23:39:51 +08:00
parent 500cf03652
commit 3fa6e4ef4d
2 changed files with 25 additions and 1 deletions

View File

@@ -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;

View File

@@ -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);