Skip to content

Commit

Permalink
Adapt Airtable sanitizer due to a recent change in the Airtable REST …
Browse files Browse the repository at this point in the history
…API (which now returns width/height for all attachments, which broke our dynamic property lookup by overriding our own width/height props)
  • Loading branch information
Vadorequest committed Aug 24, 2021
1 parent 003ea51 commit 1da6db3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/modules/core/airtable/sanitizeRawAirtableDS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/modules/core/data/types/AirtableAttachment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<RawAirtableAttachment, 'id'>
& AirtableRecordBaseFields;

0 comments on commit 1da6db3

Please sign in to comment.