diff --git a/src/modules/core/airtable/sanitizeRawAirtableDS.ts b/src/modules/core/airtable/sanitizeRawAirtableDS.ts index 90622f06..6239c80b 100644 --- a/src/modules/core/airtable/sanitizeRawAirtableDS.ts +++ b/src/modules/core/airtable/sanitizeRawAirtableDS.ts @@ -281,10 +281,17 @@ export const sanitizeRawAirtableDS = (airtableSchema: AirtableSchema, airtableDa delete attachmentFields?.['id']; // Delete the id field so that it won't override the record id (it'll still be available as "attachmentId") delete sanitizedRecord[tableSchema?.attachmentFieldName]; // Delete the attachment altogether to avoid noise (all props will be copied to the sanitized record) - // Add the native Airtable attachment fields + // Add the native Airtable attachment fields as properties of the record map(attachmentFields, (attachmentFieldValue: any, attachmentFieldName: string) => { - sanitizedRecord[attachmentFieldName] = attachmentFieldValue; + // Except for width/height which shouldn't be + if (attachmentFieldName !== 'width' && attachmentFieldName !== 'height') { + sanitizedRecord[attachmentFieldName] = attachmentFieldValue; + } }); + + // Copy auto-detected width/height properties using aliases (they represent the dimensions of the uploaded/origin attachment, not the dimensions it's meant to be resized to on the screen) + sanitizedRecord['attachmentWidth'] = attachmentFields?.width; + sanitizedRecord['attachmentHeight'] = attachmentFields?.height; } else { // When there is no attachment in the attachment field, then do nothing } diff --git a/src/modules/core/airtable/types/RawAirtableAttachmentBaseFields.ts b/src/modules/core/airtable/types/RawAirtableAttachmentBaseFields.ts index 81c4cafc..ba86350d 100644 --- a/src/modules/core/airtable/types/RawAirtableAttachmentBaseFields.ts +++ b/src/modules/core/airtable/types/RawAirtableAttachmentBaseFields.ts @@ -8,6 +8,8 @@ import { RawAirtableAttachmentThumbnails } from './RawAirtableAttachmentThumbnai export type RawAirtableAttachmentBaseFields = { id: string; url: string; + width: number; + height: number; filename: string; size?: number; // TODO Not sure if it's always present, gotta confirm behaviour type: string; diff --git a/src/modules/core/data/types/AirtableAttachment.ts b/src/modules/core/data/types/AirtableAttachment.ts index 94056916..856c2a4b 100644 --- a/src/modules/core/data/types/AirtableAttachment.ts +++ b/src/modules/core/data/types/AirtableAttachment.ts @@ -8,5 +8,7 @@ import { AirtableRecordBaseFields } from './AirtableRecordBaseFields'; */ export type AirtableAttachment = { attachmentId: string; // The airtable attachment id, can't be stored as "id" because it's already taken by the Asset record id + attachmentWidth: number; // The airtable attachment original width, as it was detected by Airtable when the file was first uploaded to their service + attachmentHeight: number; // The airtable attachment original height, as it was detected by Airtable when the file was first uploaded to their service } & Omit & AirtableRecordBaseFields;