Skip to content

Commit

Permalink
Updated GET endpoint for images to use path.parse to get filename &…
Browse files Browse the repository at this point in the history
… extension.
  • Loading branch information
Irwin Razaghi committed Mar 21, 2020
1 parent 81c5958 commit 7d71dcd
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/images/src/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export class ImageService {

this.app.get('/image/:filename', async (req, res) => {
const { filename } = req.params;
const [id, format] = filename.split('.');
const { name: id, ext: format } = nodePath.parse(filename);

if (!id || !format) {
return res.status(404).send('Not Found (Invalid Filename)');
Expand All @@ -93,10 +93,10 @@ export class ImageService {
return res.status(404).send('Not Found (No Matching Image)');
}

const originalPath = nodePath.join(this.sourcePath, `${id}.${data.format}`);
const originalPath = nodePath.join(this.sourcePath, `${id}${data.format}`);
const resizeOptions = processResizeOptions(req.query);

if (!resizeOptions && format === data.format) {
if (!resizeOptions && format === `.${data.format}`) {
return res.sendFile(originalPath);
}

Expand All @@ -114,7 +114,7 @@ export class ImageService {
suffix = `-${hash}`;
}

let transformedFilename = nodePath.join(this.transformsPath, `${id}${suffix}.${format}`);
let transformedFilename = nodePath.join(this.transformsPath, `${id}${suffix}${format}`);

// If a cached copy of the transformed file exists, don't re-create it
if (await fs.exists(transformedFilename)) {
Expand Down

0 comments on commit 7d71dcd

Please sign in to comment.