Files
Enterprise-Knowledge-Base/frontend/src/composables/useApiBaseUrlDisplay.ts
T
wizardchen 8285188501 feat(frontend): add Chrome extension and Claw Skill integration landing pages
Move Chrome extension and Claw Skill entries from the user menu into the
integrations center with dedicated landing tabs, setup steps, and lobster-themed Claw styling.
2026-06-28 00:31:38 +08:00

61 lines
1.6 KiB
TypeScript

import { computed, onMounted, ref } from 'vue'
import { getApiBaseUrl } from '@/utils/api-base'
type WeKnoraDesktopWindow = Window & {
__WEKNORA_API_BASE__?: string
go?: {
main?: {
App?: {
GetAPIBaseURL?: () => Promise<string> | string
}
}
}
}
export function useApiBaseUrlDisplay() {
const wailsApiBaseURL = ref<string | null>(null)
const apiBaseUrlDisplay = computed(() => {
if (wailsApiBaseURL.value) {
return wailsApiBaseURL.value
}
const configured = getApiBaseUrl().trim().replace(/\/$/, '')
let origin = typeof window !== 'undefined' ? window.location.origin : ''
if (!origin || origin === 'null') {
origin = ''
}
const base = configured || origin
return `${base}/api/v1`
})
async function loadApiBaseUrl() {
const win = window as WeKnoraDesktopWindow
for (let i = 0; i < 40; i++) {
const injected = win.__WEKNORA_API_BASE__
if (typeof injected === 'string' && injected.trim()) {
wailsApiBaseURL.value = injected.trim().replace(/\/$/, '')
return
}
const fn = win.go?.main?.App?.GetAPIBaseURL
if (typeof fn === 'function') {
try {
const raw = await Promise.resolve(fn())
if (typeof raw === 'string' && raw.trim()) {
wailsApiBaseURL.value = raw.trim().replace(/\/$/, '')
return
}
} catch {
/* binding error */
}
}
await new Promise<void>((resolve) => setTimeout(resolve, 50))
}
}
onMounted(() => {
void loadApiBaseUrl()
})
return { apiBaseUrlDisplay }
}