feat(recording): consolidate recording pipeline on server B

This commit is contained in:
hectorzhao
2026-08-27 16:57:45 +08:00
parent 32bba1bd84
commit be53848dee
12 changed files with 260 additions and 22 deletions
+31 -1
View File
@@ -1,4 +1,4 @@
import { mkdtemp, readFile, rm, stat, writeFile } from 'node:fs/promises';
import { mkdir, mkdtemp, readFile, rm, stat, writeFile } from 'node:fs/promises';
import os from 'node:os';
import path from 'node:path';
@@ -6,6 +6,7 @@ import { describe, expect, it } from 'vitest';
import {
callIdFromStorageKey,
LocalRecordingClient,
normalizeRemoteRelativePath,
type PulledRecordingFile,
type RecordingStore,
@@ -90,6 +91,35 @@ describe('recording transfer', () => {
}
});
it('lists, copies, and deletes ready files from a local source directory', async () => {
const root = await mkdtemp(path.join(os.tmpdir(), 'lisglosips-local-rec-'));
const readyDir = path.join(root, 'ready');
const outputDir = path.join(root, 'recordings');
const sourcePath = path.join(readyDir, '2026', '08', '27', 'call.wav.ready');
const client = new LocalRecordingClient({ readyDir });
const store = new MemoryStore();
const service = new RecordingTransferService(client, store, {
localRoot: outputDir,
deleteSourceAfterCopy: true,
maxFilesPerScan: 10
});
try {
await mkdir(path.dirname(sourcePath), { recursive: true });
await writeFile(sourcePath, 'local-audio');
await writeFile(path.join(readyDir, 'ignored.part'), 'incomplete');
await expect(client.listReadyFiles()).resolves.toEqual([
{ relativePath: '2026/08/27/call.wav.ready', bytes: 11 }
]);
await expect(service.scanOnce()).resolves.toEqual({ moved: 1, skipped: 0, failed: 0 });
await expect(readFile(path.join(outputDir, '2026', '08', '27', 'call.wav'), 'utf8')).resolves.toBe('local-audio');
await expect(stat(sourcePath)).rejects.toThrow();
} finally {
await rm(root, { recursive: true, force: true });
}
});
it('keeps source file when local size verification fails', async () => {
const root = await mkdtemp(path.join(os.tmpdir(), 'lisglosips-rec-'));
const remote = new MemoryRemote(new Map([['bad.wav.ready', Buffer.from('abc')]]));