Skip to content

Commit 9572484

Browse files
committed
feat: session 返回接口方式做显示判断
1 parent c555289 commit 9572484

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

service/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import express from 'express'
22
import type { ChatContext, ChatMessage } from './chatgpt'
3-
import { chatConfig, chatReplyProcess } from './chatgpt'
3+
import { chatConfig, chatReplyProcess, currentModel } from './chatgpt'
44
import { auth } from './middleware/auth'
55
import { isNotEmptyString } from './utils/is'
66

@@ -50,7 +50,7 @@ router.post('/session', async (req, res) => {
5050
try {
5151
const AUTH_SECRET_KEY = process.env.AUTH_SECRET_KEY
5252
const hasAuth = isNotEmptyString(AUTH_SECRET_KEY)
53-
res.send({ status: 'Success', message: '', data: { auth: hasAuth } })
53+
res.send({ status: 'Success', message: '', data: { auth: hasAuth, model: currentModel() } })
5454
}
5555
catch (error) {
5656
res.send({ status: 'Fail', message: error.message, data: null })

src/components/common/Setting/About.vue

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<script setup lang='ts'>
2-
import { onMounted, ref } from 'vue'
2+
import { computed, onMounted, ref } from 'vue'
33
import { NSpin } from 'naive-ui'
44
import { fetchChatConfig } from '@/api'
55
import pkg from '@/../package.json'
6+
import { useAuthStore } from '@/store'
67
78
interface ConfigState {
89
timeoutMs?: number
@@ -13,10 +14,14 @@ interface ConfigState {
1314
balance?: string
1415
}
1516
17+
const authStore = useAuthStore()
18+
1619
const loading = ref(false)
1720
1821
const config = ref<ConfigState>()
1922
23+
const isChatGPTAPI = computed<boolean>(() => !!authStore.isChatGPTAPI)
24+
2025
async function fetchConfig() {
2126
try {
2227
loading.value = true
@@ -56,8 +61,12 @@ onMounted(() => {
5661
</p>
5762
</div>
5863
<p>{{ $t("setting.api") }}:{{ config?.apiModel ?? '-' }}</p>
59-
<p>{{ $t("setting.balance") }}:{{ config?.balance ?? '-' }}</p>
60-
<p>{{ $t("setting.reverseProxy") }}:{{ config?.reverseProxy ?? '-' }}</p>
64+
<p v-if="isChatGPTAPI">
65+
{{ $t("setting.balance") }}:{{ config?.balance ?? '-' }}
66+
</p>
67+
<p v-if="!isChatGPTAPI">
68+
{{ $t("setting.reverseProxy") }}:{{ config?.reverseProxy ?? '-' }}
69+
</p>
6170
<p>{{ $t("setting.timeout") }}:{{ config?.timeoutMs ?? '-' }}</p>
6271
<p>{{ $t("setting.socks") }}:{{ config?.socksProxy ?? '-' }}</p>
6372
<p>{{ $t("setting.httpsProxy") }}:{{ config?.httpsProxy ?? '-' }}</p>

src/store/modules/auth/index.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@ import { getToken, removeToken, setToken } from './helper'
33
import { store } from '@/store'
44
import { fetchSession } from '@/api'
55

6+
interface SessionResponse {
7+
auth: boolean
8+
model: 'ChatGPTAPI' | 'ChatGPTUnofficialProxyAPI'
9+
}
10+
611
export interface AuthState {
712
token: string | undefined
8-
session: { auth: boolean } | null
13+
session: SessionResponse | null
914
}
1015

1116
export const useAuthStore = defineStore('auth-store', {
@@ -14,10 +19,16 @@ export const useAuthStore = defineStore('auth-store', {
1419
session: null,
1520
}),
1621

22+
getters: {
23+
isChatGPTAPI(state): boolean {
24+
return state.session?.model === 'ChatGPTAPI'
25+
},
26+
},
27+
1728
actions: {
1829
async getSession() {
1930
try {
20-
const { data } = await fetchSession<{ auth: boolean }>()
31+
const { data } = await fetchSession<SessionResponse>()
2132
this.session = { ...data }
2233
return Promise.resolve(data)
2334
}

0 commit comments

Comments
 (0)