修复缺少函数的BUG
This commit is contained in:
25
server.js
25
server.js
@@ -120,6 +120,29 @@ const probeFile = (filePath) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const parseTimemarkToSeconds = (timemark) => {
|
||||||
|
if (typeof timemark !== 'string' || !timemark.trim()) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const parts = timemark.trim().split(':');
|
||||||
|
if (parts.length !== 3) {
|
||||||
|
const numericValue = parseFloat(timemark);
|
||||||
|
return Number.isFinite(numericValue) ? numericValue : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const [hoursPart, minutesPart, secondsPart] = parts;
|
||||||
|
const hours = parseInt(hoursPart, 10);
|
||||||
|
const minutes = parseInt(minutesPart, 10);
|
||||||
|
const seconds = parseFloat(secondsPart);
|
||||||
|
|
||||||
|
if (![hours, minutes, seconds].every(Number.isFinite)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (hours * 3600) + (minutes * 60) + seconds;
|
||||||
|
};
|
||||||
|
|
||||||
const stopActiveTranscode = (progressKey) => {
|
const stopActiveTranscode = (progressKey) => {
|
||||||
const activeCommand = transcodeProcesses.get(progressKey);
|
const activeCommand = transcodeProcesses.get(progressKey);
|
||||||
if (!activeCommand) {
|
if (!activeCommand) {
|
||||||
@@ -448,7 +471,7 @@ app.get('/api/stream', async (req, res) => {
|
|||||||
ffmpegCommand
|
ffmpegCommand
|
||||||
.on('progress', (progress) => {
|
.on('progress', (progress) => {
|
||||||
const effectiveDuration = Math.max(0, (progressMap[progressKey]?.duration || 0) - startSeconds);
|
const effectiveDuration = Math.max(0, (progressMap[progressKey]?.duration || 0) - startSeconds);
|
||||||
const timemarkSeconds = ffmpeg.timemarkToSeconds(progress.timemark || '0');
|
const timemarkSeconds = parseTimemarkToSeconds(progress.timemark || '0');
|
||||||
const absoluteSeconds = startSeconds + (isFinite(timemarkSeconds) ? timemarkSeconds : 0);
|
const absoluteSeconds = startSeconds + (isFinite(timemarkSeconds) ? timemarkSeconds : 0);
|
||||||
const percent = effectiveDuration > 0
|
const percent = effectiveDuration > 0
|
||||||
? Math.min(Math.max(Math.round((absoluteSeconds / (progressMap[progressKey]?.duration || effectiveDuration)) * 100), 0), 100)
|
? Math.min(Math.max(Math.round((absoluteSeconds / (progressMap[progressKey]?.duration || effectiveDuration)) * 100), 0), 100)
|
||||||
|
|||||||
Reference in New Issue
Block a user