fix(flash-transfer): finish seconds-pass flash uploads
A fileset that already exists on the server still needs the apply step so the share is not left waiting for upload. Fixes #420
This commit is contained in:
3 files changed
+9
-6
No files matched your search
@@ -570,7 +570,8 @@ export class FlashTransferApi {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 阶段1:流式哈希 + prepare(拿 rkey)+ apply(注册 fileId)。
|
* 阶段1:流式哈希 + prepare(拿 rkey)+ apply(注册 fileId)。
|
||||||
* 秒传(rkey=null)返回 null,调用方跳过 sliceupload。
|
* 秒传时 prepare 不回 rkey,仍必须 apply,否则 fileset 会一直停在等待上传;
|
||||||
|
* 返回 null 只表示调用方跳过 sliceupload。
|
||||||
*/
|
*/
|
||||||
private async prepareAndApply(
|
private async prepareAndApply(
|
||||||
filesetUuid: string, it: StagedFlashItem,
|
filesetUuid: string, it: StagedFlashItem,
|
||||||
@@ -582,13 +583,12 @@ export class FlashTransferApi {
|
|||||||
filesetUuid, fileUuid: it.fileUuid, fileName: it.fileName, fileSize: it.fileSize,
|
filesetUuid, fileUuid: it.fileUuid, fileName: it.fileName, fileSize: it.fileSize,
|
||||||
sha1: hashes.sha1Hex, fileIndex: it.fileIndex, formatCode: it.formatCode,
|
sha1: hashes.sha1Hex, fileIndex: it.fileIndex, formatCode: it.formatCode,
|
||||||
});
|
});
|
||||||
if (rkey === null) return null; // 秒传
|
|
||||||
|
|
||||||
const fileId = FlashTransferApi.buildFileId(hashes.sha1, it.fileSize);
|
const fileId = FlashTransferApi.buildFileId(hashes.sha1, it.fileSize);
|
||||||
await ApplyUpload.invoke(this.ctx, {
|
await ApplyUpload.invoke(this.ctx, {
|
||||||
filesetUuid, fileUuid: it.fileUuid, fileId, fileName: it.fileName, fileSize: it.fileSize,
|
filesetUuid, fileUuid: it.fileUuid, fileId, fileName: it.fileName, fileSize: it.fileSize,
|
||||||
md5: hashes.md5Hex, sha1: hashes.sha1Hex, fileIndex: it.fileIndex, formatCode: it.formatCode,
|
md5: hashes.md5Hex, sha1: hashes.sha1Hex, fileIndex: it.fileIndex, formatCode: it.formatCode,
|
||||||
});
|
});
|
||||||
|
if (rkey === null) return null;
|
||||||
return { rkey, sha1StateV: hashes.sha1StateV, sliceCount: hashes.sliceCount };
|
return { rkey, sha1StateV: hashes.sha1StateV, sliceCount: hashes.sliceCount };
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -678,12 +678,12 @@ export class FlashTransferApi {
|
|||||||
filesetUuid, fileUuid, fileName, fileSize, sha1: hashes.sha1Hex,
|
filesetUuid, fileUuid, fileName, fileSize, sha1: hashes.sha1Hex,
|
||||||
fileIndex, formatCode: thumbFormatCode, thumbType, width, height,
|
fileIndex, formatCode: thumbFormatCode, thumbType, width, height,
|
||||||
});
|
});
|
||||||
if (rkey === null) return; // 秒传
|
|
||||||
const fileId = FlashTransferApi.buildFileId(hashes.sha1, fileSize, appid);
|
const fileId = FlashTransferApi.buildFileId(hashes.sha1, fileSize, appid);
|
||||||
await ApplyUpload.invoke(this.ctx, {
|
await ApplyUpload.invoke(this.ctx, {
|
||||||
filesetUuid, fileUuid, fileId, fileName, fileSize,
|
filesetUuid, fileUuid, fileId, fileName, fileSize,
|
||||||
md5: hashes.md5Hex, sha1: hashes.sha1Hex, fileIndex, formatCode: thumbFormatCode, thumbType, width, height,
|
md5: hashes.md5Hex, sha1: hashes.sha1Hex, fileIndex, formatCode: thumbFormatCode, thumbType, width, height,
|
||||||
});
|
});
|
||||||
|
if (rkey === null) return;
|
||||||
// sliceupload(缩略图小,1 片,Sha1StateV=[标准 SHA1])
|
// sliceupload(缩略图小,1 片,Sha1StateV=[标准 SHA1])
|
||||||
const sha1StateV = computeSha1StateV(new Uint8Array(thumbBytes), 1, fileSize);
|
const sha1StateV = computeSha1StateV(new Uint8Array(thumbBytes), 1, fileSize);
|
||||||
const body: FlashSliceUploadBody = {
|
const body: FlashSliceUploadBody = {
|
||||||
|
|||||||
@@ -196,7 +196,9 @@ describe('FlashTransferApi.createFlashTask — disk streaming (#359)', () => {
|
|||||||
|
|
||||||
await api().createFlashTask(file);
|
await api().createFlashTask(file);
|
||||||
expect(mainSlices(slices)).toHaveLength(0);
|
expect(mainSlices(slices)).toHaveLength(0);
|
||||||
expect(ApplyUpload.invoke).toHaveBeenCalled(); // thumbs still apply
|
expect(ApplyUpload.invoke).toHaveBeenCalledWith(expect.anything(), expect.objectContaining({
|
||||||
|
fileName: 'hit.mp4',
|
||||||
|
}));
|
||||||
expect(SetFilesetStatus.invoke).toHaveBeenCalled();
|
expect(SetFilesetStatus.invoke).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -90,7 +90,8 @@ export namespace PrepareUpload {
|
|||||||
|
|
||||||
export const deserialize = (_ctx: Deps, body: FlashPrepareUploadResp): string | null => {
|
export const deserialize = (_ctx: Deps, body: FlashPrepareUploadResp): string | null => {
|
||||||
// sub-100 resp f2={f1:rkey}(正常上传,CAES/CAIS/CAQS/CAMS)。
|
// sub-100 resp f2={f1:rkey}(正常上传,CAES/CAIS/CAQS/CAMS)。
|
||||||
// 秒传(文件已在服务端)时 f2 无 f1(rkey),返回 null,调用方跳过 sliceupload。
|
// 秒传(文件已在服务端)时 f2 无 f1(rkey),返回 null,调用方仍要 apply,
|
||||||
|
// 只跳过 sliceupload。
|
||||||
return body.rkeyWrap?.rkey ?? null;
|
return body.rkeyWrap?.rkey ?? null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user