fix(flash-transfer): honor create_flash_task name as the card title
create_flash_task already accepted `name`, but the flash card still showed the first filename. Use a non-empty name as the fileset title and keep the real filenames on the files themselves. Fixes #363
This commit is contained in:
2 files changed
+53
-5
No files matched your search
@@ -413,14 +413,15 @@ export class FlashTransferApi {
|
||||
* 多文件:0x93d0 的 f4 是 repeated,一个 commit 请求同时携带 fileset 内所有文件
|
||||
* 条目,每条 f6=文件序号(1,2,3...)。commit 在上传前只发一次,之后 complete →
|
||||
* 逐个 prepare/apply/sliceupload。prepare/apply 的 filesetWrap.f4 必须与 commit
|
||||
* 的 f6 一致,否则文件不计入 fileset。多文件时 ApplyFileset 的 fileName 用
|
||||
* 「<首文件名>等N个文件」、fileSize 用总和——服务端据此判定 fileset 为多文件。
|
||||
* 的 f6 一致,否则文件不计入 fileset。ApplyFileset 的 fileName 是 fileset 显示名
|
||||
* (卡片标题):有 name 用 name,否则单文件用首文件名、多文件用「<首文件名>等N个文件」。
|
||||
* fileSize 用总和——服务端据此判定 fileset 为多文件。各文件在 commit 里仍用真实文件名。
|
||||
*
|
||||
* 源文件经 stageSourceToDisk 落到本地路径后流式哈希 / 分片读取,不再经
|
||||
* loadBinarySource 整文件进内存。本地与 HTTP 上限与群文件相同(4 GiB);
|
||||
* 内联 base64 仍按 1 GiB 封顶,因为 stage 解码时会占用等量 RAM。
|
||||
*/
|
||||
async createFlashTask(files: string | string[], _name?: string, _thumbPath?: string): Promise<{ filesetId: string }> {
|
||||
async createFlashTask(files: string | string[], name?: string, _thumbPath?: string): Promise<{ filesetId: string }> {
|
||||
const fileList = Array.isArray(files) ? files : [files];
|
||||
if (fileList.length === 0) throw new Error('create_flash_task: files is empty');
|
||||
const uploader = {
|
||||
@@ -449,12 +450,14 @@ export class FlashTransferApi {
|
||||
});
|
||||
if (staged.fileSize === 0) throw new Error('create_flash_task: file is empty');
|
||||
}
|
||||
// 申请 fileset。多文件时 fileName 用「<首文件名>等N个文件」、fileSize 用总和,
|
||||
// 申请 fileset。fileName 是卡片/面板上的 fileset 标题;各文件真实名走 commit。
|
||||
// 未指定 name 时,多文件用「<首文件名>等N个文件」、fileSize 用总和,
|
||||
// 服务端据此判定 fileset 为多文件,commit 的后续 entry 才会被计入。
|
||||
const first = items[0];
|
||||
const { typeCode } = FlashTransferApi.fileTypeCode(first.fileName);
|
||||
const isMulti = items.length > 1;
|
||||
const filesetName = isMulti ? `${first.fileName}等${items.length}个文件` : first.fileName;
|
||||
const filesetName = name?.trim()
|
||||
|| (isMulti ? `${first.fileName}等${items.length}个文件` : first.fileName);
|
||||
const totalSize = items.reduce((s, it) => s + it.fileSize, 0);
|
||||
const apply = await ApplyFileset.invoke(this.ctx, {
|
||||
fileName: filesetName, origName: filesetName,
|
||||
|
||||
@@ -252,6 +252,51 @@ describe('FlashTransferApi.createFlashTask — disk streaming (#359)', () => {
|
||||
expect(Buffer.from(uploaded[1]!.payload!.chunk!).equals(Buffer.from(b))).toBe(true);
|
||||
});
|
||||
|
||||
it('uses the optional name as the fileset title and keeps real file names on commit (#363)', async () => {
|
||||
const file = writeSrc('clip.mp4', synth(40, 3));
|
||||
installSliceuploadOk();
|
||||
|
||||
await api().createFlashTask(file, '自定义名称');
|
||||
|
||||
expect(ApplyFileset.invoke).toHaveBeenCalledWith(expect.anything(), expect.objectContaining({
|
||||
fileName: '自定义名称',
|
||||
origName: '自定义名称',
|
||||
fileSize: 40,
|
||||
}));
|
||||
expect(CommitFile.invoke).toHaveBeenCalledWith(expect.anything(), expect.objectContaining({
|
||||
entries: [expect.objectContaining({ fileName: 'clip.mp4', fileSize: 40 })],
|
||||
}));
|
||||
});
|
||||
|
||||
it('uses the optional name as the multi-file fileset title (#363)', async () => {
|
||||
const fileA = writeSrc('a.mp4', synth(50, 1));
|
||||
const fileB = writeSrc('b.zip', synth(70, 2));
|
||||
installSliceuploadOk();
|
||||
|
||||
await api().createFlashTask([fileA, fileB], '相册');
|
||||
|
||||
expect(ApplyFileset.invoke).toHaveBeenCalledWith(expect.anything(), expect.objectContaining({
|
||||
fileName: '相册',
|
||||
origName: '相册',
|
||||
fileSize: 120,
|
||||
}));
|
||||
const commit = vi.mocked(CommitFile.invoke).mock.calls[0]![1];
|
||||
expect(commit.entries[0]).toEqual(expect.objectContaining({ fileName: 'a.mp4' }));
|
||||
expect(commit.entries[1]).toEqual(expect.objectContaining({ fileName: 'b.zip' }));
|
||||
});
|
||||
|
||||
it('falls back to the filename title when name is blank (#363)', async () => {
|
||||
const file = writeSrc('clip.mp4', synth(32, 9));
|
||||
installSliceuploadOk();
|
||||
|
||||
await api().createFlashTask(file, ' ');
|
||||
|
||||
expect(ApplyFileset.invoke).toHaveBeenCalledWith(expect.anything(), expect.objectContaining({
|
||||
fileName: 'clip.mp4',
|
||||
origName: 'clip.mp4',
|
||||
}));
|
||||
});
|
||||
|
||||
it('rejects a source that mutates between hashing and upload', async () => {
|
||||
const file = writeSrc('mut.mp4', synth(90, 5));
|
||||
const actualHash = hashMod.hashFlashFileStreaming;
|
||||
|
||||
Reference in new issue
Block a user