mirror of
https://github.com/legop3/MultiRoombaRover.git
synced 2026-09-16 01:21:20 -04:00
ugh
This commit is contained in:
@@ -604,7 +604,7 @@ async function buildReplayVideo({ sources = [] } = {}) {
|
|||||||
|
|
||||||
function getReplayHealthSnapshot() {
|
function getReplayHealthSnapshot() {
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
const neededWindowMs = BUILD_DURATION_MS;
|
const neededCount = Math.max(1, Math.ceil(BUILD_DURATION_MS / 1000));
|
||||||
const sources = [];
|
const sources = [];
|
||||||
let readyCount = 0;
|
let readyCount = 0;
|
||||||
|
|
||||||
@@ -617,20 +617,41 @@ function getReplayHealthSnapshot() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (const source of replaySources) {
|
for (const source of replaySources) {
|
||||||
const entries = getVideoEntriesForSource({ id: source.id });
|
const key = sourceKey({ sourceType: source.type, kind: 'video', id: String(source.id) });
|
||||||
const inWindow = entries.filter((entry) => now - entry.endMs <= BUFFER_SECONDS * 1000);
|
const dir = sourceDirForKey(key);
|
||||||
const newest = inWindow[inWindow.length - 1] || null;
|
let recentCount = 0;
|
||||||
const oldest = inWindow[0] || null;
|
let lastSegmentAt = null;
|
||||||
const coveredMs = newest && oldest ? Math.max(0, newest.endMs - oldest.startMs) : 0;
|
try {
|
||||||
const ready = coveredMs >= neededWindowMs;
|
const files = fs.readdirSync(dir);
|
||||||
|
for (const name of files) {
|
||||||
|
if (!/^seg-\d{6}\.mp4$/.test(name)) continue;
|
||||||
|
const full = path.join(dir, name);
|
||||||
|
let stat;
|
||||||
|
try {
|
||||||
|
stat = fs.statSync(full);
|
||||||
|
} catch {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!stat.isFile() || stat.size < 4096) continue;
|
||||||
|
if (stat.mtimeMs > (lastSegmentAt || 0)) {
|
||||||
|
lastSegmentAt = stat.mtimeMs;
|
||||||
|
}
|
||||||
|
if (now - stat.mtimeMs <= BUFFER_SECONDS * 1000) {
|
||||||
|
recentCount += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// ignore missing source directory
|
||||||
|
}
|
||||||
|
const ready = recentCount >= neededCount;
|
||||||
if (ready) readyCount += 1;
|
if (ready) readyCount += 1;
|
||||||
sources.push({
|
sources.push({
|
||||||
type: source.type,
|
type: source.type,
|
||||||
id: source.id,
|
id: source.id,
|
||||||
label: source.label,
|
label: source.label,
|
||||||
recentCount: inWindow.length,
|
recentCount,
|
||||||
neededCount: Math.ceil(neededWindowMs / 1000),
|
neededCount,
|
||||||
lastSegmentAt: newest?.endMs || null,
|
lastSegmentAt,
|
||||||
ready,
|
ready,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user