2017-07-17 22:16:11 +02:00
|
|
|
const logger = require('winston');
|
|
|
|
|
2017-08-23 21:21:15 +02:00
|
|
|
function createOpenGraphInfo ({ fileType, claimId, name, fileName, 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/media/${fileName}`,
|
|
|
|
};
|
|
|
|
}
|
2017-08-23 00:50:20 +02:00
|
|
|
|
2017-07-17 22:16:11 +02:00
|
|
|
module.exports = {
|
|
|
|
serveFile ({ fileName, fileType, filePath }, res) {
|
|
|
|
logger.info(`serving file ${fileName}`);
|
|
|
|
// set default options
|
|
|
|
let options = {
|
|
|
|
headers: {
|
|
|
|
'X-Content-Type-Options': 'nosniff',
|
|
|
|
'Content-Type' : fileType,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
// adjust default options as needed
|
|
|
|
switch (fileType) {
|
|
|
|
case 'image/jpeg':
|
|
|
|
case 'image/gif':
|
|
|
|
case 'image/png':
|
|
|
|
case 'video/mp4':
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
logger.warn('sending file with unknown type as .jpeg');
|
|
|
|
options['headers']['Content-Type'] = 'image/jpeg';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// send the file
|
|
|
|
res.status(200).sendFile(filePath, options);
|
|
|
|
},
|
2017-08-02 03:58:13 +02:00
|
|
|
showFile (fileInfo, res) {
|
2017-08-05 02:41:06 +02:00
|
|
|
const openGraphInfo = createOpenGraphInfo(fileInfo);
|
|
|
|
res.status(200).render('show', { layout: 'show', fileInfo, openGraphInfo });
|
2017-08-01 02:02:39 +02:00
|
|
|
},
|
2017-08-02 03:58:13 +02:00
|
|
|
showFileLite (fileInfo, res) {
|
2017-08-05 02:41:06 +02:00
|
|
|
const openGraphInfo = createOpenGraphInfo(fileInfo);
|
|
|
|
res.status(200).render('showLite', { layout: 'show', fileInfo, openGraphInfo });
|
2017-08-01 02:02:39 +02:00
|
|
|
},
|
2017-07-17 22:16:11 +02:00
|
|
|
};
|