fix(upload_mgr): show errors in uploading

This commit is contained in:
hexxa 2021-09-28 21:12:50 +08:00 committed by Hexxa
parent 9c3a947795
commit b8fdb2bbee

View file

@ -25,7 +25,10 @@ export class UploadMgr {
private intervalID: number; private intervalID: number;
private worker: IWorker; private worker: IWorker;
private infos = OrderedMap<string, UploadEntry>(); private infos = OrderedMap<string, UploadEntry>();
private statusCb = (infos: Map<string, UploadEntry>, refresh: boolean): void => {}; private statusCb = (
infos: Map<string, UploadEntry>,
refresh: boolean
): void => {};
constructor(worker: IWorker) { constructor(worker: IWorker) {
this.worker = worker; this.worker = worker;
@ -49,7 +52,6 @@ export class UploadMgr {
info.state === UploadState.Ready || info.state === UploadState.Ready ||
info.state === UploadState.Created info.state === UploadState.Created
) { ) {
this.infos = this.infos.set(info.filePath, { this.infos = this.infos.set(info.filePath, {
...info, ...info,
state: UploadState.Uploading, state: UploadState.Uploading,
@ -88,7 +90,9 @@ export class UploadMgr {
return this.cycle; return this.cycle;
}; };
setStatusCb = (cb: (infos: Map<string, UploadEntry>, refresh: boolean) => void) => { setStatusCb = (
cb: (infos: Map<string, UploadEntry>, refresh: boolean) => void
) => {
this.statusCb = cb; this.statusCb = cb;
}; };
@ -144,12 +148,10 @@ export class UploadMgr {
stop = (filePath: string) => { stop = (filePath: string) => {
const entry = this.infos.get(filePath); const entry = this.infos.get(filePath);
if (entry != null) { if (entry != null) {
this.infos = this.infos.set(filePath, { this.infos = this.infos.set(filePath, {
...entry, ...entry,
state: UploadState.Stopped, state: UploadState.Stopped,
}); });
} else { } else {
alert(`failed to stop uploading ${filePath}: not found`); alert(`failed to stop uploading ${filePath}: not found`);
} }
@ -178,7 +180,7 @@ export class UploadMgr {
this.infos = this.infos.set(errResp.filePath, { this.infos = this.infos.set(errResp.filePath, {
...errEntry, ...errEntry,
state: UploadState.Error, state: UploadState.Error,
err: `${errEntry.err} / ${errResp.filePath}`, err: errResp.err,
}); });
} else { } else {
// TODO: refine this // TODO: refine this
@ -201,7 +203,8 @@ export class UploadMgr {
uploaded: infoResp.uploaded, uploaded: infoResp.uploaded,
state: state:
// this avoids overwriting Stopped/Error state // this avoids overwriting Stopped/Error state
(entry.state === UploadState.Stopped || entry.state === UploadState.Error) entry.state === UploadState.Stopped ||
entry.state === UploadState.Error
? UploadState.Stopped ? UploadState.Stopped
: infoResp.state, : infoResp.state,
}); });