mirror of
https://github.com/Foltik/Shimapan
synced 2024-11-30 22:41:47 -05:00
Update view.js route
This commit is contained in:
parent
998bd496f0
commit
a395485f09
@ -1,6 +1,7 @@
|
|||||||
const express = require('express');
|
const express = require('express');
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
const config = require('config');
|
const config = require('config');
|
||||||
|
const fs = require('fs');
|
||||||
|
|
||||||
const ModelPath = '../../models/';
|
const ModelPath = '../../models/';
|
||||||
const Upload = require(ModelPath + 'Upload.js');
|
const Upload = require(ModelPath + 'Upload.js');
|
||||||
@ -21,19 +22,16 @@ router.get('/:id', wrap(async (req, res) => {
|
|||||||
await incrementViews(req.params.id);
|
await incrementViews(req.params.id);
|
||||||
|
|
||||||
// Whether the file should be an attachment or displayed inline on the page
|
// Whether the file should be an attachment or displayed inline on the page
|
||||||
let inline = false;
|
const mimetype = upload.file.mime.split('/');
|
||||||
|
|
||||||
const mimetype = upload.file.mimetype.split('/');
|
|
||||||
const inlineMimeTypes = config.get('View.inlineMimeTypes').map(type => type.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)
|
res.status(200);
|
||||||
if (mimetype[0] === type[0])
|
|
||||||
if (mimetype[1] === type[1] || type[1] === '*')
|
|
||||||
inline = true;
|
|
||||||
|
|
||||||
res.set({
|
res.set({
|
||||||
'Content-Disposition': inline ? 'inline' : 'attachment; filename="' + upload.file.originalname + '"',
|
'Content-Disposition': inline ? 'inline' : 'attachment; filename="' + upload.file.originalName + '"',
|
||||||
'Content-Type': upload.file.mimetype
|
'Content-Type': upload.file.mime
|
||||||
});
|
});
|
||||||
|
|
||||||
fs.createReadStream(upload.file.path)
|
fs.createReadStream(upload.file.path)
|
||||||
|
Loading…
Reference in New Issue
Block a user