Skip to content

Commit

Permalink
Merge pull request #150 from JJ1898/airtable-image-fix
Browse files Browse the repository at this point in the history
Add new Airtable CDN domain to the whitelist and open some logic
  • Loading branch information
slmnio authored Nov 8, 2022
2 parents 2e65f75 + bdede3d commit 2e508ec
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions server/src/images.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ module.exports = ({ app, cors, Cache, corsHandle }) => {
const originalFileType = dots[dots.length - 1]; // last . (now works with .svg.png)
const filename = parts[4] + "." + originalFileType;

if (!["dl.airtable.com", "media.slmn.io"].some(domain => domain === parts[2])) {
if (!["dl.airtable.com", "media.slmn.io", "v5.airtableusercontent.com"].some(domain => domain === parts[2])) {
return res.status(400).send("Domain not whitelisted");
}

Expand Down Expand Up @@ -194,7 +194,7 @@ module.exports = ({ app, cors, Cache, corsHandle }) => {
};
}

if (["svg", "gif"].includes(originalFileType)) {
if (!size /*["svg", "gif"].includes(originalFileType)*/) { // TODO: load image first then detect filetype
// just do orig if svg
size = "orig";
}
Expand All @@ -205,7 +205,11 @@ module.exports = ({ app, cors, Cache, corsHandle }) => {

let imagePath = await getImage(filename, size);

if (imagePath) return res.sendFile(imagePath);
if (imagePath) {
// let metaFileType = (await sharp(imagePath).metadata())?.format;
// console.log({metaFileType});
return res.sendFile(imagePath);
}
console.log("[image]", `no file for ${originalFilename} @ ${size}`);
// no image

Expand All @@ -222,6 +226,9 @@ module.exports = ({ app, cors, Cache, corsHandle }) => {
if (size === "orig") return res.sendFile(orig);
}

// let metaFileType = (await sharp(orig).metadata())?.format;
// console.log({metaFileType});

// resize time!
// console.log("[image]", `resizing ${originalFilename} @ ${size}`);
const t = Date.now();
Expand Down

0 comments on commit 2e508ec

Please sign in to comment.