spee.ch/helpers/serveHelpers.js

27 lines
1,001 B
JavaScript
Raw Normal View History

const logger = require('winston');
2017-11-21 21:53:43 +01:00
// const { postToStats, sendGoogleAnalytics } = require('../controllers/statsController.js');
module.exports = {
2017-11-28 00:57:20 +01:00
serveFile ({ filePath, fileType }, claimId, name, res) {
2017-11-21 21:53:43 +01:00
logger.verbose(`serving ${name}#${claimId}`);
// set response options
2017-11-28 00:57:20 +01:00
const headerContentType = fileType || 'image/jpeg';
2017-11-21 21:53:43 +01:00
const options = {
headers: {
'X-Content-Type-Options': 'nosniff',
2017-11-21 21:53:43 +01:00
'Content-Type' : headerContentType,
},
};
// send the file
res.status(200).sendFile(filePath, options);
},
2017-11-27 23:35:29 +01:00
showFile (claimInfo, shortId, res) {
2017-11-27 23:54:53 +01:00
const openGraphInfo = module.exports.createOpenGraphInfo(claimInfo);
2017-11-21 21:53:43 +01:00
res.status(200).render('show', { layout: 'show', claimInfo, shortId, openGraphInfo });
},
2017-11-27 23:35:29 +01:00
showFileLite (claimInfo, shortId, res) {
2017-11-27 23:54:53 +01:00
const openGraphInfo = module.exports.createOpenGraphInfo(claimInfo);
2017-11-21 21:53:43 +01:00
res.status(200).render('showLite', { layout: 'showlite', claimInfo, shortId, openGraphInfo });
},
};