@budibase/frontend-core 2.23.4 → 2.23.5
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 +5 -5
- package/src/api/attachments.js +14 -0
- package/src/utils/download.js +33 -3
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@budibase/frontend-core",
|
|
3
|
-
"version": "2.23.
|
|
3
|
+
"version": "2.23.5",
|
|
4
4
|
"description": "Budibase frontend core libraries used in builder and client",
|
|
5
5
|
"author": "Budibase",
|
|
6
6
|
"license": "MPL-2.0",
|
|
7
7
|
"svelte": "src/index.js",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@budibase/bbui": "2.23.
|
|
10
|
-
"@budibase/shared-core": "2.23.
|
|
11
|
-
"@budibase/types": "2.23.
|
|
9
|
+
"@budibase/bbui": "2.23.5",
|
|
10
|
+
"@budibase/shared-core": "2.23.5",
|
|
11
|
+
"@budibase/types": "2.23.5",
|
|
12
12
|
"dayjs": "^1.10.8",
|
|
13
13
|
"lodash": "4.17.21",
|
|
14
14
|
"socket.io-client": "^4.6.1"
|
|
15
15
|
},
|
|
16
|
-
"gitHead": "
|
|
16
|
+
"gitHead": "c2744834f4b0658b965a9060dee1b0ce05156cd8"
|
|
17
17
|
}
|
package/src/api/attachments.js
CHANGED
|
@@ -88,5 +88,19 @@ export const buildAttachmentEndpoints = API => {
|
|
|
88
88
|
},
|
|
89
89
|
})
|
|
90
90
|
},
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Download an attachment from a row given its column name.
|
|
94
|
+
* @param datasourceId the ID of the datasource to download from
|
|
95
|
+
* @param rowId the ID of the row to download from
|
|
96
|
+
* @param columnName the column name to download
|
|
97
|
+
*/
|
|
98
|
+
downloadAttachment: async (datasourceId, rowId, columnName, options) => {
|
|
99
|
+
return await API.get({
|
|
100
|
+
url: `/api/${datasourceId}/rows/${rowId}/attachment/${columnName}`,
|
|
101
|
+
parseResponse: response => response,
|
|
102
|
+
suppressErrors: options?.suppressErrors,
|
|
103
|
+
})
|
|
104
|
+
},
|
|
91
105
|
}
|
|
92
106
|
}
|
package/src/utils/download.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const extractFileNameRegex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/
|
|
2
|
+
|
|
1
3
|
export function downloadText(filename, text) {
|
|
2
4
|
if (typeof text === "object") {
|
|
3
5
|
text = JSON.stringify(text)
|
|
@@ -17,9 +19,7 @@ export async function downloadStream(streamResponse) {
|
|
|
17
19
|
|
|
18
20
|
const contentDisposition = streamResponse.headers.get("Content-Disposition")
|
|
19
21
|
|
|
20
|
-
const matches =
|
|
21
|
-
contentDisposition
|
|
22
|
-
)
|
|
22
|
+
const matches = extractFileNameRegex.exec(contentDisposition)
|
|
23
23
|
|
|
24
24
|
const filename = matches[1].replace(/['"]/g, "")
|
|
25
25
|
|
|
@@ -34,3 +34,33 @@ export async function downloadStream(streamResponse) {
|
|
|
34
34
|
|
|
35
35
|
URL.revokeObjectURL(blobUrl)
|
|
36
36
|
}
|
|
37
|
+
|
|
38
|
+
export async function downloadFile(url, body) {
|
|
39
|
+
const response = await fetch(url, {
|
|
40
|
+
method: "POST",
|
|
41
|
+
headers: {
|
|
42
|
+
"Content-Type": "application/json",
|
|
43
|
+
},
|
|
44
|
+
body: JSON.stringify(body),
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
if (!response.ok) {
|
|
48
|
+
return false
|
|
49
|
+
} else {
|
|
50
|
+
const contentDisposition = response.headers.get("Content-Disposition")
|
|
51
|
+
|
|
52
|
+
const matches = extractFileNameRegex.exec(contentDisposition)
|
|
53
|
+
|
|
54
|
+
const filename = matches[1].replace(/['"]/g, "")
|
|
55
|
+
|
|
56
|
+
const url = URL.createObjectURL(await response.blob())
|
|
57
|
+
|
|
58
|
+
const link = document.createElement("a")
|
|
59
|
+
link.href = url
|
|
60
|
+
link.download = filename
|
|
61
|
+
link.click()
|
|
62
|
+
|
|
63
|
+
URL.revokeObjectURL(url)
|
|
64
|
+
return true
|
|
65
|
+
}
|
|
66
|
+
}
|