feat: File rename API done.

This commit is contained in:
chiayin
2024-01-11 12:26:40 +08:00
parent 01d712e487
commit d4f0801ca1
4 changed files with 104 additions and 9 deletions

View File

@@ -168,15 +168,38 @@ export default defineStore('filesStore', {
},
/**
* Rename a Log
* @param { string } type log | filter | log-check | filter-check
* @param { number } id
* @param { string } name
*/
async rename() {
const id = this.uploadLogId;
const api = `/api/logs/${id}/name`;
const data = {"name": this.uploadFileName};
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;
}
switch (type) {
case 'log':
api = `/api/logs/${id}/name`;
break;
case 'filter':
api = `/api/filters/${id}/name`;
break;
case 'log-check':
api = `/api/log-checks/${id}/name`;
break;
case 'filter-check':
api = `/api/filter-checks/${id}/name`;
break;
}
try {
const response = await axios.put(api, data);
this.uploadFileName = null;
await this.fetchAllFiles();
} catch(error) {
apiError(error, 'Failed to rename.');
}