mirror of
https://github.com/Buriburizaem0n/nezha-dash-v1.git
synced 2026-02-06 21:50:07 +00:00
update: init
This commit is contained in:
80
src/lib/nezha-api.ts
Normal file
80
src/lib/nezha-api.ts
Normal file
@@ -0,0 +1,80 @@
|
||||
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;
|
||||
};
|
||||
|
||||
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}`,
|
||||
},
|
||||
},
|
||||
);
|
||||
const data = await response.json();
|
||||
if (data.error) {
|
||||
throw new Error(data.error);
|
||||
}
|
||||
return data;
|
||||
};
|
||||
Reference in New Issue
Block a user