Feat/chat support voice input (#532)
This commit is contained in:
@@ -35,7 +35,9 @@ export type IOnError = (msg: string) => void
|
||||
|
||||
type IOtherOptions = {
|
||||
isPublicAPI?: boolean
|
||||
bodyStringify?: boolean
|
||||
needAllResponseContent?: boolean
|
||||
deleteContentType?: boolean
|
||||
onData?: IOnData // for stream
|
||||
onError?: IOnError
|
||||
onCompleted?: IOnCompleted // for stream
|
||||
@@ -132,7 +134,9 @@ const baseFetch = (
|
||||
fetchOptions: any,
|
||||
{
|
||||
isPublicAPI = false,
|
||||
bodyStringify = true,
|
||||
needAllResponseContent,
|
||||
deleteContentType,
|
||||
}: IOtherOptions,
|
||||
) => {
|
||||
const options = Object.assign({}, baseOptions, fetchOptions)
|
||||
@@ -141,6 +145,15 @@ const baseFetch = (
|
||||
options.headers.set('Authorization', `bearer ${sharedToken}`)
|
||||
}
|
||||
|
||||
if (deleteContentType) {
|
||||
options.headers.delete('Content-Type')
|
||||
}
|
||||
else {
|
||||
const contentType = options.headers.get('Content-Type')
|
||||
if (!contentType)
|
||||
options.headers.set('Content-Type', ContentType.json)
|
||||
}
|
||||
|
||||
const urlPrefix = isPublicAPI ? PUBLIC_API_PREFIX : API_PREFIX
|
||||
let urlWithPrefix = `${urlPrefix}${url.startsWith('/') ? url : `/${url}`}`
|
||||
|
||||
@@ -160,7 +173,7 @@ const baseFetch = (
|
||||
delete options.params
|
||||
}
|
||||
|
||||
if (body)
|
||||
if (body && bodyStringify)
|
||||
options.body = JSON.stringify(body)
|
||||
|
||||
// Handle timeout
|
||||
@@ -285,6 +298,10 @@ export const ssePost = (url: string, fetchOptions: any, { isPublicAPI = false, o
|
||||
signal: abortController.signal,
|
||||
}, fetchOptions)
|
||||
|
||||
const contentType = options.headers.get('Content-Type')
|
||||
if (!contentType)
|
||||
options.headers.set('Content-Type', ContentType.json)
|
||||
|
||||
getAbortController?.(abortController)
|
||||
|
||||
const urlPrefix = isPublicAPI ? PUBLIC_API_PREFIX : API_PREFIX
|
||||
|
Reference in New Issue
Block a user