mirror of
https://gh-proxy.org/https://github.com/klinsmaya/SQLBot.git
synced 2026-11-09 09:46:55 +08:00
perf: Assistant token
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { store } from './index'
|
||||
|
||||
interface AssistantState {
|
||||
token: string
|
||||
}
|
||||
|
||||
export const AssistantStore = defineStore('assistant', {
|
||||
state: (): AssistantState => {
|
||||
return {
|
||||
token: '',
|
||||
}
|
||||
},
|
||||
getters: {
|
||||
getToken(): string {
|
||||
return this.token
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
setToken(token: string) {
|
||||
this.token = token
|
||||
},
|
||||
clear() {
|
||||
this.$reset()
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
export const useAssistantStore = () => {
|
||||
return AssistantStore(store)
|
||||
}
|
||||
@@ -10,6 +10,8 @@ import axios, {
|
||||
|
||||
import { useCache } from '@/utils/useCache'
|
||||
import { getLocale } from './utils'
|
||||
import { useAssistantStore } from '@/stores/assistant'
|
||||
const assistantStore = useAssistantStore()
|
||||
const { wsCache } = useCache()
|
||||
// Response data structure
|
||||
export interface ApiResponse<T = unknown> {
|
||||
@@ -70,6 +72,10 @@ class HttpService {
|
||||
if (token && config.headers) {
|
||||
config.headers['X-SQLBOT-TOKEN'] = `Bearer ${token}`
|
||||
}
|
||||
if (assistantStore.getToken) {
|
||||
config.headers['X-SQLBOT-ASSISTANT-TOKEN'] = `Assistant ${assistantStore.getToken}`
|
||||
if (config.headers['X-SQLBOT-TOKEN']) config.headers.delete('X-SQLBOT-TOKEN')
|
||||
}
|
||||
const locale = getLocale()
|
||||
if (locale) {
|
||||
/* const mapping = {
|
||||
|
||||
@@ -62,8 +62,9 @@ import IconOpeEdit from '@/assets/svg/operate/ope-edit.svg'
|
||||
import IconOpeDelete from '@/assets/svg/operate/ope-delete.svg'
|
||||
import { useRoute } from 'vue-router'
|
||||
import { assistantApi } from '@/api/assistant'
|
||||
import { useUserStore } from '@/stores/user'
|
||||
const userStore = useUserStore()
|
||||
import { useAssistantStore } from '@/stores/assistant'
|
||||
|
||||
const assistantStore = useAssistantStore()
|
||||
const route = useRoute()
|
||||
|
||||
const chatRef = ref()
|
||||
@@ -96,7 +97,7 @@ const loading = ref(true)
|
||||
onBeforeMount(async () => {
|
||||
const assistantId = route.params.id
|
||||
validator.value = await assistantApi.validate(assistantId)
|
||||
userStore.setToken(validator.value.token)
|
||||
assistantStore.setToken(validator.value.token)
|
||||
loading.value = false
|
||||
})
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user