mirror of
https://github.com/rustfs/console.git
synced 2026-08-30 17:14:47 +08:00
ca87e9e007
* feat: move status route and format repo * fix: resolve lint warnings * fix: load bucket usage asynchronously * fix: sign version config request * fix: show spinner for bucket usage loading * fix: prevent object list fetch loop * fix: dedupe list requests * feat: add sidebar version footer
39 lines
1.3 KiB
TypeScript
39 lines
1.3 KiB
TypeScript
export function download(filename: string, text: string) {
|
|
const element = document.createElement("a")
|
|
element.setAttribute("href", "data:text/plain;charset=utf-8," + encodeURIComponent(text))
|
|
element.setAttribute("download", filename)
|
|
element.style.display = "none"
|
|
document.body.appendChild(element)
|
|
element.click()
|
|
document.body.removeChild(element)
|
|
}
|
|
|
|
export interface ExportFileRes {
|
|
headers: Record<string, string>
|
|
data: Blob
|
|
}
|
|
|
|
/**
|
|
* Export blob file with content-type headers
|
|
*/
|
|
export function exportFile(res: ExportFileRes, fileName: string) {
|
|
const file = res.data
|
|
const name = decodeURIComponent(res.headers.filename ?? "")
|
|
|
|
if (typeof window !== "undefined" && "navigator" in window && "msSaveOrOpenBlob" in window.navigator) {
|
|
const blob = new Blob([file], { type: res.headers["content-type"] ?? "application/octet-stream" })
|
|
;(window.navigator as unknown as { msSaveOrOpenBlob: (blob: Blob, name: string) => void }).msSaveOrOpenBlob(
|
|
blob,
|
|
fileName || name,
|
|
)
|
|
} else {
|
|
const type = res.headers["content-type"] ?? "application/octet-stream"
|
|
const objectUrl = window.URL.createObjectURL(new Blob([file], { type }))
|
|
const link = document.createElement("a")
|
|
link.download = fileName || name
|
|
link.href = objectUrl
|
|
link.click()
|
|
window.URL.revokeObjectURL(objectUrl)
|
|
}
|
|
}
|