KI-AGENT: Dateivorschauen authentifiziert laden
This commit is contained in:
@@ -146,6 +146,26 @@ export const useFiles = () => {
|
||||
|
||||
}
|
||||
|
||||
const openFile = async (id: string) => {
|
||||
const targetWindow = window.open("about:blank", "_blank")
|
||||
|
||||
try {
|
||||
const blob = await downloadFile(id, undefined, true) as Blob
|
||||
const objectUrl = URL.createObjectURL(blob)
|
||||
|
||||
if (targetWindow) {
|
||||
targetWindow.location.replace(objectUrl)
|
||||
} else {
|
||||
window.open(objectUrl, "_blank")
|
||||
}
|
||||
|
||||
window.setTimeout(() => URL.revokeObjectURL(objectUrl), 60_000)
|
||||
} catch (error) {
|
||||
targetWindow?.close()
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
const dataURLtoFile = (dataurl:string, filename:string) => {
|
||||
let arr = dataurl.split(","),
|
||||
//@ts-ignore
|
||||
@@ -160,5 +180,5 @@ export const useFiles = () => {
|
||||
}
|
||||
|
||||
|
||||
return {uploadFiles, selectDocuments, selectSomeDocuments, selectDocument, downloadFile, dataURLtoFile}
|
||||
return {uploadFiles, selectDocuments, selectSomeDocuments, selectDocument, downloadFile, openFile, dataURLtoFile}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user