mirror of
http://112.124.100.131/huang.ze/ebiz-dify-ai.git
synced 2025-12-09 02:46:52 +08:00
Remove useless code (#4416)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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')
|
||||
}
|
||||
|
||||
@@ -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')
|
||||
}
|
||||
@@ -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
9
web/service/sso.ts
Normal 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')
|
||||
}
|
||||
Reference in New Issue
Block a user