Set content type of assets based on name

This commit is contained in:
Ruben van de Ven 2020-10-25 12:56:07 +01:00
parent 14a4425dc2
commit dc20a7238f

View file

@ -9,6 +9,7 @@ import Project from '../models/project';
import User from '../models/user';
import { resolvePathToFile } from '../utils/filePath';
import generateFileSystemSafeName from '../utils/generateFileSystemSafeName';
import mime from 'mime-types';
export { default as createProject, apiCreateProject } from './project.controller/createProject';
export { default as deleteProject } from './project.controller/deleteProject';
@ -112,6 +113,11 @@ export function getProjectAsset(req, res) {
return res.status(404).send({ message: 'Asset does not exist' });
}
if (!resolvedFile.url) {
// set the content type based on the filename
const mimetype = mime.lookup(resolvedFile.name);
if(mimetype) {
res.type(mimetype);
}
return res.send(resolvedFile.content);
}
request({ method: 'GET', url: resolvedFile.url, encoding: null }, (innerErr, response, body) => {