feat: show admin dashboard version
This commit is contained in:
1 parent
2428409953
commit
04a0498923
7 files changed
+89
-21
No files matched your search
+29
-19
@@ -1,38 +1,48 @@
|
||||
import api from './client'
|
||||
import type { ApiResponse, ConfigState } from '@/types'
|
||||
|
||||
type PublicConfigEnvelope = {
|
||||
config?: Partial<ConfigState>
|
||||
meta?: unknown
|
||||
}
|
||||
import type { ApiResponse, ConfigState, PublicConfigPayload } from '@/types'
|
||||
|
||||
const isPublicConfigEnvelope = (
|
||||
detail: ConfigState | PublicConfigEnvelope | null | undefined
|
||||
): detail is PublicConfigEnvelope => {
|
||||
detail: ConfigState | PublicConfigPayload | null | undefined
|
||||
): detail is PublicConfigPayload => {
|
||||
return !!detail && typeof detail === 'object' && 'config' in detail
|
||||
}
|
||||
|
||||
const normalizeUserConfigResponse = (
|
||||
response: ApiResponse<ConfigState | PublicConfigPayload>
|
||||
): ApiResponse<PublicConfigPayload> => {
|
||||
if (isPublicConfigEnvelope(response.detail)) {
|
||||
return {
|
||||
...response,
|
||||
detail: {
|
||||
config: response.detail.config,
|
||||
meta: response.detail.meta
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
...response,
|
||||
detail: {
|
||||
config: response.detail ?? {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class ConfigService {
|
||||
static async getConfig(): Promise<ApiResponse<ConfigState>> {
|
||||
return api.get('/admin/config/get')
|
||||
}
|
||||
|
||||
static async getUserConfig(): Promise<ApiResponse<ConfigState>> {
|
||||
static async getUserConfig(): Promise<ApiResponse<PublicConfigPayload>> {
|
||||
try {
|
||||
const response = (await api.get('/api/v1/config')) as ApiResponse<
|
||||
ConfigState | PublicConfigEnvelope
|
||||
ConfigState | PublicConfigPayload
|
||||
>
|
||||
|
||||
if (isPublicConfigEnvelope(response.detail) && response.detail.config) {
|
||||
return {
|
||||
...response,
|
||||
detail: response.detail.config as ConfigState
|
||||
}
|
||||
}
|
||||
|
||||
return response as ApiResponse<ConfigState>
|
||||
return normalizeUserConfigResponse(response)
|
||||
} catch {
|
||||
return api.post('/')
|
||||
const response = (await api.post('/')) as ApiResponse<ConfigState>
|
||||
return normalizeUserConfigResponse(response)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user