mirror of
https://github.com/dreamhunter2333/cloudflare_temp_email.git
synced 2026-07-12 16:02:10 +08:00
feat: add admin panel (#31)
* feat: add admin panel * feature: update limit
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { useGlobalState } from '../store'
|
||||
|
||||
const API_BASE = import.meta.env.VITE_API_BASE || "";
|
||||
const { loading, auth, jwt, openSettings, showAuth } = useGlobalState();
|
||||
const { loading, auth, jwt, openSettings, showAuth, adminAuth, showAdminAuth } = useGlobalState();
|
||||
|
||||
const apiFetch = async (path, options = {}) => {
|
||||
loading.value = true;
|
||||
@@ -10,6 +10,7 @@ const apiFetch = async (path, options = {}) => {
|
||||
method: options.method || 'GET',
|
||||
headers: {
|
||||
'x-custom-auth': auth.value,
|
||||
'x-admin-auth': adminAuth.value,
|
||||
'Authorization': `Bearer ${jwt.value}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
@@ -18,6 +19,10 @@ const apiFetch = async (path, options = {}) => {
|
||||
showAuth.value = true;
|
||||
throw new Error("Unauthorized");
|
||||
}
|
||||
if (response.status === 401 && path.startsWith("/admin")) {
|
||||
showAdminAuth.value = true;
|
||||
throw new Error("Unauthorized");
|
||||
}
|
||||
if (!response.ok) {
|
||||
throw new Error(`${response.status} ${await response.text()}` || "error");
|
||||
}
|
||||
@@ -58,9 +63,39 @@ const getSettings = async () => {
|
||||
return res["address"];
|
||||
}
|
||||
|
||||
const adminShowPassword = async (id) => {
|
||||
try {
|
||||
const { password } = await apiFetch(`/admin/show_password/${id}`);
|
||||
return password;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
const adminDeleteAddress = async (id) => {
|
||||
try {
|
||||
await apiFetch(`/admin/delete_address/${id}`, {
|
||||
method: 'DELETE'
|
||||
});
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
const adminGetAddress = async () => {
|
||||
try {
|
||||
return await apiFetch("/admin/addresss");
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export const api = {
|
||||
fetch: apiFetch,
|
||||
getSettings: getSettings,
|
||||
getOpenSettings: getOpenSettings,
|
||||
adminShowPassword: adminShowPassword,
|
||||
adminDeleteAddress: adminDeleteAddress,
|
||||
adminGetAddress: adminGetAddress,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user