fix(web): make cancel, delete and chat work while a file is uploading [CI]
This commit is contained in:
1 parent
1245aedfd2
commit
7ef298f587
4 files changed
+34
-6
No files matched your search
@@ -109,9 +109,26 @@ async function dispatch(operation: string, input: unknown): Promise<unknown> {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 账号和空间的操作按顺序执行(登录、同步、改设置等互相依赖)。但上传、发消息、删除、取消是长任务或互不依赖:
|
||||
* 如果也排在这条队列里,一个大文件的 sendFiles 会让取消按钮、聊天消息、删除全部等到上传结束才生效。
|
||||
*/
|
||||
function laneOf(operation: string, payload: Record<string, unknown>): string | undefined {
|
||||
const space = String(payload.id ?? '');
|
||||
switch (operation) {
|
||||
case 'cancelUpload': return undefined;
|
||||
case 'sendFiles': return `upload:${space}`;
|
||||
case 'sendText': case 'editChannelText': return `chat:${space}`;
|
||||
case 'removeChannelItem': return `item:${space}`;
|
||||
default: return 'account-scope';
|
||||
}
|
||||
}
|
||||
|
||||
scope.onmessage = (event) => {
|
||||
const request = event.data;
|
||||
const task = serial('account-scope', () => dispatch(request.operation, request.payload));
|
||||
const lane = laneOf(request.operation, request.payload as Record<string, unknown>);
|
||||
const run = () => dispatch(request.operation, request.payload);
|
||||
const task = lane ? serial(lane, run) : run();
|
||||
void task.then(
|
||||
(result) => scope.postMessage({ requestId: request.requestId, result }),
|
||||
(error: unknown) => scope.postMessage({
|
||||
|
||||
@@ -3,6 +3,7 @@ import { dequeueFrame, dequeueItem, queueFrame, queueLocation, saveResource, typ
|
||||
import { errorMessage } from '../errors';
|
||||
import type { FileItem, FileUploadOptions } from '../types';
|
||||
import { prepareObject } from './channelDataKeys';
|
||||
import { removeChannelItem } from './channelItems';
|
||||
import { queueFileCatalog } from './channelThreads';
|
||||
import { deviceIdentity, publishWorkspace } from './presentation';
|
||||
import { senderSnapshot } from './senderSnapshot';
|
||||
@@ -160,6 +161,8 @@ async function discard(resource: SavedResource, item: FileItem | undefined): Pro
|
||||
await saveResource(resource);
|
||||
blobs.delete(`${resource.id}:${item.id}`);
|
||||
publishWorkspace(resource.id, { t: 'removed', id: item.id });
|
||||
// 服务端可能已收下前几帧:删掉这个没传完的条目,不然它会一直占着空间配额(没传完的条目服务端允许直接删)。第 0 帧都没到服务端时返回 404,忽略
|
||||
void removeChannelItem(resource.id, item.id).catch(() => undefined);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user