From 9bab4b736f460a26482d28a1ec06391a250d4cc8 Mon Sep 17 00:00:00 2001 From: sijinhui Date: Mon, 1 Jul 2024 17:53:59 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A6=81=E6=AD=A2=E7=AE=A1=E7=90=86=E5=91=98?= =?UTF-8?q?=E5=A4=96=E7=94=A8=E6=88=B7=E4=BD=BF=E7=94=A8=E6=9F=90=E4=BA=9B?= =?UTF-8?q?=E6=A8=A1=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/store/config.ts | 4 ++-- app/utils/hooks.ts | 7 ++++++- lib/auth.ts | 2 ++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/store/config.ts b/app/store/config.ts index a4fa191a2..e81ecd3b8 100644 --- a/app/store/config.ts +++ b/app/store/config.ts @@ -138,7 +138,7 @@ export const useAppConfig = createPersistStore( }), { name: StoreKey.Config, - version: 3.95, + version: 3.96, migrate(persistedState, version) { const state = persistedState as ChatConfig; @@ -174,7 +174,7 @@ export const useAppConfig = createPersistStore( // return { ...DEFAULT_CONFIG }; // } - if (version < 3.95) { + if (version < 3.96) { state.modelConfig = DEFAULT_CONFIG.modelConfig; // state.modelConfig.template = // state.modelConfig.template !== DEFAULT_INPUT_TEMPLATE diff --git a/app/utils/hooks.ts b/app/utils/hooks.ts index cabc55918..1876e7930 100644 --- a/app/utils/hooks.ts +++ b/app/utils/hooks.ts @@ -7,7 +7,7 @@ export function useAllModels() { const accessStore = useAccessStore(); const configStore = useAppConfig(); const { data: session, status } = useSession(); - console.log("-sssssssssss", session, status); + const models = useMemo(() => { return collectModelsWithDefaultModel( configStore.models, @@ -22,5 +22,10 @@ export function useAllModels() { configStore.dontUseModel, ]); + // @ts-expect-error + if (status === "authenticated" && !session?.user?.isAdmin) { + // 过滤非管理员用户可使用的模型 + return models.filter((m) => !m.name.endsWith("-all")); + } return models; } diff --git a/lib/auth.ts b/lib/auth.ts index 10a0cb1fc..abdd038e5 100644 --- a/lib/auth.ts +++ b/lib/auth.ts @@ -171,6 +171,8 @@ export const authOptions: NextAuthOptions = { username: token?.user?.username || token?.user?.gh_username, // @ts-expect-error hasPassword: !!token?.user?.password, + // @ts-expect-error + isAdmin: token?.user?.isAdmin, }; // console.log('555555555,', session, token) return session;