Handle single files on imports
This commit is contained in:
parent
e5843929f1
commit
6928e7454c
|
@ -5,6 +5,7 @@ import {
|
|||
Automation,
|
||||
AutomationTriggerStepId,
|
||||
RowAttachment,
|
||||
FieldType,
|
||||
} from "@budibase/types"
|
||||
import { getAutomationParams } from "../../../db/utils"
|
||||
import { budibaseTempDir } from "../../../utilities/budibaseDir"
|
||||
|
@ -58,10 +59,19 @@ export async function updateAttachmentColumns(prodAppId: string, db: Database) {
|
|||
updatedRows = updatedRows.concat(
|
||||
rows.map(row => {
|
||||
for (let column of columns) {
|
||||
if (Array.isArray(row[column])) {
|
||||
const columnType = table.schema[column].type
|
||||
if (
|
||||
columnType === FieldType.ATTACHMENTS &&
|
||||
Array.isArray(row[column])
|
||||
) {
|
||||
row[column] = row[column].map((attachment: RowAttachment) =>
|
||||
rewriteAttachmentUrl(prodAppId, attachment)
|
||||
)
|
||||
} else if (
|
||||
columnType === FieldType.ATTACHMENT_SINGLE &&
|
||||
row[column]
|
||||
) {
|
||||
row[column] = rewriteAttachmentUrl(prodAppId, row[column])
|
||||
}
|
||||
}
|
||||
return row
|
||||
|
|
|
@ -30,7 +30,10 @@ export async function getRowsWithAttachments(appId: string, table: Table) {
|
|||
const db = dbCore.getDB(appId)
|
||||
const attachmentCols: string[] = []
|
||||
for (let [key, column] of Object.entries(table.schema)) {
|
||||
if (column.type === FieldType.ATTACHMENTS) {
|
||||
if (
|
||||
column.type === FieldType.ATTACHMENTS ||
|
||||
column.type === FieldType.ATTACHMENT_SINGLE
|
||||
) {
|
||||
attachmentCols.push(key)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,9 +31,13 @@ describe("should be able to re-write attachment URLs", () => {
|
|||
sourceType: TableSourceType.INTERNAL,
|
||||
schema: {
|
||||
photo: {
|
||||
type: FieldType.ATTACHMENTS,
|
||||
type: FieldType.ATTACHMENT_SINGLE,
|
||||
name: "photo",
|
||||
},
|
||||
gallery: {
|
||||
type: FieldType.ATTACHMENTS,
|
||||
name: "gallery",
|
||||
},
|
||||
otherCol: {
|
||||
type: FieldType.STRING,
|
||||
name: "otherCol",
|
||||
|
@ -43,7 +47,8 @@ describe("should be able to re-write attachment URLs", () => {
|
|||
|
||||
for (let i = 0; i < FIND_LIMIT * 4; i++) {
|
||||
await config.api.row.save(table._id!, {
|
||||
photo: [attachment],
|
||||
photo: { ...attachment },
|
||||
gallery: [{ ...attachment }, { ...attachment }],
|
||||
otherCol: "string",
|
||||
})
|
||||
}
|
||||
|
@ -56,8 +61,12 @@ describe("should be able to re-write attachment URLs", () => {
|
|||
)
|
||||
for (const row of rows) {
|
||||
expect(row.otherCol).toBe("string")
|
||||
expect(row.photo[0].url).toBe("")
|
||||
expect(row.photo[0].key).toBe(`${db.name}/attachments/a.png`)
|
||||
expect(row.photo.url).toBe("")
|
||||
expect(row.photo.key).toBe(`${db.name}/attachments/a.png`)
|
||||
expect(row.gallery[0].url).toBe("")
|
||||
expect(row.gallery[0].key).toBe(`${db.name}/attachments/a.png`)
|
||||
expect(row.gallery[1].url).toBe("")
|
||||
expect(row.gallery[1].key).toBe(`${db.name}/attachments/a.png`)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue