From a395485f093638989c626f5db6e7e1d4a8b0ed62 Mon Sep 17 00:00:00 2001 From: Jack Foltz Date: Wed, 1 Aug 2018 20:25:00 -0400 Subject: [PATCH] Update view.js route --- app/routes/api/view.js | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/app/routes/api/view.js b/app/routes/api/view.js index 4462e35..d6e99e0 100644 --- a/app/routes/api/view.js +++ b/app/routes/api/view.js @@ -1,6 +1,7 @@ const express = require('express'); const router = express.Router(); const config = require('config'); +const fs = require('fs'); const ModelPath = '../../models/'; const Upload = require(ModelPath + 'Upload.js'); @@ -21,19 +22,16 @@ router.get('/:id', wrap(async (req, res) => { await incrementViews(req.params.id); // Whether the file should be an attachment or displayed inline on the page - let inline = false; - - const mimetype = upload.file.mimetype.split('/'); + const mimetype = upload.file.mime.split('/'); const inlineMimeTypes = config.get('View.inlineMimeTypes').map(type => type.split('/')); + let inline = inlineMimeTypes.some(type => + (mimetype[0] === type[0] || type[0] === '*') && + (mimetype[1] === type[1] || type[1] === '*')); - for (let type in inlineMimeTypes) - if (mimetype[0] === type[0]) - if (mimetype[1] === type[1] || type[1] === '*') - inline = true; - + res.status(200); res.set({ - 'Content-Disposition': inline ? 'inline' : 'attachment; filename="' + upload.file.originalname + '"', - 'Content-Type': upload.file.mimetype + 'Content-Disposition': inline ? 'inline' : 'attachment; filename="' + upload.file.originalName + '"', + 'Content-Type': upload.file.mime }); fs.createReadStream(upload.file.path)