From ec730875aaf8556aab9aa76ab96a95eff9350fb8 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Wed, 18 Sep 2024 23:04:42 +0800 Subject: [PATCH] :bug: Upload won't timeout --- pages/gallery/new.vue | 30 ++++++++++++++++-------------- utils/request.ts | 2 +- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/pages/gallery/new.vue b/pages/gallery/new.vue index 79c06b0..a647d12 100644 --- a/pages/gallery/new.vue +++ b/pages/gallery/new.vue @@ -6,12 +6,7 @@
- + - +
@@ -94,7 +95,7 @@ const success = ref(false) const multipartSize = ref(0) const multipartInfo = ref(null) -const multipartProgress = reactive<{ value: number | null, current: number, total: number }>({ +const multipartProgress = reactive<{ value: number | null; current: number; total: number }>({ value: null, current: 0, total: 0, @@ -147,11 +148,11 @@ async function createMultipartPlaceholder() { if (!content.value) return const mimetypeMap: { [id: string]: string } = { - "mp4": "video/mp4", - "mov": "video/quicktime", - "mp3": "audio/mp3", - "wav": "audio/wav", - "m4a": "audio/m4a", + mp4: "video/mp4", + mov: "video/quicktime", + mp3: "audio/mp3", + wav: "audio/wav", + m4a: "audio/m4a", } const mimetype = mimetypeMap[content.value.name.split(".").pop() as string] @@ -189,6 +190,7 @@ async function uploadSingleMultipart(chunkId: string) { const resp = await solarFetch(`/cgi/uc/attachments/multipart/${multipartInfo.value.rid}/${chunkId}`, { method: "POST", body: data, + signal: AbortSignal.timeout(3 * 60 * 1000), }) if (resp.status != 200) throw new Error(await resp.text()) multipartInfo.value = await resp.json() diff --git a/utils/request.ts b/utils/request.ts index 5e2ca10..9641c32 100644 --- a/utils/request.ts +++ b/utils/request.ts @@ -10,7 +10,7 @@ export async function solarFetch(input: string, init?: RequestInit) { ...init, headers: { ...init?.headers, - "Authorization": `Bearer ${await auth.getAtk()}`, + Authorization: `Bearer ${await auth.getAtk()}`, }, }) }