(tempId: string, url: string, password: string, options: UploadOptions)
| 49 | } |
| 50 | |
| 51 | async init(tempId: string, url: string, password: string, options: UploadOptions) { |
| 52 | const { state: uploadCfg, execute: uploadFile } = uploadFileApi(); |
| 53 | try { |
| 54 | await uploadFile({ |
| 55 | timeout: Number.MAX_VALUE, |
| 56 | url: `${url}/upload-new/${password}`, |
| 57 | params: { |
| 58 | filename: this.file.name, |
| 59 | size: this.file.size, |
| 60 | sum: "", |
| 61 | ...options |
| 62 | } |
| 63 | }); |
| 64 | |
| 65 | if (!uploadCfg.value?.id) { |
| 66 | throw new Error(t("TXT_CODE_62051fcc")); |
| 67 | } |
| 68 | const id = uploadCfg.value?.id; |
| 69 | this.id = id; |
| 70 | this.pieceUrl = `${url}/upload-piece/${id}`; |
| 71 | uploadService.changeId(tempId, id); |
| 72 | |
| 73 | const received: { start: number; end: number }[] = uploadCfg.value?.received!; |
| 74 | if (received.length > 0 && received[0].start == 0) { |
| 75 | this.offset = received[0].end; |
| 76 | } |
| 77 | |
| 78 | this.prepared = true; |
| 79 | if (this.canceled) { |
| 80 | await this.stop(); |
| 81 | } |
| 82 | |
| 83 | uploadService.update(); |
| 84 | } catch (err: any) { |
| 85 | this.removing = true; |
| 86 | return reportErrorMsg(err.response?.data || err.message); |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | addCallback(type: "start" | "end", callback: () => void) { |
| 91 | if (type == "start") { |
no test coverage detected