Merge pull request #14385 from Budibase/fix/14375

App import issue (invalid attachments)
This commit is contained in:
Michael Drury 2024-08-15 14:48:18 +01:00 committed by GitHub
commit 5e35e633c0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 13 additions and 8 deletions

View File

@ -308,16 +308,21 @@ export async function downloadAttachment(ctx: UserCtx) {
if (attachments.length === 1) {
const attachment = attachments[0]
ctx.attachment(attachment.name)
ctx.body = await objectStore.getReadStream(
objectStore.ObjectStoreBuckets.APPS,
attachment.key
)
if (attachment.key) {
ctx.body = await objectStore.getReadStream(
objectStore.ObjectStoreBuckets.APPS,
attachment.key
)
}
} else {
const passThrough = new stream.PassThrough()
const archive = archiver.create("zip")
archive.pipe(passThrough)
for (const attachment of attachments) {
if (!attachment.key) {
continue
}
const attachmentStream = await objectStore.getReadStream(
objectStore.ObjectStoreBuckets.APPS,
attachment.key

View File

@ -34,7 +34,7 @@ type TemplateType = {
function rewriteAttachmentUrl(appId: string, attachment: RowAttachment) {
// URL looks like: /prod-budi-app-assets/appId/attachments/file.csv
const urlParts = attachment.key.split("/")
const urlParts = attachment.key?.split("/") || []
// remove the app ID
urlParts.shift()
// add new app ID

View File

@ -44,8 +44,8 @@ export class AttachmentCleanup {
if (type === FieldType.ATTACHMENTS && Array.isArray(rowData)) {
return rowData
.filter(attachment => attachment.key)
.map(attachment => attachment.key)
} else if ("key" in rowData) {
.map(attachment => attachment.key!)
} else if ("key" in rowData && rowData.key) {
return [rowData.key]
}

View File

@ -131,7 +131,7 @@ export interface RowAttachment {
size: number
name: string
extension: string
key: string
key?: string
// Populated on read
url?: string
}