spee.ch/helpers/serveHelpers.js
2017-11-27 16:53:32 -08:00

34 lines
1.3 KiB
JavaScript

const logger = require('winston');
// const { postToStats, sendGoogleAnalytics } = require('../controllers/statsController.js');
module.exports = {
serveFile ({ filePath, fileType }, claimId, name, res) {
logger.verbose(`serving ${name}#${claimId}`);
// set response options
const headerContentType = fileType || 'image/jpeg';
const options = {
headers: {
'X-Content-Type-Options': 'nosniff',
'Content-Type' : headerContentType,
},
};
// send the file
res.status(200).sendFile(filePath, options);
},
showFile (claimInfo, shortId, res) {
const openGraphInfo = module.exports.createOpenGraphInfo(claimInfo);
res.status(200).render('show', { layout: 'show', claimInfo, shortId, openGraphInfo });
},
showFileLite (claimInfo, shortId, res) {
const openGraphInfo = module.exports.createOpenGraphInfo(claimInfo);
res.status(200).render('showLite', { layout: 'showlite', claimInfo, shortId, openGraphInfo });
},
createOpenGraphInfo ({ claimId, name, fileExt }) {
return {
embedUrl : `https://spee.ch/embed/${claimId}/${name}`,
showUrl : `https://spee.ch/${claimId}/${name}`,
source : `https://spee.ch/${claimId}/${name}.${fileExt}`,
directFileUrl: `https://spee.ch/${claimId}/${name}.${fileExt}`,
};
},
};