This commit is contained in:
Yvan
2026-09-04 14:07:09 +08:00
parent af1e194396
commit 43db5e5450
22 changed files with 416 additions and 134 deletions
@@ -326,17 +326,28 @@ const selected = computed(
const integrationKey = (item) => `${item.kind}/${item.provider}`
const providerMeta = (item) => TARGETS[integrationKey(item)] || TARGETS[TARGET_ORDER[0]]
const isWebSocket = (item) => integrationKey(item) === 'websocket/melody'
const websocketApiBase = () => String(import.meta.env.VITE_BASE_API || '').trim()
const websocketUrlOverride = () => String(import.meta.env.VITE_WEBSOCKET_URL || '').trim()
const websocketUrlPath = (value) => {
try {
return new URL(value, window.location.origin).pathname.replace(/\/+$/, '')
} catch {
return ''
}
}
const websocketBackendIsExplicit = () =>
Boolean(
String(import.meta.env.VITE_WEBSOCKET_URL || '').trim() ||
String(import.meta.env.VITE_SERVER_PORT || '').trim()
websocketUrlOverride() ||
String(import.meta.env.VITE_SERVER_PORT || '').trim() ||
/^https?:\/\//i.test(websocketApiBase())
)
const websocketOrigin = () => {
if (websocketBackendIsExplicit()) {
const configuredBase = String(
import.meta.env.VITE_WEBSOCKET_URL ||
import.meta.env.VITE_BASE_PATH ||
window.location.origin
websocketUrlOverride() ||
(/^https?:\/\//i.test(websocketApiBase())
? websocketApiBase()
: import.meta.env.VITE_BASE_PATH || window.location.origin)
)
const backend = new URL(configuredBase, window.location.origin)
if (
@@ -355,9 +366,14 @@ const websocketOrigin = () => {
return `${protocol}//${window.location.host}`
}
const websocketPathPrefix = () => {
if (websocketBackendIsExplicit()) return ''
const base = String(import.meta.env.VITE_BASE_API || '').trim()
if (!base || /^https?:\/\//i.test(base)) return ''
const override = websocketUrlOverride()
if (override) return websocketUrlPath(override)
const base = websocketApiBase()
if (!base) return ''
if (/^https?:\/\//i.test(base)) {
return websocketUrlPath(base)
}
if (String(import.meta.env.VITE_SERVER_PORT || '').trim()) return ''
return `/${base.replace(/^\/+|\/+$/g, '')}`
}
const connectionInfo = computed(() => {