feat: dify1.11.1进行适配
This commit is contained in:
@@ -128,7 +128,35 @@ export const createFirstDocument = ({ body }: { body: CreateDocumentReq }): Prom
|
||||
}
|
||||
|
||||
export const createDocument = ({ datasetId, body }: { datasetId: string; body: CreateDocumentReq }): Promise<createDocumentResponse> => {
|
||||
return post<createDocumentResponse>(`/datasets/${datasetId}/documents`, { body })
|
||||
const IsHsAiApp = localStorage.getItem('IsHsAiApp')
|
||||
if (IsHsAiApp == null) {
|
||||
// 当 IsHsAiApp 为 null 时,调用 post 方法并返回其结果
|
||||
return post<createDocumentResponse>(`/datasets/${datasetId}/documents`, { body })
|
||||
}
|
||||
else{
|
||||
// 当 IsHsAiApp 不为 null 时,调用 Electron 的 IPC 方法
|
||||
// 需要返回一个 Promise,以符合 Fetcher 的返回类型
|
||||
return new Promise<createDocumentResponse>((resolve, reject) => {
|
||||
if (typeof window !== 'undefined' && 'electron' in window) {
|
||||
// 安全地使用 window.electron
|
||||
// @ts-ignore
|
||||
window.electron.ipcRenderer
|
||||
.invoke('difyWebUploadFileToApi', datasetId, JSON.stringify(body))
|
||||
.then((response: any) => {
|
||||
console.log(response)
|
||||
// 假设 response 是符合 createDocumentResponse 类型的
|
||||
resolve(response as createDocumentResponse)
|
||||
})
|
||||
.catch((error: any) => {
|
||||
console.error(error)
|
||||
reject(error) // 捕获错误并拒绝 Promise
|
||||
})
|
||||
}
|
||||
else {
|
||||
console.warn('Electron API is not available in this environment.')
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export const fetchIndexingEstimate = ({ datasetId, documentId }: CommonDocReq): Promise<IndexingEstimateResponse> => {
|
||||
|
||||
Reference in New Issue
Block a user