2017-07-17 22:16:11 +02:00
|
|
|
const logger = require('winston');
|
2017-11-21 21:53:43 +01:00
|
|
|
// const { postToStats, sendGoogleAnalytics } = require('../controllers/statsController.js');
|
2017-07-17 22:16:11 +02:00
|
|
|
|
|
|
|
module.exports = {
|
2017-11-27 23:35:29 +01:00
|
|
|
serveFile ({ filePath }, { claimId, name, contentType }, res) {
|
2017-11-21 21:53:43 +01:00
|
|
|
logger.verbose(`serving ${name}#${claimId}`);
|
|
|
|
// set response options
|
|
|
|
const headerContentType = contentType || 'image/jpeg';
|
|
|
|
const options = {
|
2017-07-17 22:16:11 +02:00
|
|
|
headers: {
|
|
|
|
'X-Content-Type-Options': 'nosniff',
|
2017-11-21 21:53:43 +01:00
|
|
|
'Content-Type' : headerContentType,
|
2017-07-17 22:16:11 +02:00
|
|
|
},
|
|
|
|
};
|
|
|
|
// send the file
|
2017-11-21 21:53:43 +01:00
|
|
|
if (filePath) {
|
|
|
|
res.status(200).sendFile(filePath, options);
|
|
|
|
} else {
|
2017-11-22 00:44:27 +01:00
|
|
|
// res.status(307).redirect(`/api/get/${name}/${claimId}`);
|
|
|
|
res.status(400).json({success: false, message: 'that claim is not hosted locally by Spee<ch yet'});
|
2017-11-21 21:53:43 +01:00
|
|
|
}
|
2017-07-17 22:16:11 +02:00
|
|
|
},
|
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-08-01 02:02:39 +02:00
|
|
|
},
|
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 });
|
2017-08-01 02:02:39 +02:00
|
|
|
},
|
2017-11-27 23:54:53 +01:00
|
|
|
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}`,
|
|
|
|
};
|
|
|
|
},
|
2017-07-17 22:16:11 +02:00
|
|
|
};
|