Skip to content

Commit

Permalink
Merge #374
Browse files Browse the repository at this point in the history
374: Fix: Pull fileNode file name from airtable metadata r=jbolda a=ryan-talus

This makes the fileNode pull `name` from the airtable
metadata instead of the remote file, because when an airtable
user changes the file name, airtable does not rename the original
file. This change makes file name changes in airtable usable in
the fileNode instead of needing to download, rename, and
re-upload the file.

Co-authored-by: Ryan <[email protected]>
Co-authored-by: Ryan Zimmerman <[email protected]>
  • Loading branch information
3 people authored Apr 15, 2022
2 parents 61eb9fb + fea9711 commit 76e4b11
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .changes/fix-airtable-filenames.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"gatsby-source-airtable": patch
---

This makes the fileNode pull `name` from the airtable metadata instead of the
remote file, because when an airtable user changes the file name, airtable does
not rename the original url. This change makes file name changes in airtable
usable in the fileNode instead of needing to download, rename, and re-upload the
file.
4 changes: 4 additions & 0 deletions gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const crypto = require("crypto");
const { createRemoteFileNode } = require("gatsby-source-filesystem");
const { map } = require("bluebird");
const mime = require("mime/lite");
const path = require("path");

exports.sourceNodes = async (
{ actions, createNodeId, store, cache },
Expand Down Expand Up @@ -305,8 +306,11 @@ const localFileCheck = async (
// the cleanKey here
data[key].forEach((attachment) => {
const ext = mime.getExtension(attachment.type); // unknown type returns null
// get the filename from the airtable metadata instead of the remote file
const airtableFileName = path.parse(attachment.filename).name;
let attachmentNode = createRemoteFileNode({
url: attachment.url,
name: airtableFileName,
store,
cache,
createNode,
Expand Down

0 comments on commit 76e4b11

Please sign in to comment.