feat: server group

This commit is contained in:
hamster1963
2024-11-24 01:45:33 +08:00
parent 0fb3f4a6cf
commit fb38b0eb8a
10 changed files with 167 additions and 109 deletions

View File

@@ -1,77 +1,7 @@
export const fetchUsers = async (token: string) => {
const response = await fetch("http://localhost:8008/api/v1/user", {
headers: {
Authorization: `Bearer ${token}`,
},
});
const data = await response.json();
if (data.error) {
throw new Error(data.error);
}
return data;
};
import { ServerGroupResponse } from "@/types/nezha-api";
export const createUser = async (
token: string,
username: string,
password: string,
) => {
const response = await fetch(`http://localhost:8008/api/v1/user`, {
method: "POST",
body: JSON.stringify({ username, password }),
headers: {
Authorization: `Bearer ${token}`,
},
});
const data = await response.json();
if (data.error) {
throw new Error(data.error);
}
return data;
};
export const deleteUser = async (token: string, ids: number[]) => {
const response = await fetch(
`http://localhost:8008/api/v1/batch-delete/user`,
{
method: "POST",
body: JSON.stringify(ids),
headers: {
Authorization: `Bearer ${token}`,
},
},
);
const data = await response.json();
if (data.error) {
throw new Error(data.error);
}
return data;
};
export const fetchServers = async (token: string) => {
const response = await fetch("http://localhost:8008/api/v1/server", {
headers: {
Authorization: `Bearer ${token}`,
},
});
const data = await response.json();
if (data.error) {
throw new Error(data.error);
}
return data;
};
export const deleteServer = async (token: string, ids: number[]) => {
const response = await fetch(
`http://localhost:8008/api/v1/batch-delete/server`,
{
method: "POST",
body: JSON.stringify(ids),
headers: {
Authorization: `Bearer ${token}`,
},
},
);
export const fetchServerGroup = async (): Promise<ServerGroupResponse> => {
const response = await fetch("/api/v1/server-group");
const data = await response.json();
if (data.error) {
throw new Error(data.error);