@budibase/frontend-core 2.23.4 → 2.23.6

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,17 +1,17 @@
1
1
  {
2
2
  "name": "@budibase/frontend-core",
3
- "version": "2.23.4",
3
+ "version": "2.23.6",
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.4",
10
- "@budibase/shared-core": "2.23.4",
11
- "@budibase/types": "2.23.4",
9
+ "@budibase/bbui": "2.23.6",
10
+ "@budibase/shared-core": "2.23.6",
11
+ "@budibase/types": "2.23.6",
12
12
  "dayjs": "^1.10.8",
13
13
  "lodash": "4.17.21",
14
14
  "socket.io-client": "^4.6.1"
15
15
  },
16
- "gitHead": "8a3a415c5f998d40ec0e96e73ccd171fa1bc2226"
16
+ "gitHead": "c19bcab71d54cb614911afbb6229e9c42bde16aa"
17
17
  }
@@ -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
  }
@@ -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 = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/.exec(
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
+ }