mirror of
https://github.com/langgenius/dify.git
synced 2026-04-29 20:48:01 +08:00
chore: fix request form data
This commit is contained in:
parent
7ccc268ced
commit
4a6a1b9855
@ -108,10 +108,6 @@ const beforeRequestAuthorization: BeforeRequestHook = (request) => {
|
|||||||
request.headers.set('Authorization', `Bearer ${accessToken}`)
|
request.headers.set('Authorization', `Bearer ${accessToken}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const beforeRequestDeleteContentType: BeforeRequestHook = (request) => {
|
|
||||||
request.headers.delete('Content-Type')
|
|
||||||
}
|
|
||||||
|
|
||||||
const baseHooks: Hooks = {
|
const baseHooks: Hooks = {
|
||||||
afterResponse: [
|
afterResponse: [
|
||||||
afterResponse204,
|
afterResponse204,
|
||||||
@ -134,7 +130,7 @@ export const baseOptions: RequestInit = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function base<T>(url: string, options: FetchOptionType = {}, otherOptions: IOtherOptions = {}): Promise<T> {
|
async function base<T>(url: string, options: FetchOptionType = {}, otherOptions: IOtherOptions = {}): Promise<T> {
|
||||||
const { params, body, ...init } = Object.assign({}, baseOptions, options)
|
const { params, body, headers, ...init } = Object.assign({}, baseOptions, options)
|
||||||
const {
|
const {
|
||||||
isPublicAPI = false,
|
isPublicAPI = false,
|
||||||
isMarketplaceAPI = false,
|
isMarketplaceAPI = false,
|
||||||
@ -159,6 +155,9 @@ async function base<T>(url: string, options: FetchOptionType = {}, otherOptions:
|
|||||||
|
|
||||||
const fetchPathname = `${base}${url.startsWith('/') ? url : `/${url}`}`
|
const fetchPathname = `${base}${url.startsWith('/') ? url : `/${url}`}`
|
||||||
|
|
||||||
|
if (deleteContentType)
|
||||||
|
(headers as any).delete('Content-Type')
|
||||||
|
|
||||||
const client = baseClient.extend({
|
const client = baseClient.extend({
|
||||||
hooks: {
|
hooks: {
|
||||||
...baseHooks,
|
...baseHooks,
|
||||||
@ -170,8 +169,7 @@ async function base<T>(url: string, options: FetchOptionType = {}, otherOptions:
|
|||||||
...baseHooks.beforeRequest || [],
|
...baseHooks.beforeRequest || [],
|
||||||
isPublicAPI && beforeRequestPublicAuthorization,
|
isPublicAPI && beforeRequestPublicAuthorization,
|
||||||
!isPublicAPI && !isMarketplaceAPI && beforeRequestAuthorization,
|
!isPublicAPI && !isMarketplaceAPI && beforeRequestAuthorization,
|
||||||
deleteContentType && beforeRequestDeleteContentType,
|
].filter(Boolean),
|
||||||
].filter(i => !!i),
|
|
||||||
afterResponse: [
|
afterResponse: [
|
||||||
...baseHooks.afterResponse || [],
|
...baseHooks.afterResponse || [],
|
||||||
afterResponseErrorCode(otherOptions),
|
afterResponseErrorCode(otherOptions),
|
||||||
@ -181,6 +179,7 @@ async function base<T>(url: string, options: FetchOptionType = {}, otherOptions:
|
|||||||
|
|
||||||
const res = await client(fetchPathname, {
|
const res = await client(fetchPathname, {
|
||||||
...init,
|
...init,
|
||||||
|
headers,
|
||||||
credentials: isMarketplaceAPI
|
credentials: isMarketplaceAPI
|
||||||
? 'omit'
|
? 'omit'
|
||||||
: (options.credentials || 'include'),
|
: (options.credentials || 'include'),
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user