Apply repository-wide ESLint auto-fix formatting pass

Co-Authored-By: Codex <codex@openai.com>
This commit is contained in:
2026-03-08 12:11:57 +08:00
parent 7c48faaa3d
commit 847904c49b
172 changed files with 13629 additions and 9154 deletions

View File

@@ -11,18 +11,24 @@
import { defineStore } from "pinia";
import apiClient from "@/api/client.js";
import moment from 'moment';
import apiError from '@/module/apiError.js';
import Swal from 'sweetalert2';
import { uploadFailedFirst, uploadFailedSecond, uploadloader, uploadSuccess, deleteSuccess } from '@/module/alertModal.js';
import { useLoadingStore } from '@/stores/loading';
import moment from "moment";
import apiError from "@/module/apiError.js";
import Swal from "sweetalert2";
import {
uploadFailedFirst,
uploadFailedSecond,
uploadloader,
uploadSuccess,
deleteSuccess,
} from "@/module/alertModal.js";
import { useLoadingStore } from "@/stores/loading";
/** Map of file type to API path segment. */
const FILE_TYPE_PATHS = {
'log': 'logs',
'filter': 'filters',
'log-check': 'log-checks',
'filter-check': 'filter-checks',
log: "logs",
filter: "filters",
"log-check": "log-checks",
"filter-check": "filter-checks",
};
/**
@@ -36,22 +42,22 @@ function getFileApiBase(type, id) {
}
/** Pinia store for file CRUD operations and upload workflow. */
export const useFilesStore = defineStore('filesStore', {
export const useFilesStore = defineStore("filesStore", {
state: () => ({
allEventFiles: [
{
parentLog: '',
fileType: '',
ownerName: '',
}
parentLog: "",
fileType: "",
ownerName: "",
},
],
switchFilesTagData: {
ALL: ['Log', 'Filter', 'Rule', 'Design'],
DISCOVER: ['Log', 'Filter', 'Rule'],
COMPARE: ['Log','Filter'],
DESIGN: ['Log', 'Design'],
ALL: ["Log", "Filter", "Rule", "Design"],
DISCOVER: ["Log", "Filter", "Rule"],
COMPARE: ["Log", "Filter"],
DESIGN: ["Log", "Design"],
},
filesTag: 'ALL',
filesTag: "ALL",
httpStatus: 200,
uploadId: null,
allUploadDetail: null,
@@ -63,64 +69,64 @@ export const useFilesStore = defineStore('filesStore', {
/**
* Get allFiles and switch files tag
*/
allFiles: state => {
allFiles: (state) => {
let result = state.allEventFiles;
const data = state.switchFilesTagData;
const filesTag = state.filesTag;
result = result.filter(file => data[filesTag].includes(file.fileType));
result = result.filter((file) => data[filesTag].includes(file.fileType));
return result;
},
/**
* Get upload preview
*/
uploadDetail: state => {
uploadDetail: (state) => {
return state.allUploadDetail;
},
/**
* Get dependents of files data
*/
dependentsData: state => {
dependentsData: (state) => {
return state.allDependentsData;
}
},
},
actions: {
/**
* Fetch All Files api
*/
async fetchAllFiles() {
const api = '/api/files';
const api = "/api/files";
try {
const response = await apiClient.get(api);
this.allEventFiles = response.data;
this.allEventFiles.forEach(o => {
let icon = '';
let fileType = '';
this.allEventFiles.forEach((o) => {
let icon = "";
let fileType = "";
let parentLog = o.name;
switch (o.type) {
case 'log':
icon = 'work_history';
fileType = 'Log';
case "log":
icon = "work_history";
fileType = "Log";
parentLog = o.name;
break;
case 'filter':
icon = 'tornado';
fileType = 'Filter';
case "filter":
icon = "tornado";
fileType = "Filter";
parentLog = o.parent.name;
break;
case 'log-check':
case 'filter-check':
icon = 'local_police';
fileType = 'Rule';
case "log-check":
case "filter-check":
icon = "local_police";
fileType = "Rule";
parentLog = o.parent.name;
break;
case 'design':
icon = 'shape_line';
fileType = 'Design';
case "design":
icon = "shape_line";
fileType = "Design";
parentLog = o.name;
break;
}
@@ -130,23 +136,29 @@ export const useFilesStore = defineStore('filesStore', {
o.ownerName = o.owner.name;
o.updated_base = o.updated_at;
o.accessed_base = o.accessed_at;
o.updated_at = moment(o.updated_at).utcOffset('+08:00').format('YYYY-MM-DD HH:mm');
o.accessed_at = o.accessed_at ? moment(o.accessed_at).utcOffset('+08:00').format('YYYY-MM-DD HH:mm') : null;
o.updated_at = moment(o.updated_at)
.utcOffset("+08:00")
.format("YYYY-MM-DD HH:mm");
o.accessed_at = o.accessed_at
? moment(o.accessed_at)
.utcOffset("+08:00")
.format("YYYY-MM-DD HH:mm")
: null;
});
} catch(error) {
apiError(error, 'Failed to load the files.');
};
} catch (error) {
apiError(error, "Failed to load the files.");
}
},
/**
* Uploads a CSV log file (first stage).
* @param {Object} fromData - The form data to send to the backend.
*/
async upload(fromData) {
const api = '/api/logs/csv-uploads';
const api = "/api/logs/csv-uploads";
const config = {
data: true,
headers: {
'Content-Type': 'multipart/form-data',
"Content-Type": "multipart/form-data",
},
};
@@ -155,10 +167,10 @@ export const useFilesStore = defineStore('filesStore', {
const response = await apiClient.post(api, fromData, config);
this.uploadId = response.data.id;
this.$router.push({name: 'Upload'});
this.$router.push({ name: "Upload" });
Swal.close(); // Close the loading progress bar
} catch(error) {
if(error.response?.status === 422) {
} catch (error) {
if (error.response?.status === 422) {
// msg: 'not in UTF-8' | 'insufficient columns' | 'the csv file is empty' | 'the filename does not ends with .csv'
// type: 'encoding' | 'insufficient_columns' | 'empty' | 'name_suffix'
const detail = error.response.data.detail;
@@ -166,7 +178,7 @@ export const useFilesStore = defineStore('filesStore', {
uploadFailedFirst(detail[0].type, detail[0].msg, detail[0].loc[2]);
} else {
Swal.close(); // Close the loading progress bar
apiError(error, 'Failed to upload the files.');
apiError(error, "Failed to upload the files.");
}
}
},
@@ -180,8 +192,8 @@ export const useFilesStore = defineStore('filesStore', {
try {
const response = await apiClient.get(api);
this.allUploadDetail = response.data.preview;
} catch(error) {
apiError(error, 'Failed to get upload detail.');
} catch (error) {
apiError(error, "Failed to get upload detail.");
}
},
/**
@@ -200,15 +212,15 @@ export const useFilesStore = defineStore('filesStore', {
Swal.close(); // Close the loading progress bar
await this.rename(); // Rename the file
await uploadSuccess();
this.$router.push({name: 'Files'});
} catch(error) {
if(error.response?.status === 422) {
this.$router.push({ name: "Files" });
} catch (error) {
if (error.response?.status === 422) {
const detail = [...error.response.data.detail];
uploadFailedSecond(detail);
} else {
Swal.close(); // Close the loading progress bar
apiError(error, 'Failed to upload the log files.');
apiError(error, "Failed to upload the log files.");
}
}
},
@@ -220,19 +232,19 @@ export const useFilesStore = defineStore('filesStore', {
*/
async rename(type, id, fileName) {
// If uploadLogId exists, set id and type accordingly; then check the file type.
if(this.uploadId && this.uploadFileName) {
type = 'log';
if (this.uploadId && this.uploadFileName) {
type = "log";
id = this.uploadLogId;
fileName = this.uploadFileName;
}
const data = {"name": fileName};
const data = { name: fileName };
try {
await apiClient.put(`${getFileApiBase(type, id)}/name`, data);
this.uploadFileName = null;
await this.fetchAllFiles();
} catch(error) {
apiError(error, 'Failed to rename.');
} catch (error) {
apiError(error, "Failed to rename.");
}
},
/**
@@ -242,10 +254,12 @@ export const useFilesStore = defineStore('filesStore', {
*/
async getDependents(type, id) {
try {
const response = await apiClient.get(`${getFileApiBase(type, id)}/dependents`);
const response = await apiClient.get(
`${getFileApiBase(type, id)}/dependents`,
);
this.allDependentsData = response.data;
} catch(error) {
apiError(error, 'Failed to get Dependents of the files.');
} catch (error) {
apiError(error, "Failed to get Dependents of the files.");
}
},
/**
@@ -254,18 +268,18 @@ export const useFilesStore = defineStore('filesStore', {
* @param {number} id - The file ID.
*/
async deleteFile(type, id) {
if(id === null || id === undefined || isNaN(id)) {
console.error('Delete File API Error: invalid id');
if (id === null || id === undefined || isNaN(id)) {
console.error("Delete File API Error: invalid id");
return;
};
}
const loading = useLoadingStore();
loading.isLoading = true;
try {
await apiClient.delete(getFileApiBase(type, id));
await this.fetchAllFiles();
await deleteSuccess();
} catch(error) {
apiError(error, 'Failed to delete.');
} catch (error) {
apiError(error, "Failed to delete.");
} finally {
loading.isLoading = false;
}
@@ -275,15 +289,15 @@ export const useFilesStore = defineStore('filesStore', {
* @param {number} id - The file ID.
*/
async deletionRecord(id) {
let api = '';
let api = "";
const loading = useLoadingStore();
loading.isLoading = true;
api = `/api/deletion/${id}`;
try {
await apiClient.delete(api);
} catch(error) {
apiError(error, 'Failed to Remove a Deletion Record.')
} catch (error) {
apiError(error, "Failed to Remove a Deletion Record.");
} finally {
loading.isLoading = false;
}
@@ -295,21 +309,21 @@ export const useFilesStore = defineStore('filesStore', {
* @param {string} fileName - The file name.
*/
async downloadFileCSV(type, id, fileName) {
if (type !== 'log' && type !== 'filter') return;
if (type !== "log" && type !== "filter") return;
try {
const response = await apiClient.get(`${getFileApiBase(type, id)}/csv`);
const csvData = response.data;
const blob = new Blob([csvData], { type: 'text/csv' });
const blob = new Blob([csvData], { type: "text/csv" });
const url = window.URL.createObjectURL(blob);
const link = document.createElement('a');
const link = document.createElement("a");
link.href = url;
link.download = `${fileName}.csv`;
link.click();
window.URL.revokeObjectURL(url);
} catch(error) {
apiError(error, 'Failed to download.');
} catch (error) {
apiError(error, "Failed to download.");
}
},
},
})
});