parent
d8b07c1843
commit
03d7533e2a
1 changed files with 8 additions and 12 deletions
|
@ -4,6 +4,7 @@ import moment from 'moment';
|
||||||
import isUrl from 'is-url';
|
import isUrl from 'is-url';
|
||||||
import slugify from 'slugify';
|
import slugify from 'slugify';
|
||||||
import jsdom, { serializeDocument } from 'jsdom';
|
import jsdom, { serializeDocument } from 'jsdom';
|
||||||
|
import { resolvePathToFile } from '../utils/filePath';
|
||||||
import generateFileSystemSafeName from '../utils/generateFileSystemSafeName';
|
import generateFileSystemSafeName from '../utils/generateFileSystemSafeName';
|
||||||
import Project from '../models/project';
|
import Project from '../models/project';
|
||||||
import User from '../models/user';
|
import User from '../models/user';
|
||||||
|
@ -159,20 +160,15 @@ export function getProjectAsset(req, res) {
|
||||||
return res.status(404).send({ message: 'Project with that id does not exist' });
|
return res.status(404).send({ message: 'Project with that id does not exist' });
|
||||||
}
|
}
|
||||||
|
|
||||||
let assetURL = null;
|
const filePath = req.params[0];
|
||||||
const seekPath = req.params[0]; // req.params.asset_path;
|
const resolvedFile = resolvePathToFile(filePath, project.files);
|
||||||
const seekPathSplit = seekPath.split('/');
|
if (!resolvedFile) {
|
||||||
const seekFilename = seekPathSplit[seekPathSplit.length - 1];
|
|
||||||
project.files.forEach((file) => {
|
|
||||||
if (file.name === seekFilename) {
|
|
||||||
assetURL = file.url;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!assetURL) {
|
|
||||||
return res.status(404).send({ message: 'Asset does not exist' });
|
return res.status(404).send({ message: 'Asset does not exist' });
|
||||||
}
|
}
|
||||||
request({ method: 'GET', url: assetURL, encoding: null }, (innerErr, response, body) => {
|
if (!resolvedFile.url) {
|
||||||
|
return res.send(resolvedFile.content);
|
||||||
|
}
|
||||||
|
request({ method: 'GET', url: resolvedFile.url, encoding: null }, (innerErr, response, body) => {
|
||||||
if (innerErr) {
|
if (innerErr) {
|
||||||
return res.status(404).send({ message: 'Asset does not exist' });
|
return res.status(404).send({ message: 'Asset does not exist' });
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue