mirror of
https://github.com/langgenius/dify.git
synced 2026-01-29 15:13:53 +08:00
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
35 lines
900 B
TypeScript
35 lines
900 B
TypeScript
export type DownloadUrlOptions = {
|
|
url: string
|
|
fileName?: string
|
|
rel?: string
|
|
target?: string
|
|
}
|
|
|
|
const triggerDownload = ({ url, fileName, rel, target }: DownloadUrlOptions) => {
|
|
if (!url)
|
|
return
|
|
|
|
const anchor = document.createElement('a')
|
|
anchor.href = url
|
|
if (fileName)
|
|
anchor.download = fileName
|
|
if (rel)
|
|
anchor.rel = rel
|
|
if (target)
|
|
anchor.target = target
|
|
anchor.style.display = 'none'
|
|
document.body.appendChild(anchor)
|
|
anchor.click()
|
|
anchor.remove()
|
|
}
|
|
|
|
export const downloadUrl = ({ url, fileName, rel = 'noopener noreferrer', target }: DownloadUrlOptions) => {
|
|
triggerDownload({ url, fileName, rel, target })
|
|
}
|
|
|
|
export const downloadBlob = ({ data, fileName }: { data: Blob, fileName: string }) => {
|
|
const url = window.URL.createObjectURL(data)
|
|
triggerDownload({ url, fileName, rel: 'noopener noreferrer' })
|
|
window.URL.revokeObjectURL(url)
|
|
}
|