v1.3.9: 받아오기 — 표시 이름에 '..' 이 든 녹음 파일 이름도 받는다 (폴더 구분자만 막음)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -6,7 +6,7 @@ import path from 'node:path';
|
||||
import { Store } from '../src/core/db/db.ts';
|
||||
import { AudioNamer, audioFileName, safePart } from '../src/core/audio-names.ts';
|
||||
import { Bundles } from '../src/core/bundles.ts';
|
||||
import { readZip } from '../src/core/util/zip.ts';
|
||||
import { readZip, writeZip } from '../src/core/util/zip.ts';
|
||||
|
||||
const tmp = () => fs.mkdtempSync(path.join(process.env.TMPDIR || os.tmpdir(), 'gvr-names-'));
|
||||
const at = (h: number, m: number, s: number) => new Date(2026, 9, 16, h, m, s).getTime();
|
||||
@@ -74,3 +74,52 @@ test('녹음 파일 이름: 실제 파일을 바꾸고, 경기 뒤 라운드 ·
|
||||
assert.ok(fs.existsSync(store.getUtterance('a1')!.audio_path!));
|
||||
store.close();
|
||||
});
|
||||
|
||||
test('녹음 파일 이름: 표시 이름에 ".." 이 있어도 zip 내보내기 → 지우기 → 받아오기로 되살린다', () => {
|
||||
const dir = tmp();
|
||||
const audio = path.join(dir, 'audio');
|
||||
const store = new Store(path.join(dir, 'db.sqlite'));
|
||||
store.upsertUser({ id: 'u1', name: '하늘..별', avatar: null });
|
||||
const namer = new AudioNamer(store, { summary: () => ({ mode: '', map: { name: '' } }), liveRound: () => null } as any, () => false);
|
||||
const f = path.join(audio, 'day', 'x1.ogg');
|
||||
fs.mkdirSync(path.dirname(f), { recursive: true });
|
||||
fs.writeFileSync(f, Buffer.concat([Buffer.from('OggS'), Buffer.alloc(50)]));
|
||||
const ts = at(5, 0, 0);
|
||||
store.insertUtterance({ id: 'x1', session_id: null, user_id: 'u1', started_at: ts, ended_at: ts + 1000, audio_path: f, match_id: null });
|
||||
store.updateUtteranceResult('x1', { text: '안녕', raw_text: null, words: [], noise: false, noise_reason: null, confidence: 1, lufs: -20, gain_db: 0, model: 'm', status: 'precise' });
|
||||
assert.equal(namer.refresh('x1'), true);
|
||||
assert.equal(path.basename(store.getUtterance('x1')!.audio_path!), '2026-10-16_05-00-00_하늘..별_경기밖_x1.ogg');
|
||||
const b = new Bundles(store, { summary: () => ({ mode: '', map: { name: '' }, score: null, win: null }) } as any, () => audio, 'test', (ids) => ids.forEach((id) => namer.refresh(id)));
|
||||
const id = b.list()[0].id;
|
||||
const { zip } = b.export([id]);
|
||||
assert.ok(readZip(zip).has('audio/2026-10-16_05-00-00_하늘..별_경기밖_x1.ogg'));
|
||||
b.delete([id]);
|
||||
assert.equal(store.getUtterance('x1'), undefined);
|
||||
const r = b.import(zip);
|
||||
assert.equal(r.added.utterances, 1);
|
||||
assert.equal(r.added.audio, 1);
|
||||
const back = store.getUtterance('x1')!;
|
||||
assert.equal(back.text, '안녕');
|
||||
assert.ok(fs.existsSync(back.audio_path!));
|
||||
assert.ok(back.audio_path!.startsWith(audio), '받은 파일은 이 PC 의 audio 폴더 안에만 쓴다');
|
||||
store.close();
|
||||
});
|
||||
|
||||
test('받아오기: 폴더를 넘나드는 zip 안 이름은 막는다', () => {
|
||||
const dir = tmp();
|
||||
const store = new Store(path.join(dir, 'db.sqlite'));
|
||||
store.upsertUser({ id: 'u1', name: '하늘', avatar: null });
|
||||
const b = new Bundles(store, { summary: () => ({ mode: '', map: { name: '' }, score: null, win: null }) } as any, () => path.join(dir, 'audio'), 'test');
|
||||
for (const bad of ['audio/../x1.ogg', 'audio/..\\x1.ogg', 'audio/sub/x1.ogg', '../x1.ogg']) {
|
||||
const data = { users: [{ id: 'u1', name: '하늘' }], utterances: [{ id: 'x1', user_id: 'u1', started_at: 1, ended_at: 2, audio: bad }] };
|
||||
const manifest = { format: 'gvr-bundle', version: 1, bundles: [{ kind: 'talk', id: 'talk-x1' }], counts: { utterances: 1 } };
|
||||
const zip = writeZip([
|
||||
{ name: 'manifest.json', data: Buffer.from(JSON.stringify(manifest)) },
|
||||
{ name: 'data.json', data: Buffer.from(JSON.stringify(data)) },
|
||||
{ name: bad, data: Buffer.from('OggS....') },
|
||||
]);
|
||||
assert.throws(() => b.import(zip), /음성 파일 이름이 잘못되었습니다/, bad);
|
||||
}
|
||||
assert.equal(store.getUtterance('x1'), undefined);
|
||||
store.close();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user