2026-03-06 17:54:09 +07:00
|
|
|
import axios, { type AxiosProgressEvent } from "@/config/axios";
|
2025-12-22 14:53:19 +07:00
|
|
|
import { API_ENDPOINTS } from "@/config/api";
|
|
|
|
|
import type { Version } from "@/types/file";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Lấy danh sách phiên bản agent
|
|
|
|
|
*/
|
|
|
|
|
export async function getAgentVersion(): Promise<Version[]> {
|
|
|
|
|
const response = await axios.get<Version[]>(API_ENDPOINTS.APP_VERSION.GET_VERSION);
|
|
|
|
|
return response.data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Lấy danh sách phần mềm
|
|
|
|
|
*/
|
|
|
|
|
export async function getSoftwareList(): Promise<Version[]> {
|
|
|
|
|
const response = await axios.get<Version[]>(API_ENDPOINTS.APP_VERSION.GET_SOFTWARE);
|
|
|
|
|
return response.data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Upload file phần mềm/agent
|
|
|
|
|
* @param formData - FormData chứa file
|
|
|
|
|
* @param onUploadProgress - Callback theo dõi tiến độ upload
|
|
|
|
|
*/
|
|
|
|
|
export async function uploadSoftware(
|
|
|
|
|
formData: FormData,
|
|
|
|
|
onUploadProgress?: (progressEvent: AxiosProgressEvent) => void
|
|
|
|
|
): Promise<{ message: string }> {
|
|
|
|
|
const response = await axios.post(API_ENDPOINTS.APP_VERSION.UPLOAD, formData, {
|
|
|
|
|
headers: {
|
|
|
|
|
"Content-Type": "multipart/form-data",
|
|
|
|
|
},
|
|
|
|
|
onUploadProgress,
|
|
|
|
|
});
|
|
|
|
|
return response.data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Lấy danh sách blacklist
|
|
|
|
|
*/
|
|
|
|
|
export async function getBlacklist(): Promise<any[]> {
|
|
|
|
|
const response = await axios.get<any[]>(API_ENDPOINTS.APP_VERSION.GET_BLACKLIST);
|
|
|
|
|
return response.data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Thêm ứng dụng vào blacklist
|
|
|
|
|
* @param data - Dữ liệu thêm blacklist
|
|
|
|
|
*/
|
|
|
|
|
export async function addBlacklist(data: any): Promise<{ message: string }> {
|
|
|
|
|
const response = await axios.post(API_ENDPOINTS.APP_VERSION.ADD_BLACKLIST, data);
|
|
|
|
|
return response.data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Xóa ứng dụng khỏi blacklist
|
|
|
|
|
* @param appId - ID ứng dụng
|
|
|
|
|
*/
|
|
|
|
|
export async function deleteBlacklist(appId: number): Promise<{ message: string }> {
|
|
|
|
|
const response = await axios.delete(
|
|
|
|
|
API_ENDPOINTS.APP_VERSION.DELETE_BLACKLIST(appId)
|
|
|
|
|
);
|
|
|
|
|
return response.data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Cập nhật blacklist
|
|
|
|
|
* @param appId - ID ứng dụng
|
|
|
|
|
* @param data - Dữ liệu cập nhật
|
|
|
|
|
*/
|
|
|
|
|
export async function updateBlacklist(appId: string, data: any): Promise<{ message: string }> {
|
|
|
|
|
const response = await axios.put(
|
|
|
|
|
API_ENDPOINTS.APP_VERSION.UPDATE_BLACKLIST(appId),
|
|
|
|
|
data
|
|
|
|
|
);
|
|
|
|
|
return response.data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Yêu cầu cập nhật blacklist
|
|
|
|
|
* @param data - Dữ liệu yêu cầu
|
|
|
|
|
*/
|
|
|
|
|
export async function requestUpdateBlacklist(data: any): Promise<{ message: string }> {
|
|
|
|
|
const response = await axios.post(
|
|
|
|
|
API_ENDPOINTS.APP_VERSION.REQUEST_UPDATE_BLACKLIST,
|
|
|
|
|
data
|
|
|
|
|
);
|
|
|
|
|
return response.data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Lấy danh sách file bắt buộc
|
|
|
|
|
*/
|
|
|
|
|
export async function getRequiredFiles(): Promise<any[]> {
|
|
|
|
|
const response = await axios.get<any[]>(API_ENDPOINTS.APP_VERSION.GET_REQUIRED_FILES);
|
|
|
|
|
return response.data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Thêm file bắt buộc
|
|
|
|
|
* @param data - Dữ liệu file
|
|
|
|
|
*/
|
|
|
|
|
export async function addRequiredFile(data: any): Promise<{ message: string }> {
|
|
|
|
|
const response = await axios.post(API_ENDPOINTS.APP_VERSION.ADD_REQUIRED_FILE, data);
|
|
|
|
|
return response.data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Xóa file bắt buộc
|
|
|
|
|
* @param fileId - ID file
|
|
|
|
|
*/
|
|
|
|
|
export async function deleteRequiredFile(fileId: number): Promise<{ message: string }> {
|
|
|
|
|
const response = await axios.delete(
|
|
|
|
|
API_ENDPOINTS.APP_VERSION.DELETE_REQUIRED_FILE(fileId)
|
|
|
|
|
);
|
|
|
|
|
return response.data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Xóa file từ server
|
|
|
|
|
* @param fileId - ID file
|
|
|
|
|
*/
|
|
|
|
|
export async function deleteFile(fileId: number): Promise<{ message: string }> {
|
|
|
|
|
const response = await axios.delete(API_ENDPOINTS.APP_VERSION.DELETE_FILES(fileId));
|
|
|
|
|
return response.data;
|
|
|
|
|
}
|