rover snapshots in server

This commit is contained in:
legop3
2026-01-13 18:54:30 -05:00
parent b7a79b03c9
commit 5fdcb233f8
5 changed files with 72 additions and 42 deletions
@@ -62,10 +62,17 @@ async function listLatestSegments(sourceKey, neededCount) {
const dir = path.join(replaySegmentsDir, sourceKey);
const entries = await fsp.readdir(dir, { withFileTypes: true });
const files = [];
const now = Date.now();
for (const entry of entries) {
if (!entry.isFile() || !entry.name.endsWith('.mp4')) continue;
const filePath = path.join(dir, entry.name);
const stat = await fsp.stat(filePath);
if (stat.size < 16 * 1024) {
continue;
}
if (now - stat.mtimeMs < segmentSeconds * 1000) {
continue;
}
files.push({ filePath, mtimeMs: stat.mtimeMs });
}
files.sort((a, b) => a.mtimeMs - b.mtimeMs);