const logger = require('winston'); 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}`, }; } module.exports = { serveFile ({ fileName, fileType, filePath }, res) { logger.verbose(`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); }, showFile (fileInfo, res) { const openGraphInfo = createOpenGraphInfo(fileInfo); res.status(200).render('show', { layout: 'show', fileInfo, openGraphInfo }); }, showFileLite (fileInfo, res) { const openGraphInfo = createOpenGraphInfo(fileInfo); res.status(200).render('showLite', { layout: 'showlite', fileInfo, openGraphInfo }); }, };