Remove useless code (#4416)

This commit is contained in:
Garfield Dai
2024-05-15 16:14:49 +08:00
committed by GitHub
parent da81233d61
commit dd94931116
26 changed files with 466 additions and 230 deletions

View File

@@ -10,6 +10,7 @@ import type {
WorkflowFinishedResponse,
WorkflowStartedResponse,
} from '@/types/workflow'
import { removeAccessToken } from '@/app/components/share/utils'
const TIME_OUT = 100000
const ContentType = {
@@ -97,6 +98,10 @@ function unicodeToChar(text: string) {
})
}
function requiredWebSSOLogin() {
globalThis.location.href = `/webapp-signin?redirect_url=${globalThis.location.pathname}`
}
export function format(text: string) {
let res = text.trim()
if (res.startsWith('\n'))
@@ -308,6 +313,15 @@ const baseFetch = <T>(
return bodyJson.then((data: ResponseError) => {
if (!silent)
Toast.notify({ type: 'error', message: data.message })
if (data.code === 'web_sso_auth_required')
requiredWebSSOLogin()
if (data.code === 'unauthorized') {
removeAccessToken()
globalThis.location.reload()
}
return Promise.reject(data)
})
}
@@ -467,6 +481,16 @@ export const ssePost = (
if (!/^(2|3)\d{2}$/.test(String(res.status))) {
res.json().then((data: any) => {
Toast.notify({ type: 'error', message: data.message || 'Server Error' })
if (isPublicAPI) {
if (data.code === 'web_sso_auth_required')
requiredWebSSOLogin()
if (data.code === 'unauthorized') {
removeAccessToken()
globalThis.location.reload()
}
}
})
onError?.('Server Error')
return

View File

@@ -34,6 +34,7 @@ import type {
ModelProvider,
} from '@/app/components/header/account-setting/model-provider-page/declarations'
import type { RETRIEVE_METHOD } from '@/types/app'
import type { SystemFeatures } from '@/types/feature'
export const login: Fetcher<CommonResponse & { data: string }, { url: string; body: Record<string, any> }> = ({ url, body }) => {
return post(url, { body }) as Promise<CommonResponse & { data: string }>
@@ -271,3 +272,7 @@ type RetrievalMethodsRes = {
export const fetchSupportRetrievalMethods: Fetcher<RetrievalMethodsRes, string> = (url) => {
return get<RetrievalMethodsRes>(url)
}
export const getSystemFeatures = () => {
return get<SystemFeatures>('/system-features')
}

View File

@@ -1,14 +0,0 @@
import { get } from './base'
import type { EnterpriseFeatures } from '@/types/enterprise'
export const getEnterpriseFeatures = () => {
return get<EnterpriseFeatures>('/enterprise-features')
}
export const getSAMLSSOUrl = () => {
return get<{ url: string }>('/enterprise/sso/saml/login')
}
export const getOIDCSSOUrl = () => {
return get<{ url: string; state: string }>('/enterprise/sso/oidc/login')
}

View File

@@ -11,6 +11,7 @@ import type {
ConversationItem,
} from '@/models/share'
import type { ChatConfig } from '@/app/components/base/chat/types'
import type { SystemFeatures } from '@/types/feature'
function getAction(action: 'get' | 'post' | 'del' | 'patch', isInstalledApp: boolean) {
switch (action) {
@@ -135,6 +136,29 @@ export const fetchAppParams = async (isInstalledApp: boolean, installedAppId = '
return (getAction('get', isInstalledApp))(getUrl('parameters', isInstalledApp, installedAppId)) as Promise<ChatConfig>
}
export const fetchSystemFeatures = async () => {
return (getAction('get', false))(getUrl('system-features', false, '')) as Promise<SystemFeatures>
}
export const fetchWebSAMLSSOUrl = async (appCode: string, redirectUrl: string) => {
return (getAction('get', false))(getUrl('/enterprise/sso/saml/login', false, ''), {
params: {
app_code: appCode,
redirect_url: redirectUrl,
},
}) as Promise<{ url: string }>
}
export const fetchWebOIDCSSOUrl = async (appCode: string, redirectUrl: string) => {
return (getAction('get', false))(getUrl('/enterprise/sso/oidc/login', false, ''), {
params: {
app_code: appCode,
redirect_url: redirectUrl,
},
}) as Promise<{ url: string }>
}
export const fetchAppMeta = async (isInstalledApp: boolean, installedAppId = '') => {
return (getAction('get', isInstalledApp))(getUrl('meta', isInstalledApp, installedAppId)) as Promise<AppMeta>
}

9
web/service/sso.ts Normal file
View File

@@ -0,0 +1,9 @@
import { get } from './base'
export const getUserSAMLSSOUrl = () => {
return get<{ url: string }>('/enterprise/sso/saml/login')
}
export const getUserOIDCSSOUrl = () => {
return get<{ url: string; state: string }>('/enterprise/sso/oidc/login')
}