feat: session 返回接口方式做显示判断
This commit is contained in:
parent
c5552893d7
commit
95724845cf
|
@ -1,6 +1,6 @@
|
||||||
import express from 'express'
|
import express from 'express'
|
||||||
import type { ChatContext, ChatMessage } from './chatgpt'
|
import type { ChatContext, ChatMessage } from './chatgpt'
|
||||||
import { chatConfig, chatReplyProcess } from './chatgpt'
|
import { chatConfig, chatReplyProcess, currentModel } from './chatgpt'
|
||||||
import { auth } from './middleware/auth'
|
import { auth } from './middleware/auth'
|
||||||
import { isNotEmptyString } from './utils/is'
|
import { isNotEmptyString } from './utils/is'
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ router.post('/session', async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const AUTH_SECRET_KEY = process.env.AUTH_SECRET_KEY
|
const AUTH_SECRET_KEY = process.env.AUTH_SECRET_KEY
|
||||||
const hasAuth = isNotEmptyString(AUTH_SECRET_KEY)
|
const hasAuth = isNotEmptyString(AUTH_SECRET_KEY)
|
||||||
res.send({ status: 'Success', message: '', data: { auth: hasAuth } })
|
res.send({ status: 'Success', message: '', data: { auth: hasAuth, model: currentModel() } })
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
res.send({ status: 'Fail', message: error.message, data: null })
|
res.send({ status: 'Fail', message: error.message, data: null })
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
<script setup lang='ts'>
|
<script setup lang='ts'>
|
||||||
import { onMounted, ref } from 'vue'
|
import { computed, onMounted, ref } from 'vue'
|
||||||
import { NSpin } from 'naive-ui'
|
import { NSpin } from 'naive-ui'
|
||||||
import { fetchChatConfig } from '@/api'
|
import { fetchChatConfig } from '@/api'
|
||||||
import pkg from '@/../package.json'
|
import pkg from '@/../package.json'
|
||||||
|
import { useAuthStore } from '@/store'
|
||||||
|
|
||||||
interface ConfigState {
|
interface ConfigState {
|
||||||
timeoutMs?: number
|
timeoutMs?: number
|
||||||
|
@ -13,10 +14,14 @@ interface ConfigState {
|
||||||
balance?: string
|
balance?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const authStore = useAuthStore()
|
||||||
|
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
|
|
||||||
const config = ref<ConfigState>()
|
const config = ref<ConfigState>()
|
||||||
|
|
||||||
|
const isChatGPTAPI = computed<boolean>(() => !!authStore.isChatGPTAPI)
|
||||||
|
|
||||||
async function fetchConfig() {
|
async function fetchConfig() {
|
||||||
try {
|
try {
|
||||||
loading.value = true
|
loading.value = true
|
||||||
|
@ -56,8 +61,12 @@ onMounted(() => {
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<p>{{ $t("setting.api") }}:{{ config?.apiModel ?? '-' }}</p>
|
<p>{{ $t("setting.api") }}:{{ config?.apiModel ?? '-' }}</p>
|
||||||
<p>{{ $t("setting.balance") }}:{{ config?.balance ?? '-' }}</p>
|
<p v-if="isChatGPTAPI">
|
||||||
<p>{{ $t("setting.reverseProxy") }}:{{ config?.reverseProxy ?? '-' }}</p>
|
{{ $t("setting.balance") }}:{{ config?.balance ?? '-' }}
|
||||||
|
</p>
|
||||||
|
<p v-if="!isChatGPTAPI">
|
||||||
|
{{ $t("setting.reverseProxy") }}:{{ config?.reverseProxy ?? '-' }}
|
||||||
|
</p>
|
||||||
<p>{{ $t("setting.timeout") }}:{{ config?.timeoutMs ?? '-' }}</p>
|
<p>{{ $t("setting.timeout") }}:{{ config?.timeoutMs ?? '-' }}</p>
|
||||||
<p>{{ $t("setting.socks") }}:{{ config?.socksProxy ?? '-' }}</p>
|
<p>{{ $t("setting.socks") }}:{{ config?.socksProxy ?? '-' }}</p>
|
||||||
<p>{{ $t("setting.httpsProxy") }}:{{ config?.httpsProxy ?? '-' }}</p>
|
<p>{{ $t("setting.httpsProxy") }}:{{ config?.httpsProxy ?? '-' }}</p>
|
||||||
|
|
|
@ -3,9 +3,14 @@ import { getToken, removeToken, setToken } from './helper'
|
||||||
import { store } from '@/store'
|
import { store } from '@/store'
|
||||||
import { fetchSession } from '@/api'
|
import { fetchSession } from '@/api'
|
||||||
|
|
||||||
|
interface SessionResponse {
|
||||||
|
auth: boolean
|
||||||
|
model: 'ChatGPTAPI' | 'ChatGPTUnofficialProxyAPI'
|
||||||
|
}
|
||||||
|
|
||||||
export interface AuthState {
|
export interface AuthState {
|
||||||
token: string | undefined
|
token: string | undefined
|
||||||
session: { auth: boolean } | null
|
session: SessionResponse | null
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useAuthStore = defineStore('auth-store', {
|
export const useAuthStore = defineStore('auth-store', {
|
||||||
|
@ -14,10 +19,16 @@ export const useAuthStore = defineStore('auth-store', {
|
||||||
session: null,
|
session: null,
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
getters: {
|
||||||
|
isChatGPTAPI(state): boolean {
|
||||||
|
return state.session?.model === 'ChatGPTAPI'
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
async getSession() {
|
async getSession() {
|
||||||
try {
|
try {
|
||||||
const { data } = await fetchSession<{ auth: boolean }>()
|
const { data } = await fetchSession<SessionResponse>()
|
||||||
this.session = { ...data }
|
this.session = { ...data }
|
||||||
return Promise.resolve(data)
|
return Promise.resolve(data)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue