feat(flash-transfer): let create_flash_task set per-file names

upload_file_stream now returns file_name with the original name.
create_flash_task accepts { file, name } so a streamed path can
keep the real filename on the fileset.

Fixes #361
This commit is contained in:
DrSmoothl committed 2026-08-14 14:17:58 +08:00
1 parent 925d9c0ac7
commit d014d6c379
8 files changed
+170 -28

No files matched your search

+15 -1
View File
@@ -42,7 +42,10 @@ describe('upload_file_stream', () => {
r = await handleUpload(mk({ stream_id: id, total_chunks: 3, is_complete: true, expected_sha256: sha }));
const data = r.data as Record<string, unknown>;
expect(data).toMatchObject({ type: 'response', status: 'file_complete', total_chunks: 3, file_size: full.length, sha256: sha });
expect(data).toMatchObject({
type: 'response', status: 'file_complete', total_chunks: 3,
file_size: full.length, sha256: sha, file_name: `upload_${id}`,
});
expect(fs.readFileSync(String(data.file_path), 'utf8')).toBe(full);
// state dropped after completion, chunk dir gone
expect(uploads.has(id)).toBe(false);
@@ -97,6 +100,17 @@ describe('upload_file_stream', () => {
await expect(handleUpload(mk({ stream_id: 'nope', verify_only: true }))).rejects.toThrow(/not found/i);
});
it('returns the original filename alongside the prefixed file_path (#361)', async () => {
const id = 'up-named';
await handleUpload(mk({
stream_id: id, total_chunks: 1, chunk_index: 0, chunk_data: b64('x'), filename: 'report.pdf',
}));
const r = await handleUpload(mk({ stream_id: id, total_chunks: 1, is_complete: true }));
const data = r.data as Record<string, unknown>;
expect(data.file_name).toBe('report.pdf');
expect(String(data.file_path)).toBe(path.join(STREAM_UPLOAD_DIR, `${id}__report.pdf`));
});
it('strips path separators from filename (no temp-dir escape)', async () => {
const id = 'up-escape';
await handleUpload(mk({ stream_id: id, total_chunks: 1, chunk_index: 0, chunk_data: b64('x'), filename: '../../evil.sh' }));