Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/apps/system/crud/assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def get_complete_endpoint(self, endpoint: str) -> str | None:
if not domain_text:
return None
if ',' in domain_text:
return self.request_origin.strip('/') if self.request_origin else domain_text.split(',')[0].strip('/') + endpoint
return (self.request_origin.strip('/') if self.request_origin else domain_text.split(',')[0].strip('/')) + endpoint
else:
return f"{domain_text}{endpoint}"

Expand Down
2 changes: 1 addition & 1 deletion backend/apps/system/middleware/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async def dispatch(self, request, call_next):
if validator[0]:
request.state.current_user = validator[1]
request.state.assistant = validator[2]
origin = request.headers.get("origin") or get_origin_from_referer(request)
origin = request.headers.get("X-SQLBOT-HOST-ORIGIN") or get_origin_from_referer(request)
if origin and validator[2]:
request.state.assistant.request_origin = origin
return await call_next(request)
Expand Down
14 changes: 7 additions & 7 deletions frontend/public/assistant.js
Original file line number Diff line number Diff line change
Expand Up @@ -539,12 +539,15 @@
return
}
if (event.data?.busi == 'ready' && event.data?.ready) {
const certificate = parsrCertificate(data)
params = {
busi: 'certificate',
certificate,
eventName,
messageId: id,
hostOrigin: window.location.origin,
}
if (data.type === 1) {
const certificate = parsrCertificate(data)
params['busi'] = 'certificate'
params['certificate'] = certificate
}
const contentWindow = iframe.contentWindow
contentWindow.postMessage(params, url)
Expand Down Expand Up @@ -596,10 +599,7 @@
tempData['userFlag'] = userFlag
tempData['history'] = history
initsqlbot_assistant(tempData)
if (data.type == 1) {
registerMessageEvent(id, tempData)
// postMessage the certificate to iframe
}
registerMessageEvent(id, tempData)
})
.catch((e) => {
showMsg('嵌入失败', e.message)
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/stores/assistant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ interface AssistantState {
online: boolean
pageEmbedded?: boolean
history: boolean
hostOrigin: string
requestPromiseMap: Map<string, PendingRequest>
}

Expand All @@ -36,6 +37,7 @@ export const AssistantStore = defineStore('assistant', {
online: false,
pageEmbedded: false,
history: true,
hostOrigin: '',
requestPromiseMap: new Map<string, PendingRequest>(),
}
},
Expand Down Expand Up @@ -70,6 +72,9 @@ export const AssistantStore = defineStore('assistant', {
getEmbedded(): boolean {
return this.assistant && this.type === 4
},
getHostOrigin(): string {
return this.hostOrigin
},
},
actions: {
refreshCertificate<T>() {
Expand Down Expand Up @@ -138,6 +143,9 @@ export const AssistantStore = defineStore('assistant', {
setHistory(history: boolean) {
this.history = history ?? true
},
setHostOrigin(origin: string) {
this.hostOrigin = origin
},
async setChat() {
if (!this.assistant) {
return null
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/utils/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ class HttpService {
if (!assistantStore.getType || assistantStore.getType === 2) {
config.headers['X-SQLBOT-ASSISTANT-ONLINE'] = assistantStore.getOnline
}
if (assistantStore.getHostOrigin) {
config.headers['X-SQLBOT-HOST-ORIGIN'] = assistantStore.getHostOrigin
}
}
const locale = getLocale()
if (locale) {
Expand Down Expand Up @@ -302,6 +305,9 @@ class HttpService {
encodeURIComponent(assistantStore.getCertificate)
)
}
if (assistantStore.getHostOrigin) {
heads['X-SQLBOT-HOST-ORIGIN'] = assistantStore.getHostOrigin
}
if (!assistantStore.getType || assistantStore.getType === 2) {
heads['X-SQLBOT-ASSISTANT-ONLINE'] = assistantStore.getOnline
}
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/views/embedded/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ const communicationCb = async (event: any) => {
assistantStore.setCertificate(certificate)
assistantStore.resolveCertificate(certificate)
}
if (event.data?.hostOrigin) {
assistantStore.setHostOrigin(event.data?.hostOrigin)
}
if (event.data?.busi == 'setOnline') {
setFormatOnline(event.data.online)
}
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/views/embedded/page.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ const communicationCb = async (event: any) => {
assistantStore.setCertificate(certificate)
assistantStore.resolveCertificate(certificate)
}
if (event.data?.hostOrigin) {
assistantStore.setHostOrigin(event.data?.hostOrigin)
}
if (event.data?.busi == 'setOnline') {
setFormatOnline(event.data.online)
}
Expand Down