1
0
Fork 0
mirror of synced 2024-06-13 07:54:46 +12:00

Download single attachment column

This commit is contained in:
Adria Navarro 2024-04-03 15:33:25 +02:00
parent b44f0a3a36
commit e87c84b0aa
2 changed files with 16 additions and 4 deletions

View file

@ -35,8 +35,8 @@
parameters.tableId && options.find(t => t.resourceId === parameters.tableId)
$: attachmentColumns =
selectedTable &&
Object.values(selectedTable.schema).filter(
c => c.type === FieldType.ATTACHMENT
Object.values(selectedTable.schema).filter(c =>
[FieldType.ATTACHMENTS, FieldType.ATTACHMENT_SINGLE].includes(c.type)
)
onMount(() => {

View file

@ -13,6 +13,7 @@ import {
DeleteRows,
ExportRowsRequest,
ExportRowsResponse,
FieldType,
GetRowResponse,
PatchRowRequest,
PatchRowResponse,
@ -264,11 +265,22 @@ export async function downloadAttachment(ctx: UserCtx) {
const row = await pickApi(tableId).find(ctx)
const table = await sdk.tables.getTable(tableId)
if (!table.schema[columnName]) {
const columnSchema = table.schema[columnName]
if (!columnSchema) {
ctx.throw(400, `'${columnName}' is not valid`)
}
const attachments: RowAttachment[] = row[columnName]
const columnType = columnSchema.type
if (
columnType !== FieldType.ATTACHMENTS &&
columnType !== FieldType.ATTACHMENT_SINGLE
) {
ctx.throw(404, `'${columnName}' is not valid attachment column`)
}
const attachments: RowAttachment[] =
columnType === FieldType.ATTACHMENTS ? row[columnName] : [row[columnName]]
if (!attachments?.length) {
ctx.throw(404)