mirror of
https://github.com/langgenius/dify.git
synced 2024-11-16 03:32:23 +08:00
Merge remote-tracking branch 'origin/license-testing' into license-testing
Some checks are pending
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/amd64, build-api-amd64) (push) Waiting to run
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/arm64, build-api-arm64) (push) Waiting to run
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/amd64, build-web-amd64) (push) Waiting to run
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/arm64, build-web-arm64) (push) Waiting to run
Build and Push API & Web / create-manifest (api, DIFY_API_IMAGE_NAME, merge-api-images) (push) Blocked by required conditions
Build and Push API & Web / create-manifest (web, DIFY_WEB_IMAGE_NAME, merge-web-images) (push) Blocked by required conditions
Some checks are pending
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/amd64, build-api-amd64) (push) Waiting to run
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/arm64, build-api-arm64) (push) Waiting to run
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/amd64, build-web-amd64) (push) Waiting to run
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/arm64, build-web-arm64) (push) Waiting to run
Build and Push API & Web / create-manifest (api, DIFY_API_IMAGE_NAME, merge-api-images) (push) Blocked by required conditions
Build and Push API & Web / create-manifest (web, DIFY_WEB_IMAGE_NAME, merge-web-images) (push) Blocked by required conditions
This commit is contained in:
commit
c939fb18ee
|
@ -101,7 +101,7 @@ const translation = {
|
||||||
licenseExpired: 'License Expired',
|
licenseExpired: 'License Expired',
|
||||||
licenseExpiredTip: 'The Dify Enterprise license for your workspace has expired. Please contact your administrator to continue using Dify.',
|
licenseExpiredTip: 'The Dify Enterprise license for your workspace has expired. Please contact your administrator to continue using Dify.',
|
||||||
licenseLost: 'License Lost',
|
licenseLost: 'License Lost',
|
||||||
licenseLostTip: 'The Dify Enterprise license server for your workspace lost. Please contact your administrator to continue using Dify.',
|
licenseLostTip: 'Failed to connect Dify license server. Please contact your administrator to continue using Dify.',
|
||||||
licenseInactive: 'License Inactive',
|
licenseInactive: 'License Inactive',
|
||||||
licenseInactiveTip: 'The Dify Enterprise license for your workspace is inactive. Please contact your administrator to continue using Dify.',
|
licenseInactiveTip: 'The Dify Enterprise license for your workspace is inactive. Please contact your administrator to continue using Dify.',
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,8 +101,8 @@ const translation = {
|
||||||
noLoginMethodTip: '请联系系统管理员添加身份认证方式',
|
noLoginMethodTip: '请联系系统管理员添加身份认证方式',
|
||||||
licenseExpired: '许可证已过期',
|
licenseExpired: '许可证已过期',
|
||||||
licenseExpiredTip: '您所在空间的 Dify Enterprise 许可证已过期,请联系管理员以继续使用 Dify。',
|
licenseExpiredTip: '您所在空间的 Dify Enterprise 许可证已过期,请联系管理员以继续使用 Dify。',
|
||||||
licenseLost: '认证服务器丢失',
|
licenseLost: '许可证丢失',
|
||||||
licenseLostTip: '您所在空间的 Dify Enterprise 认证服务器已丢失,请联系管理员以继续使用 Dify。',
|
licenseLostTip: '无法连接 Dify 许可证服务器,请联系管理员以继续使用 Dify。',
|
||||||
licenseInactive: '许可证未激活',
|
licenseInactive: '许可证未激活',
|
||||||
licenseInactiveTip: '您所在空间的 Dify Enterprise 许可证尚未激活,请联系管理员以继续使用 Dify。',
|
licenseInactiveTip: '您所在空间的 Dify Enterprise 许可证尚未激活,请联系管理员以继续使用 Dify。',
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ import type {
|
||||||
WorkflowStartedResponse,
|
WorkflowStartedResponse,
|
||||||
} from '@/types/workflow'
|
} from '@/types/workflow'
|
||||||
import { removeAccessToken } from '@/app/components/share/utils'
|
import { removeAccessToken } from '@/app/components/share/utils'
|
||||||
|
import { asyncRunSafe } from '@/utils'
|
||||||
const TIME_OUT = 100000
|
const TIME_OUT = 100000
|
||||||
|
|
||||||
const ContentType = {
|
const ContentType = {
|
||||||
|
@ -550,55 +551,125 @@ export const ssePost = (
|
||||||
}
|
}
|
||||||
|
|
||||||
// base request
|
// base request
|
||||||
export const request = <T>(url: string, options = {}, otherOptions?: IOtherOptions) => {
|
export const request = async<T>(url: string, options = {}, otherOptions?: IOtherOptions) => {
|
||||||
return new Promise<T>((resolve, reject) => {
|
try {
|
||||||
const otherOptionsForBaseFetch = otherOptions || {}
|
const otherOptionsForBaseFetch = otherOptions || {}
|
||||||
baseFetch<T>(url, options, otherOptionsForBaseFetch).then(resolve).catch((errResp) => {
|
const [err, resp] = await asyncRunSafe<T>(baseFetch(url, options, otherOptionsForBaseFetch))
|
||||||
if (errResp?.status === 401) {
|
if (err === null)
|
||||||
return refreshAccessTokenOrRelogin(TIME_OUT).then(() => {
|
return resp
|
||||||
baseFetch<T>(url, options, otherOptionsForBaseFetch).then(resolve).catch(reject)
|
const errResp: Response = err as any
|
||||||
}).catch(() => {
|
if (errResp.status === 401) {
|
||||||
const {
|
const [parseErr, errRespData] = await asyncRunSafe<ResponseError>(errResp.json())
|
||||||
isPublicAPI = false,
|
const loginUrl = `${globalThis.location.origin}/signin`
|
||||||
silent,
|
if (parseErr) {
|
||||||
} = otherOptionsForBaseFetch
|
globalThis.location.href = loginUrl
|
||||||
const bodyJson = errResp.json()
|
return Promise.reject(err)
|
||||||
if (isPublicAPI) {
|
|
||||||
return bodyJson.then((data: ResponseError) => {
|
|
||||||
if (data.code === 'web_sso_auth_required')
|
|
||||||
requiredWebSSOLogin()
|
|
||||||
|
|
||||||
if (data.code === 'unauthorized') {
|
|
||||||
removeAccessToken()
|
|
||||||
globalThis.location.reload()
|
|
||||||
}
|
|
||||||
|
|
||||||
return Promise.reject(data)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
const loginUrl = `${globalThis.location.origin}/signin`
|
|
||||||
bodyJson.then((data: ResponseError) => {
|
|
||||||
if (data.code === 'init_validate_failed' && IS_CE_EDITION && !silent)
|
|
||||||
Toast.notify({ type: 'error', message: data.message, duration: 4000 })
|
|
||||||
else if (data.code === 'not_init_validated' && IS_CE_EDITION)
|
|
||||||
globalThis.location.href = `${globalThis.location.origin}/init`
|
|
||||||
else if (data.code === 'not_setup' && IS_CE_EDITION)
|
|
||||||
globalThis.location.href = `${globalThis.location.origin}/install`
|
|
||||||
else if (location.pathname !== '/signin' || !IS_CE_EDITION)
|
|
||||||
globalThis.location.href = loginUrl
|
|
||||||
else if (!silent)
|
|
||||||
Toast.notify({ type: 'error', message: data.message })
|
|
||||||
}).catch(() => {
|
|
||||||
// Handle any other errors
|
|
||||||
globalThis.location.href = loginUrl
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
else {
|
// special code
|
||||||
reject(errResp)
|
const { code, message } = errRespData
|
||||||
|
// webapp sso
|
||||||
|
if (code === 'web_sso_auth_required') {
|
||||||
|
requiredWebSSOLogin()
|
||||||
|
return Promise.reject(err)
|
||||||
}
|
}
|
||||||
})
|
// force logout
|
||||||
})
|
if (code === 'unauthorized_and_force_logout') {
|
||||||
|
removeAccessToken()
|
||||||
|
globalThis.location.reload()
|
||||||
|
return Promise.reject(err)
|
||||||
|
}
|
||||||
|
const {
|
||||||
|
isPublicAPI = false,
|
||||||
|
silent,
|
||||||
|
} = otherOptionsForBaseFetch
|
||||||
|
if (isPublicAPI && code === 'unauthorized') {
|
||||||
|
removeAccessToken()
|
||||||
|
globalThis.location.reload()
|
||||||
|
return Promise.reject(err)
|
||||||
|
}
|
||||||
|
if (code === 'init_validate_failed' && IS_CE_EDITION && !silent) {
|
||||||
|
Toast.notify({ type: 'error', message, duration: 4000 })
|
||||||
|
return Promise.reject(err)
|
||||||
|
}
|
||||||
|
if (code === 'not_init_validated' && IS_CE_EDITION) {
|
||||||
|
globalThis.location.href = `${globalThis.location.origin}/init`
|
||||||
|
return Promise.reject(err)
|
||||||
|
}
|
||||||
|
if (code === 'not_setup' && IS_CE_EDITION) {
|
||||||
|
globalThis.location.href = `${globalThis.location.origin}/install`
|
||||||
|
return Promise.reject(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// refresh token
|
||||||
|
const [refreshErr] = await asyncRunSafe(refreshAccessTokenOrRelogin(TIME_OUT))
|
||||||
|
if (refreshErr === null)
|
||||||
|
return baseFetch<T>(url, options, otherOptionsForBaseFetch)
|
||||||
|
if (location.pathname !== '/signin' || !IS_CE_EDITION) {
|
||||||
|
globalThis.location.href = loginUrl
|
||||||
|
return Promise.reject(err)
|
||||||
|
}
|
||||||
|
if (!silent) {
|
||||||
|
Toast.notify({ type: 'error', message })
|
||||||
|
return Promise.reject(err)
|
||||||
|
}
|
||||||
|
globalThis.location.href = loginUrl
|
||||||
|
return Promise.reject(err)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return Promise.reject(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
return Promise.reject(error)
|
||||||
|
}
|
||||||
|
// return new Promise<T>((resolve, reject) => {
|
||||||
|
// baseFetch<T>(url, options, otherOptionsForBaseFetch).then(resolve).catch((errResp) => {
|
||||||
|
// if (errResp?.status === 401) {
|
||||||
|
// return refreshAccessTokenOrRelogin(TIME_OUT).then(() => {
|
||||||
|
// baseFetch<T>(url, options, otherOptionsForBaseFetch).then(resolve).catch(reject)
|
||||||
|
// }).catch(() => {
|
||||||
|
// const {
|
||||||
|
// isPublicAPI = false,
|
||||||
|
// silent,
|
||||||
|
// } = otherOptionsForBaseFetch
|
||||||
|
// const bodyJson = errResp.json()
|
||||||
|
// if (isPublicAPI) {
|
||||||
|
// return bodyJson.then((data: ResponseError) => {
|
||||||
|
// if (data.code === 'web_sso_auth_required')
|
||||||
|
// requiredWebSSOLogin()
|
||||||
|
|
||||||
|
// if (data.code === 'unauthorized') {
|
||||||
|
// removeAccessToken()
|
||||||
|
// globalThis.location.reload()
|
||||||
|
// }
|
||||||
|
|
||||||
|
// return Promise.reject(data)
|
||||||
|
// })
|
||||||
|
// }
|
||||||
|
// const loginUrl = `${globalThis.location.origin}/signin`
|
||||||
|
// bodyJson.then((data: ResponseError) => {
|
||||||
|
// if (data.code === 'init_validate_failed' && IS_CE_EDITION && !silent)
|
||||||
|
// Toast.notify({ type: 'error', message: data.message, duration: 4000 })
|
||||||
|
// else if (data.code === 'not_init_validated' && IS_CE_EDITION)
|
||||||
|
// globalThis.location.href = `${globalThis.location.origin}/init`
|
||||||
|
// else if (data.code === 'not_setup' && IS_CE_EDITION)
|
||||||
|
// globalThis.location.href = `${globalThis.location.origin}/install`
|
||||||
|
// else if (location.pathname !== '/signin' || !IS_CE_EDITION)
|
||||||
|
// globalThis.location.href = loginUrl
|
||||||
|
// else if (!silent)
|
||||||
|
// Toast.notify({ type: 'error', message: data.message })
|
||||||
|
// }).catch(() => {
|
||||||
|
// // Handle any other errors
|
||||||
|
// globalThis.location.href = loginUrl
|
||||||
|
// })
|
||||||
|
// })
|
||||||
|
// }
|
||||||
|
// else {
|
||||||
|
// reject(errResp)
|
||||||
|
// }
|
||||||
|
// })
|
||||||
|
// })
|
||||||
}
|
}
|
||||||
|
|
||||||
// request methods
|
// request methods
|
||||||
|
|
|
@ -8,10 +8,8 @@ export async function asyncRunSafe<T = any>(fn: Promise<T>): Promise<[Error] | [
|
||||||
try {
|
try {
|
||||||
return [null, await fn]
|
return [null, await fn]
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e: any) {
|
||||||
if (e instanceof Error)
|
return [e || new Error('unknown error')]
|
||||||
return [e]
|
|
||||||
return [new Error('unknown error')]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user