From 5bc9139fc52cd90d0cfe9c94eb3be6d7f77cf661 Mon Sep 17 00:00:00 2001 From: chiayin Date: Tue, 16 Jan 2024 11:40:03 +0800 Subject: [PATCH] fix: Files Upload API & Rename API done. --- src/stores/files.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/stores/files.js b/src/stores/files.js index e379e73..744e2b4 100644 --- a/src/stores/files.js +++ b/src/stores/files.js @@ -151,21 +151,19 @@ export default defineStore('filesStore', { uploadloader(); // 進度條 try { const response = await axios.post(api, data); - this.uploadLogId = response.data.id; - Swal.close(); // 關閉進度條 - this.rename(); // 改檔名 + + this.uploadLogId = await response.data.id; + await Swal.close(); // 關閉進度條 + await this.rename(); // 改檔名 await uploadSuccess(); this.$router.push({name: 'Files'}); } catch(error) { - console.log('error:', error); if(error.response.status === 422) { uploadFailedSecond(error.response.data.detail[0].type, error.response.data.detail[0].msg); } else { Swal.close(); // 關閉進度條 apiError(error, 'Failed to upload the log files.'); } - } finally { - // await this.rename(); } }, /** @@ -176,14 +174,15 @@ export default defineStore('filesStore', { */ async rename(type, id, fileName) { // 先判斷有沒有 uploadLogId,有就設定 id 和 type;再判斷檔案型別。 - let api; - let data = {"name": fileName}; - if(this.uploadId && this.uploadFileName) { type = 'log'; id = this.uploadLogId; fileName = this.uploadFileName; } + + let api; + let data = {"name": fileName}; + switch (type) { case 'log': api = `/api/logs/${id}/name`;