@ -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 )
}