feat: connect admin session and public config endpoints

This commit is contained in:
Lan committed 2026-06-03 02:52:38 +08:00
1 parent 2a73e24d1c
commit 46e75f94b2
7 files changed
+83 -7

No files matched your search

+27 -1
View File
@@ -1,13 +1,39 @@
import api from './client'
import type { ApiResponse, ConfigState } from '@/types'
type PublicConfigEnvelope = {
config?: Partial<ConfigState>
meta?: unknown
}
const isPublicConfigEnvelope = (
detail: ConfigState | PublicConfigEnvelope | null | undefined
): detail is PublicConfigEnvelope => {
return !!detail && typeof detail === 'object' && 'config' in detail
}
export class ConfigService {
static async getConfig(): Promise<ApiResponse<ConfigState>> {
return api.get('/admin/config/get')
}
static async getUserConfig(): Promise<ApiResponse<ConfigState>> {
return api.post('/')
try {
const response = (await api.get('/api/v1/config')) as ApiResponse<
ConfigState | PublicConfigEnvelope
>
if (isPublicConfigEnvelope(response.detail) && response.detail.config) {
return {
...response,
detail: response.detail.config as ConfigState
}
}
return response as ApiResponse<ConfigState>
} catch {
return api.post('/')
}
}
static async updateConfig(config: Partial<ConfigState>): Promise<ApiResponse> {