feat: get server configs

This commit is contained in:
DIYgod 2024-10-21 00:03:32 +08:00
parent 847c317bb4
commit 1a874120ce
No known key found for this signature in database
6 changed files with 66 additions and 1 deletions

View File

@ -0,0 +1,8 @@
import { atom } from "jotai"
import { createAtomHooks } from "~/lib/jotai"
import type { ServerConfigs } from "~/models"
export const [, , useServerConfigs, , getServerConfigs, setServerConfigs] = createAtomHooks(
atom<Nullable<ServerConfigs>>(null),
)

View File

@ -123,3 +123,5 @@ export type ActionsInput = {
export const TransactionTypes = ["mint", "purchase", "tip", "withdraw"] as const
export type WalletModel = ExtractBizResponse<typeof apiClient.wallets.$get>["data"][number]
export type ServerConfigs = ExtractBizResponse<typeof apiClient.status.configs.$get>["data"]

View File

@ -23,6 +23,7 @@ import {
LazyModalStackProvider,
// specific import should add `index` postfix
} from "./lazy/index"
import { ServerConfigsProvider } from "./server-configs-provider"
import { SettingSync } from "./setting-sync"
import { StableRouterProvider } from "./stable-router-provider"
import { UserProvider } from "./user-provider"
@ -44,6 +45,7 @@ export const RootProviders: FC<PropsWithChildren> = ({ children }) => (
<EventProvider />
<UserProvider />
<ServerConfigsProvider />
<StableRouterProvider />
<SettingSync />

View File

@ -0,0 +1,15 @@
import { useEffect } from "react"
import { setServerConfigs } from "~/atoms/server-configs"
import { useServerConfigsQuery } from "~/queries/server-configs"
export const ServerConfigsProvider = () => {
const serverConfigs = useServerConfigsQuery()
useEffect(() => {
if (!serverConfigs) return
setServerConfigs(serverConfigs)
}, [serverConfigs])
return null
}

View File

@ -0,0 +1,12 @@
import { useAuthQuery } from "~/hooks/common"
import { apiClient } from "~/lib/api-fetch"
import { defineQuery } from "~/lib/defineQuery"
export const serverConfigs = {
get: () => defineQuery(["server-configs"], async () => await apiClient.status.configs.$get()),
}
export const useServerConfigsQuery = () => {
const { data } = useAuthQuery(serverConfigs.get())
return data?.data
}

View File

@ -4431,6 +4431,33 @@ declare const levelsRelations: drizzle_orm.Relations<"levels", {
}>;
declare const _routes: hono_hono_base.HonoBase<Env, {
"/status/configs": {
$get: {
input: {};
output: {
code: 0;
data: {
MAX_SUBSCRIPTIONS: number;
MAX_LISTS: number;
MAX_ACTIONS: number;
MAX_WEBHOOKS_PER_ACTION: number;
MAX_INBOXES: number;
IMPORTING_TITLE: string;
DAILY_POWER_PERCENTAGES: number[];
LEVEL_PERCENTAGES: number[];
DAILY_CLAIM_AMOUNT: {
trial: number;
normal: number;
};
DISABLE_PERSONAL_DAILY_POWER: boolean;
TAX_POINT: string;
};
};
outputFormat: "json" | "text";
status: 200;
};
};
} & {
"/messaging": {
$post: {
input: {
@ -5083,7 +5110,6 @@ declare const _routes: hono_hono_base.HonoBase<Env, {
activityPoints: number | null;
} | null;
todayDailyPower: string;
tomorrowDailyPower: string;
}[];
};
outputFormat: "json" | "text";