Set content type of assets based on name
This commit is contained in:
parent
14a4425dc2
commit
dc20a7238f
1 changed files with 6 additions and 0 deletions
|
@ -9,6 +9,7 @@ import Project from '../models/project';
|
||||||
import User from '../models/user';
|
import User from '../models/user';
|
||||||
import { resolvePathToFile } from '../utils/filePath';
|
import { resolvePathToFile } from '../utils/filePath';
|
||||||
import generateFileSystemSafeName from '../utils/generateFileSystemSafeName';
|
import generateFileSystemSafeName from '../utils/generateFileSystemSafeName';
|
||||||
|
import mime from 'mime-types';
|
||||||
|
|
||||||
export { default as createProject, apiCreateProject } from './project.controller/createProject';
|
export { default as createProject, apiCreateProject } from './project.controller/createProject';
|
||||||
export { default as deleteProject } from './project.controller/deleteProject';
|
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' });
|
return res.status(404).send({ message: 'Asset does not exist' });
|
||||||
}
|
}
|
||||||
if (!resolvedFile.url) {
|
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);
|
return res.send(resolvedFile.content);
|
||||||
}
|
}
|
||||||
request({ method: 'GET', url: resolvedFile.url, encoding: null }, (innerErr, response, body) => {
|
request({ method: 'GET', url: resolvedFile.url, encoding: null }, (innerErr, response, body) => {
|
||||||
|
|
Loading…
Reference in a new issue