1
0
Fork 0
mirror of synced 2024-07-09 00:06:05 +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. * Download an attachment from a row given its column name.
* @param tableId * @param datasourceId the ID of the datasource to download from
* @param rowId * @param rowId the ID of the row to download from
* @param columnName the attachments to delete * @param columnName the column name to download
*/ */
downloadAttachment: async (tableId, rowId, columnName, options) => { downloadAttachment: async (datasourceId, rowId, columnName, options) => {
return await API.get({ return await API.get({
url: `/api/${tableId}/rows/${rowId}/attachment/${columnName}`, url: `/api/${datasourceId}/rows/${rowId}/attachment/${columnName}`,
parseResponse: response => response, parseResponse: response => response,
suppressErrors: options?.suppressErrors, suppressErrors: options?.suppressErrors,
}) })

View file

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