1
0
Fork 0
mirror of synced 2024-07-03 13:30:46 +12:00

PR comments

This commit is contained in:
Adria Navarro 2024-04-10 15:15:24 +02:00
parent 33bc11750d
commit 3f4d3faeb3
2 changed files with 9 additions and 11 deletions

View file

@ -91,13 +91,13 @@ export const buildAttachmentEndpoints = API => {
/**
* Download an attachment from a row given its column name.
* @param tableId
* @param rowId
* @param columnName the attachments to delete
* @param datasourceId the ID of the datasource to download from
* @param rowId the ID of the row to download from
* @param columnName the column name to download
*/
downloadAttachment: async (tableId, rowId, columnName, options) => {
downloadAttachment: async (datasourceId, rowId, columnName, options) => {
return await API.get({
url: `/api/${tableId}/rows/${rowId}/attachment/${columnName}`,
url: `/api/${datasourceId}/rows/${rowId}/attachment/${columnName}`,
parseResponse: response => response,
suppressErrors: options?.suppressErrors,
})

View file

@ -1,3 +1,5 @@
const extractFileNameRegex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/
export function downloadText(filename, text) {
if (typeof text === "object") {
text = JSON.stringify(text)
@ -17,9 +19,7 @@ export async function downloadStream(streamResponse) {
const contentDisposition = streamResponse.headers.get("Content-Disposition")
const matches = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/.exec(
contentDisposition
)
const matches = extractFileNameRegex.exec(contentDisposition)
const filename = matches[1].replace(/['"]/g, "")
@ -49,9 +49,7 @@ export async function downloadFile(url, body) {
} else {
const contentDisposition = response.headers.get("Content-Disposition")
const matches = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/.exec(
contentDisposition
)
const matches = extractFileNameRegex.exec(contentDisposition)
const filename = matches[1].replace(/['"]/g, "")