download refactor

This commit is contained in:
Jan Prochazka
2020-11-29 21:20:27 +01:00
parent 6d7e7f97c7
commit 7e3555d84a
5 changed files with 26 additions and 41 deletions

View File

@@ -4,9 +4,12 @@ const { uploadsdir } = require('../utility/directories');
const { downloadFile } = require('../utility/downloader');
async function download(url) {
const tmpFile = path.join(uploadsdir(), uuidv1());
await downloadFile(url, tmpFile);
return tmpFile;
if (url && url.match(/(^http:\/\/)|(^https:\/\/)/)) {
const tmpFile = path.join(uploadsdir(), uuidv1());
await downloadFile(url, tmpFile);
return tmpFile;
}
return url;
}
module.exports = download;