Co-authored-by: qingguo <qingguo@lexin.com>
This commit is contained in:
GQ1994
2025-05-17 12:32:27 +08:00
committed by GitHub
parent 7d0106b220
commit e7659ecd9d
33 changed files with 89 additions and 83 deletions

View File

@@ -1,6 +1,7 @@
import { API_PREFIX, IS_CE_EDITION, PUBLIC_API_PREFIX, PUBLIC_WEB_PREFIX, WEB_PREFIX } from '@/config'
import { API_PREFIX, IS_CE_EDITION, PUBLIC_API_PREFIX } from '@/config'
import { refreshAccessTokenOrRelogin } from './refresh-token'
import Toast from '@/app/components/base/toast'
import { basePath } from '@/utils/var'
import type { AnnotationReply, MessageEnd, MessageReplace, ThoughtItem } from '@/app/components/base/chat/chat/type'
import type { VisionFile } from '@/types/app'
import type {
@@ -108,7 +109,7 @@ function unicodeToChar(text: string) {
}
function requiredWebSSOLogin() {
globalThis.location.href = `${PUBLIC_WEB_PREFIX}/webapp-signin?redirect_url=${globalThis.location.pathname}`
globalThis.location.href = `/webapp-signin?redirect_url=${globalThis.location.pathname}`
}
export function format(text: string) {
@@ -466,7 +467,7 @@ export const request = async<T>(url: string, options = {}, otherOptions?: IOther
const errResp: Response = err as any
if (errResp.status === 401) {
const [parseErr, errRespData] = await asyncRunSafe<ResponseError>(errResp.json())
const loginUrl = `${WEB_PREFIX}/signin`
const loginUrl = `${globalThis.location.origin}${basePath}/signin`
if (parseErr) {
globalThis.location.href = loginUrl
return Promise.reject(err)
@@ -498,11 +499,11 @@ export const request = async<T>(url: string, options = {}, otherOptions?: IOther
return Promise.reject(err)
}
if (code === 'not_init_validated' && IS_CE_EDITION) {
globalThis.location.href = `${WEB_PREFIX}/init`
globalThis.location.href = `${globalThis.location.origin}${basePath}/init`
return Promise.reject(err)
}
if (code === 'not_setup' && IS_CE_EDITION) {
globalThis.location.href = `${WEB_PREFIX}/install`
globalThis.location.href = `${globalThis.location.origin}${basePath}/install`
return Promise.reject(err)
}
@@ -510,7 +511,7 @@ export const request = async<T>(url: string, options = {}, otherOptions?: IOther
const [refreshErr] = await asyncRunSafe(refreshAccessTokenOrRelogin(TIME_OUT))
if (refreshErr === null)
return baseFetch<T>(url, options, otherOptionsForBaseFetch)
if (!location.pathname.includes('/signin') || !IS_CE_EDITION) {
if (location.pathname !== `${basePath}/signin` || !IS_CE_EDITION) {
globalThis.location.href = loginUrl
return Promise.reject(err)
}

View File

@@ -2,7 +2,7 @@ import type { AfterResponseHook, BeforeErrorHook, BeforeRequestHook, Hooks } fro
import ky from 'ky'
import type { IOtherOptions } from './base'
import Toast from '@/app/components/base/toast'
import { API_PREFIX, MARKETPLACE_API_PREFIX, PUBLIC_API_PREFIX, WEB_PREFIX } from '@/config'
import { API_PREFIX, MARKETPLACE_API_PREFIX, PUBLIC_API_PREFIX } from '@/config'
import { getInitialTokenV2, isTokenV1 } from '@/app/components/share/utils'
import { getProcessedSystemVariablesFromUrlParams } from '@/app/components/base/chat/utils'
@@ -44,7 +44,7 @@ const afterResponseErrorCode = (otherOptions: IOtherOptions): AfterResponseHook
if (!otherOptions.silent)
Toast.notify({ type: 'error', message: data.message })
if (data.code === 'already_setup')
globalThis.location.href = `${WEB_PREFIX}/signin`
globalThis.location.href = `${globalThis.location.origin}/signin`
})
break
case 401: