muffin-admin 3.14.0 → 3.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "muffin-admin",
3
- "version": "3.14.0",
3
+ "version": "3.15.0",
4
4
  "description": "NPM package for https://github.com/klen/muffin-admin",
5
5
  "files": [
6
6
  "src",
@@ -89,13 +89,17 @@ export function MuffinDataprovider(apiUrl: string) {
89
89
  },
90
90
 
91
91
  downloadFile: async (path: string) => {
92
+ path = path.replace(/^\/+/, "")
92
93
  const response = await fetch(`${apiUrl}/${path}`, {
93
94
  headers: requestHeaders,
94
95
  })
95
96
  const url = window.URL.createObjectURL(await response.blob())
96
97
  const link = document.createElement("a")
97
98
  link.href = url
98
- link.setAttribute("download", path)
99
+ const filename =
100
+ response.headers.get("content-disposition")?.split("filename=")[1] || path.split("/").pop()
101
+ link.setAttribute("download", filename)
102
+ if (filename) link.setAttribute("download", filename)
99
103
  link.click()
100
104
  // no need to append link as child to body.
101
105
  setTimeout(() => window.URL.revokeObjectURL(url), 0) // this is important too, otherwise we will be unnecessarily spiking memory!