Skip to content

Commit

Permalink
Add image file type validation
Browse files Browse the repository at this point in the history
  • Loading branch information
kylmp committed Aug 1, 2022
1 parent 42cc12d commit 23eaea4
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ photo-metadata-updater/
photo-metadata-updater.zip
build.sh
readme.txt
exiftool/
exiftool/
releases/
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Node.js application with a Vue frontend. Runs on Mac/Unix systems, not tested on

# Recommended Dependency

In order to take advantage of timezone and map features, you need a [Bing maps API key](https://docs.microsoft.com/en-us/bingmaps/getting-started/bing-maps-dev-center-help/getting-a-bing-maps-key). Go to the link to get one, then save it in the app after startup.
In order to take advantage of timezone and map features, you need a [Bing maps API key](https://docs.microsoft.com/en-us/bingmaps/getting-started/bing-maps-dev-center-help/getting-a-bing-maps-key).

# Run App Guide

Expand Down
3 changes: 2 additions & 1 deletion photo-metadata-updater.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ if (bingApiKey === 'YOUR_BING_API_KEY') {
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(express.static(path.join(__dirname, './public')));
app.use('/api', require('./src/middleware/routes'));
app.use('/api', require('./src/middleware/api-routes'));
app.use('/img', require('./src/middleware/image-validator'));
app.use('/img', require('./src/middleware/image-folder'));

server = app.listen(port, () => {
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions src/middleware/image-folder.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
var express = require('express');

var imgFolder = createImgFolder('/Users/testing/photo-metadata-updater/photos');
var imgFolder = createImgFolder();

function createImgFolder (path) {
var static = express.static(path);
function createImgFolder() {
var static = express.static((process.pkg) ? process.cwd() : __dirname);

const imgFolder = function (req, res, next) {
return static(req, res, next);
Expand Down
9 changes: 9 additions & 0 deletions src/middleware/image-validator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var router = require('express').Router();

const allowedTypesRegex = /^.*\.(jpg|JPG|jpeg|JPEG|png|PNG)$/;

router.get('/*', function (req, res, next) {
(allowedTypesRegex.test(req.url)) ? next() : res.status(400).send('Invalid photo extenstion type');
});

module.exports = router;

0 comments on commit 23eaea4

Please sign in to comment.