Extract duplicate API path logic into helper functions in conformance and files stores
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -16,6 +16,36 @@ import abbreviateNumber from '@/module/abbreviateNumber.js';
|
|||||||
import apiClient from "@/api/client.js";
|
import apiClient from "@/api/client.js";
|
||||||
import apiError from '@/module/apiError.js';
|
import apiError from '@/module/apiError.js';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the API base path for the current conformance check,
|
||||||
|
* prioritizing temp IDs over created IDs, and filter over log.
|
||||||
|
* @param {object} state - The store state.
|
||||||
|
* @returns {string} The API base path.
|
||||||
|
*/
|
||||||
|
function getCheckApiBase(state) {
|
||||||
|
const { conformanceFilterTempCheckId, conformanceLogTempCheckId,
|
||||||
|
conformanceFilterCreateCheckId, conformanceLogCreateCheckId } = state;
|
||||||
|
if (conformanceFilterTempCheckId !== null) return `/api/temp-filter-checks/${conformanceFilterTempCheckId}`;
|
||||||
|
if (conformanceLogTempCheckId !== null) return `/api/temp-log-checks/${conformanceLogTempCheckId}`;
|
||||||
|
if (conformanceFilterCreateCheckId !== null) return `/api/filter-checks/${conformanceFilterCreateCheckId}`;
|
||||||
|
if (conformanceLogCreateCheckId !== null) return `/api/log-checks/${conformanceLogCreateCheckId}`;
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the API path for conformance params/temp-checks,
|
||||||
|
* prioritizing filter over log.
|
||||||
|
* @param {object} state - The store state.
|
||||||
|
* @returns {{prefix: string, idParam: string}} The API prefix and ID query param.
|
||||||
|
*/
|
||||||
|
function getFileTypeApi(state) {
|
||||||
|
const { conformanceFilterId, conformanceLogId } = state;
|
||||||
|
if (conformanceFilterId !== null) {
|
||||||
|
return { prefix: 'filter', idParam: `filter_id=${conformanceFilterId}` };
|
||||||
|
}
|
||||||
|
return { prefix: 'log', idParam: `log_id=${conformanceLogId}` };
|
||||||
|
}
|
||||||
|
|
||||||
/** Pinia store for conformance checking and rule management. */
|
/** Pinia store for conformance checking and rule management. */
|
||||||
export const useConformanceStore = defineStore('conformanceStore', {
|
export const useConformanceStore = defineStore('conformanceStore', {
|
||||||
state: () => ({
|
state: () => ({
|
||||||
@@ -202,17 +232,8 @@ export const useConformanceStore = defineStore('conformanceStore', {
|
|||||||
* fetch Log Conformance Parameters api for Rule Settings.
|
* fetch Log Conformance Parameters api for Rule Settings.
|
||||||
*/
|
*/
|
||||||
async getConformanceParams() {
|
async getConformanceParams() {
|
||||||
const logId = this.conformanceLogId;
|
const { prefix, idParam } = getFileTypeApi(this);
|
||||||
const filterId = this.conformanceFilterId;
|
const api = `/api/${prefix}-checks/params?${idParam}`;
|
||||||
let api = '';
|
|
||||||
|
|
||||||
// 先判斷 filter 檔,再判斷 log 檔。
|
|
||||||
if(filterId !== null) {
|
|
||||||
api = `/api/filter-checks/params?filter_id=${filterId}`;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
api = `/api/log-checks/params?log_id=${logId}`;
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
const response = await apiClient.get(api);
|
const response = await apiClient.get(api);
|
||||||
this.allConformanceTask = response.data.tasks;
|
this.allConformanceTask = response.data.tasks;
|
||||||
@@ -230,24 +251,14 @@ export const useConformanceStore = defineStore('conformanceStore', {
|
|||||||
* @param {object} data - The request payload for the backend.
|
* @param {object} data - The request payload for the backend.
|
||||||
*/
|
*/
|
||||||
async addConformanceCheckId(data) {
|
async addConformanceCheckId(data) {
|
||||||
const logId = this.conformanceLogId;
|
const { prefix, idParam } = getFileTypeApi(this);
|
||||||
const filterId = this.conformanceFilterId;
|
const api = `/api/temp-${prefix}-checks?${idParam}`;
|
||||||
let api = '';
|
|
||||||
|
|
||||||
// 先判斷 filter 檔,再判斷 log 檔。
|
|
||||||
if(filterId !== null) {
|
|
||||||
api = `/api/temp-filter-checks?filter_id=${filterId}`;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
api = `/api/temp-log-checks?log_id=${logId}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await apiClient.post(api, data);
|
const response = await apiClient.post(api, data);
|
||||||
if(filterId !== null) {
|
if (prefix === 'filter') {
|
||||||
this.conformanceFilterTempCheckId = response.data.id;
|
this.conformanceFilterTempCheckId = response.data.id;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
this.conformanceLogTempCheckId = response.data.id;
|
this.conformanceLogTempCheckId = response.data.id;
|
||||||
}
|
}
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
@@ -259,25 +270,7 @@ export const useConformanceStore = defineStore('conformanceStore', {
|
|||||||
* @param {boolean} getRouteFile - Whether called to get the route file (used outside the Conformance page).
|
* @param {boolean} getRouteFile - Whether called to get the route file (used outside the Conformance page).
|
||||||
*/
|
*/
|
||||||
async getConformanceReport(getRouteFile = false) {
|
async getConformanceReport(getRouteFile = false) {
|
||||||
const logTempCheckId = this.conformanceLogTempCheckId;
|
const api = getCheckApiBase(this);
|
||||||
const filterTempCheckId = this.conformanceFilterTempCheckId;
|
|
||||||
const logCreateCheckId = this.conformanceLogCreateCheckId;
|
|
||||||
const filterCreateCheckId = this.conformanceFilterCreateCheckId;
|
|
||||||
let api = '';
|
|
||||||
|
|
||||||
// 先判斷 Temp 再判斷原 ID;先判斷 filter 檔,再判斷 log 檔。
|
|
||||||
if(filterTempCheckId !== null) {
|
|
||||||
api = `/api/temp-filter-checks/${filterTempCheckId}`;
|
|
||||||
}
|
|
||||||
else if(logTempCheckId !== null) {
|
|
||||||
api = `/api/temp-log-checks/${logTempCheckId}`;
|
|
||||||
}
|
|
||||||
else if(filterCreateCheckId !== null) {
|
|
||||||
api = `/api/filter-checks/${filterCreateCheckId}`;
|
|
||||||
}
|
|
||||||
else if(logCreateCheckId !== null) {
|
|
||||||
api = `/api/log-checks/${logCreateCheckId}`;
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
const response = await apiClient.get(api);
|
const response = await apiClient.get(api);
|
||||||
if(!getRouteFile) {
|
if(!getRouteFile) {
|
||||||
@@ -294,26 +287,7 @@ export const useConformanceStore = defineStore('conformanceStore', {
|
|||||||
* @param {number} issueNo - The issue number.
|
* @param {number} issueNo - The issue number.
|
||||||
*/
|
*/
|
||||||
async getConformanceIssue(issueNo) {
|
async getConformanceIssue(issueNo) {
|
||||||
const logTempCheckId = this.conformanceLogTempCheckId;
|
const api = `${getCheckApiBase(this)}/issues/${issueNo}`;
|
||||||
const filterTempCheckId = this.conformanceFilterTempCheckId;
|
|
||||||
const logCreateCheckId = this.conformanceLogCreateCheckId;
|
|
||||||
const filterCreateCheckId = this.conformanceFilterCreateCheckId;
|
|
||||||
let api = '';
|
|
||||||
|
|
||||||
// 先判斷 filter 檔,再判斷 log 檔。
|
|
||||||
if(filterTempCheckId !== null) {
|
|
||||||
api = `/api/temp-filter-checks/${filterTempCheckId}/issues/${issueNo}`;
|
|
||||||
}
|
|
||||||
else if(logTempCheckId !== null) {
|
|
||||||
api = `/api/temp-log-checks/${logTempCheckId}/issues/${issueNo}`;
|
|
||||||
}
|
|
||||||
else if(filterCreateCheckId !== null) {
|
|
||||||
api = `/api/filter-checks/${filterCreateCheckId}/issues/${issueNo}`;
|
|
||||||
}
|
|
||||||
else if(logCreateCheckId !== null) {
|
|
||||||
api = `/api/log-checks/${logCreateCheckId}/issues/${issueNo}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await apiClient.get(api);
|
const response = await apiClient.get(api);
|
||||||
this.allIssueTraces = response.data.traces;
|
this.allIssueTraces = response.data.traces;
|
||||||
@@ -328,26 +302,7 @@ export const useConformanceStore = defineStore('conformanceStore', {
|
|||||||
* @param {number} start - The starting index for loading traces.
|
* @param {number} start - The starting index for loading traces.
|
||||||
*/
|
*/
|
||||||
async getConformanceTraceDetail(issueNo, traceId, start) {
|
async getConformanceTraceDetail(issueNo, traceId, start) {
|
||||||
const logTempCheckId = this.conformanceLogTempCheckId;
|
const api = `${getCheckApiBase(this)}/issues/${issueNo}/traces/${traceId}?start=${start}&page_size=20`;
|
||||||
const filterTempCheckId = this.conformanceFilterTempCheckId;
|
|
||||||
const logCreateCheckId = this.conformanceLogCreateCheckId;
|
|
||||||
const filterCreateCheckId = this.conformanceFilterCreateCheckId;
|
|
||||||
let api = '';
|
|
||||||
|
|
||||||
// 先判斷 filter 檔,再判斷 log 檔。
|
|
||||||
if(filterTempCheckId !== null) {
|
|
||||||
api = `/api/temp-filter-checks/${filterTempCheckId}/issues/${issueNo}/traces/${traceId}?start=${start}&page_size=20`;
|
|
||||||
}
|
|
||||||
else if(logTempCheckId !== null) {
|
|
||||||
api = `/api/temp-log-checks/${logTempCheckId}/issues/${issueNo}/traces/${traceId}?start=${start}&page_size=20`;
|
|
||||||
}
|
|
||||||
else if(filterCreateCheckId !== null) {
|
|
||||||
api = `/api/filter-checks/${filterCreateCheckId}/issues/${issueNo}/traces/${traceId}?start=${start}&page_size=20`;
|
|
||||||
}
|
|
||||||
else if(logCreateCheckId !== null) {
|
|
||||||
api = `/api/log-checks/${logCreateCheckId}/issues/${issueNo}/traces/${traceId}?start=${start}&page_size=20`;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await apiClient.get(api);
|
const response = await apiClient.get(api);
|
||||||
this.allTaskSeq = response.data.task_seq;
|
this.allTaskSeq = response.data.task_seq;
|
||||||
@@ -366,18 +321,7 @@ export const useConformanceStore = defineStore('conformanceStore', {
|
|||||||
* @param {number} loopNo - The loop number.
|
* @param {number} loopNo - The loop number.
|
||||||
*/
|
*/
|
||||||
async getConformanceLoop(loopNo) {
|
async getConformanceLoop(loopNo) {
|
||||||
const logTempCheckId = this.conformanceLogTempCheckId;
|
const api = `${getCheckApiBase(this)}/loops/${loopNo}`;
|
||||||
const filterTempCheckId = this.conformanceFilterTempCheckId;
|
|
||||||
const logCreateCheckId = this.conformanceLogCreateCheckId;
|
|
||||||
const filterCreateCheckId = this.conformanceFilterCreateCheckId;
|
|
||||||
let api = '';
|
|
||||||
|
|
||||||
// 先判斷 filter 檔,再判斷 log 檔。
|
|
||||||
if(filterTempCheckId !== null) api = `/api/temp-filter-checks/${filterTempCheckId}/loops/${loopNo}`;
|
|
||||||
else if(logTempCheckId !== null) api = `/api/temp-log-checks/${logTempCheckId}/loops/${loopNo}`;
|
|
||||||
else if(filterCreateCheckId !== null) api = `/api/filter-checks/${filterCreateCheckId}/loops/${loopNo}`;
|
|
||||||
else if(logCreateCheckId !== null) api = `/api/log-checks/${logCreateCheckId}/loops/${loopNo}`;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await apiClient.get(api);
|
const response = await apiClient.get(api);
|
||||||
this.allLoopTraces = response.data.traces;
|
this.allLoopTraces = response.data.traces;
|
||||||
@@ -392,18 +336,7 @@ export const useConformanceStore = defineStore('conformanceStore', {
|
|||||||
* @param {number} start - The starting index for loading traces.
|
* @param {number} start - The starting index for loading traces.
|
||||||
*/
|
*/
|
||||||
async getConformanceLoopsTraceDetail(loopNo, traceId, start) {
|
async getConformanceLoopsTraceDetail(loopNo, traceId, start) {
|
||||||
const logTempCheckId = this.conformanceLogTempCheckId;
|
const api = `${getCheckApiBase(this)}/loops/${loopNo}/traces/${traceId}?start=${start}&page_size=20`;
|
||||||
const filterTempCheckId = this.conformanceFilterTempCheckId;
|
|
||||||
const logCreateCheckId = this.conformanceLogCreateCheckId;
|
|
||||||
const filterCreateCheckId = this.conformanceFilterCreateCheckId;
|
|
||||||
let api = '';
|
|
||||||
|
|
||||||
// 先判斷 filter 檔,再判斷 log 檔。
|
|
||||||
if(filterTempCheckId !== null) api = `/api/temp-filter-checks/${filterTempCheckId}/loops/${loopNo}/traces/${traceId}?start=${start}&page_size=20`;
|
|
||||||
else if(logTempCheckId !== null) api = `/api/temp-log-checks/${logTempCheckId}/loops/${loopNo}/traces/${traceId}?start=${start}&page_size=20`;
|
|
||||||
else if(filterCreateCheckId !== null) api = `/api/filter-checks/${filterCreateCheckId}/loops/${loopNo}/traces/${traceId}?start=${start}&page_size=20`;
|
|
||||||
else if(logCreateCheckId !== null) api = `/api/log-checks/${logCreateCheckId}/loops/${loopNo}/traces/${traceId}?start=${start}&page_size=20`;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await apiClient.get(api);
|
const response = await apiClient.get(api);
|
||||||
this.allLoopTaskSeq = response.data.task_seq;
|
this.allLoopTaskSeq = response.data.task_seq;
|
||||||
@@ -422,27 +355,21 @@ export const useConformanceStore = defineStore('conformanceStore', {
|
|||||||
* @param {string} value file's name
|
* @param {string} value file's name
|
||||||
*/
|
*/
|
||||||
async addConformanceCreateCheckId(value) {
|
async addConformanceCreateCheckId(value) {
|
||||||
const logId = this.conformanceLogId;
|
const { prefix, idParam } = getFileTypeApi(this);
|
||||||
const filterId = this.conformanceFilterId;
|
const api = `/api/${prefix}-checks?${idParam}`;
|
||||||
let api = '';
|
|
||||||
const data = {
|
const data = {
|
||||||
name: value,
|
name: value,
|
||||||
rule: this.conformanceRuleData
|
rule: this.conformanceRuleData
|
||||||
};
|
};
|
||||||
|
|
||||||
// 先判斷 filter 檔,再判斷 log 檔。
|
|
||||||
if(filterId !== null) api = `/api/filter-checks?filter_id=${filterId}`;
|
|
||||||
else api = `/api/log-checks?log_id=${logId}`;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await apiClient.post(api, data);
|
const response = await apiClient.post(api, data);
|
||||||
if(filterId !== null) {
|
if (prefix === 'filter') {
|
||||||
this.conformanceFilterCreateCheckId = response.data.id;
|
this.conformanceFilterCreateCheckId = response.data.id;
|
||||||
this.conformanceFilterTempCheckId = null;
|
this.conformanceFilterTempCheckId = null;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
this.conformanceLogCreateCheckId = response.data.id;
|
this.conformanceLogCreateCheckId = response.data.id;
|
||||||
this.conformanceLogTempCheckId= null;
|
this.conformanceLogTempCheckId = null;
|
||||||
}
|
}
|
||||||
}catch(error) {
|
}catch(error) {
|
||||||
apiError(error, 'Failed to add the Conformance Check for a file.');
|
apiError(error, 'Failed to add the Conformance Check for a file.');
|
||||||
@@ -452,15 +379,9 @@ export const useConformanceStore = defineStore('conformanceStore', {
|
|||||||
* Update an Existing Conformance Check, log and filter
|
* Update an Existing Conformance Check, log and filter
|
||||||
*/
|
*/
|
||||||
async updateConformance() {
|
async updateConformance() {
|
||||||
const logCreateCheckId = this.conformanceLogCreateCheckId;
|
const api = getCheckApiBase(this);
|
||||||
const filterCreateCheckId = this.conformanceFilterCreateCheckId;
|
|
||||||
let api = '';
|
|
||||||
const data = this.conformanceRuleData;
|
const data = this.conformanceRuleData;
|
||||||
|
|
||||||
// 先判斷有無 Temp ID,再判斷原始檔 ID
|
|
||||||
if(filterCreateCheckId !== null) api = `/api/filter-checks/${filterCreateCheckId}`;
|
|
||||||
else if(logCreateCheckId !== null) api = `/api/log-checks/${logCreateCheckId}`;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await apiClient.put(api, data);
|
const response = await apiClient.put(api, data);
|
||||||
this.isUpdateConformance = response.status === 200;
|
this.isUpdateConformance = response.status === 200;
|
||||||
|
|||||||
@@ -17,6 +17,24 @@ import Swal from 'sweetalert2';
|
|||||||
import { uploadFailedFirst, uploadFailedSecond, uploadloader, uploadSuccess, deleteSuccess } from '@/module/alertModal.js';
|
import { uploadFailedFirst, uploadFailedSecond, uploadloader, uploadSuccess, deleteSuccess } from '@/module/alertModal.js';
|
||||||
import { useLoadingStore } from '@/stores/loading';
|
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',
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the API base path for a file type and ID.
|
||||||
|
* @param {string} type - The file type.
|
||||||
|
* @param {number} id - The file ID.
|
||||||
|
* @returns {string} The API base path.
|
||||||
|
*/
|
||||||
|
function getFileApiBase(type, id) {
|
||||||
|
return `/api/${FILE_TYPE_PATHS[type]}/${id}`;
|
||||||
|
}
|
||||||
|
|
||||||
/** Pinia store for file CRUD operations and upload workflow. */
|
/** Pinia store for file CRUD operations and upload workflow. */
|
||||||
export const useFilesStore = defineStore('filesStore', {
|
export const useFilesStore = defineStore('filesStore', {
|
||||||
state: () => ({
|
state: () => ({
|
||||||
@@ -205,25 +223,9 @@ export const useFilesStore = defineStore('filesStore', {
|
|||||||
fileName = this.uploadFileName;
|
fileName = this.uploadFileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
let api;
|
|
||||||
const data = {"name": fileName};
|
const data = {"name": fileName};
|
||||||
|
|
||||||
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 {
|
try {
|
||||||
await apiClient.put(api, data);
|
await apiClient.put(`${getFileApiBase(type, id)}/name`, data);
|
||||||
this.uploadFileName = null;
|
this.uploadFileName = null;
|
||||||
await this.fetchAllFiles();
|
await this.fetchAllFiles();
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
@@ -236,24 +238,8 @@ export const useFilesStore = defineStore('filesStore', {
|
|||||||
* @param {number} id - The file ID.
|
* @param {number} id - The file ID.
|
||||||
*/
|
*/
|
||||||
async getDependents(type, id) {
|
async getDependents(type, id) {
|
||||||
let api;
|
|
||||||
|
|
||||||
switch (type) {
|
|
||||||
case 'log':
|
|
||||||
api = `/api/logs/${id}/dependents`;
|
|
||||||
break;
|
|
||||||
case 'filter':
|
|
||||||
api = `/api/filters/${id}/dependents`;
|
|
||||||
break;
|
|
||||||
case 'log-check':
|
|
||||||
api = `/api/log-checks/${id}/dependents`;
|
|
||||||
break;
|
|
||||||
case 'filter-check':
|
|
||||||
api = `/api/filter-checks/${id}/dependents`;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
const response = await apiClient.get(api);
|
const response = await apiClient.get(`${getFileApiBase(type, id)}/dependents`);
|
||||||
this.allDependentsData = response.data;
|
this.allDependentsData = response.data;
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
apiError(error, 'Failed to get Dependents of the files.');
|
apiError(error, 'Failed to get Dependents of the files.');
|
||||||
@@ -265,30 +251,14 @@ export const useFilesStore = defineStore('filesStore', {
|
|||||||
* @param {number} id - The file ID.
|
* @param {number} id - The file ID.
|
||||||
*/
|
*/
|
||||||
async deleteFile(type, id) {
|
async deleteFile(type, id) {
|
||||||
let api;
|
|
||||||
|
|
||||||
if(id === null || id === undefined || isNaN(id)) {
|
if(id === null || id === undefined || isNaN(id)) {
|
||||||
console.error('Delete File API Error: invalid id');
|
console.error('Delete File API Error: invalid id');
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
const loading = useLoadingStore();
|
const loading = useLoadingStore();
|
||||||
loading.isLoading = true;
|
loading.isLoading = true;
|
||||||
switch (type) {
|
|
||||||
case 'log':
|
|
||||||
api = `/api/logs/${id}`;
|
|
||||||
break;
|
|
||||||
case 'filter':
|
|
||||||
api = `/api/filters/${id}`;
|
|
||||||
break;
|
|
||||||
case 'log-check':
|
|
||||||
api = `/api/log-checks/${id}`;
|
|
||||||
break;
|
|
||||||
case 'filter-check':
|
|
||||||
api = `/api/filter-checks/${id}`;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
await apiClient.delete(api);
|
await apiClient.delete(getFileApiBase(type, id));
|
||||||
await this.fetchAllFiles();
|
await this.fetchAllFiles();
|
||||||
await deleteSuccess();
|
await deleteSuccess();
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
@@ -322,26 +292,9 @@ export const useFilesStore = defineStore('filesStore', {
|
|||||||
* @param {string} fileName - The file name.
|
* @param {string} fileName - The file name.
|
||||||
*/
|
*/
|
||||||
async downloadFileCSV(type, id, fileName) {
|
async downloadFileCSV(type, id, fileName) {
|
||||||
let api;
|
if (type !== 'log' && type !== 'filter') return;
|
||||||
|
|
||||||
switch (type) {
|
|
||||||
case 'log':
|
|
||||||
api = `/api/logs/${id}/csv`;
|
|
||||||
break;
|
|
||||||
case 'filter':
|
|
||||||
api = `/api/filters/${id}/csv`;
|
|
||||||
break;
|
|
||||||
// case 'log-check':
|
|
||||||
// api = `/api/log-checks/${id}/csv`;
|
|
||||||
// break;
|
|
||||||
// case 'filter-check':
|
|
||||||
// api = `/api/filter-checks/${id}/csv`;
|
|
||||||
// break;
|
|
||||||
default:
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
const response = await apiClient.get(api);
|
const response = await apiClient.get(`${getFileApiBase(type, id)}/csv`);
|
||||||
const csvData = response.data;
|
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 url = window.URL.createObjectURL(blob);
|
||||||
|
|||||||
Reference in New Issue
Block a user