Initial commit

This commit is contained in:
liumangmang
2026-05-12 17:51:53 +08:00
commit b564ca4797
55 changed files with 6407 additions and 0 deletions
+150
View File
@@ -0,0 +1,150 @@
import axios from 'axios'
import router from '@/router'
export const api = axios.create({
baseURL: '/',
timeout: 30000,
})
api.interceptors.response.use(
(r) => r,
(err) => {
if (err.response?.status === 401) {
localStorage.removeItem('smartup_token')
localStorage.removeItem('smartup_email')
router.push('/login')
}
return Promise.reject(err)
}
)
// ——— Auth ———
export const authApi = {
login: (email: string, password: string) =>
api.post<{ access_token: string }>('/api/auth/login', { email, password }),
me: () => api.get<{ email: string }>('/api/auth/me'),
}
// ——— Upstreams ———
export interface UpstreamData {
id: number
name: string
base_url: string
api_prefix: string
auth_type: string
auth_config_masked: Record<string, any>
rate_endpoint: string
groups_endpoint: string
enabled: boolean
check_interval_seconds: number
timeout_seconds: number
last_status: string
last_checked_at: string | null
last_error: string | null
created_at: string
updated_at: string
}
export interface UpstreamForm {
name: string
base_url: string
api_prefix: string
auth_type: string
auth_config: Record<string, any>
rate_endpoint: string
groups_endpoint: string
enabled: boolean
check_interval_seconds: number
timeout_seconds: number
}
export const upstreamsApi = {
list: () => api.get<UpstreamData[]>('/api/upstreams'),
create: (data: UpstreamForm) => api.post<UpstreamData>('/api/upstreams', data),
update: (id: number, data: Partial<UpstreamForm>) => api.put<UpstreamData>(`/api/upstreams/${id}`, data),
delete: (id: number) => api.delete(`/api/upstreams/${id}`),
test: (id: number) => api.post<{ success: boolean; message: string; detail?: string }>(`/api/upstreams/${id}/test`),
checkNow: (id: number) => api.post<{ success: boolean; message: string }>(`/api/upstreams/${id}/check-now`),
latestSnapshot: (id: number) => api.get(`/api/upstreams/${id}/snapshots/latest`),
listSnapshots: (id: number, limit = 20, offset = 0) =>
api.get<any[]>(`/api/upstreams/${id}/snapshots`, { params: { limit, offset } }),
}
// ——— Webhooks ———
export interface WebhookData {
id: number
name: string
type: string
url: string
secret_masked: string
enabled: boolean
events: string[]
created_at: string
updated_at: string
}
export interface WebhookForm {
name: string
type: string
url: string
secret: string
enabled: boolean
events: string[]
}
export const webhooksApi = {
list: () => api.get<WebhookData[]>('/api/webhooks'),
create: (data: WebhookForm) => api.post<WebhookData>('/api/webhooks', data),
update: (id: number, data: Partial<WebhookForm>) => api.put<WebhookData>(`/api/webhooks/${id}`, data),
delete: (id: number) => api.delete(`/api/webhooks/${id}`),
test: (id: number) => api.post<{ success: boolean; message: string }>(`/api/webhooks/${id}/test`),
}
// ——— Logs ———
export interface LogData {
id: number
webhook_config_id: number
webhook_name: string
event_type: string
payload: Record<string, any>
status: string
response_text: string | null
created_at: string
}
export const logsApi = {
list: (params?: { status?: string; event_type?: string; limit?: number; offset?: number }) =>
api.get<LogData[]>('/api/notification-logs', { params }),
}
// ——— Custom Pages ———
export interface CustomPageData {
id: number
name: string
url: string
icon: string
sort_order: number
enabled: boolean
use_proxy: boolean
description: string | null
created_at: string
updated_at: string
}
export interface CustomPageForm {
name: string
url: string
icon: string
sort_order: number
enabled: boolean
use_proxy: boolean
description?: string
}
export const customPagesApi = {
list: () => api.get<CustomPageData[]>('/api/custom-pages'),
listPublic: () => axios.get<CustomPageData[]>('/api/custom-pages/public'),
create: (data: CustomPageForm) => api.post<CustomPageData>('/api/custom-pages', data),
update: (id: number, data: Partial<CustomPageForm>) => api.put<CustomPageData>(`/api/custom-pages/${id}`, data),
delete: (id: number) => api.delete(`/api/custom-pages/${id}`),
}