Fixing an issue with app import - old attachments which have an invalid state can cause the app to fail to import.

This commit is contained in:
mike12345567 2024-08-15 14:25:36 +01:00
parent 0109fce51d
commit e32409da15
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) { if (attachments.length === 1) {
const attachment = attachments[0] const attachment = attachments[0]
ctx.attachment(attachment.name) ctx.attachment(attachment.name)
ctx.body = await objectStore.getReadStream( if (attachment.key) {
objectStore.ObjectStoreBuckets.APPS, ctx.body = await objectStore.getReadStream(
attachment.key objectStore.ObjectStoreBuckets.APPS,
) attachment.key
)
}
} else { } else {
const passThrough = new stream.PassThrough() const passThrough = new stream.PassThrough()
const archive = archiver.create("zip") const archive = archiver.create("zip")
archive.pipe(passThrough) archive.pipe(passThrough)
for (const attachment of attachments) { for (const attachment of attachments) {
if (!attachment.key) {
continue
}
const attachmentStream = await objectStore.getReadStream( const attachmentStream = await objectStore.getReadStream(
objectStore.ObjectStoreBuckets.APPS, objectStore.ObjectStoreBuckets.APPS,
attachment.key attachment.key

View File

@ -34,7 +34,7 @@ type TemplateType = {
function rewriteAttachmentUrl(appId: string, attachment: RowAttachment) { function rewriteAttachmentUrl(appId: string, attachment: RowAttachment) {
// URL looks like: /prod-budi-app-assets/appId/attachments/file.csv // 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 // remove the app ID
urlParts.shift() urlParts.shift()
// add new app ID // add new app ID

View File

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

View File

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