feat: File rename API done.
This commit is contained in:
@@ -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.');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user