mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 18:26:00 +00:00
download refactor
This commit is contained in:
@@ -38,16 +38,7 @@ const dbgateApi = require(process.env.DBGATE_API);
|
||||
${requirePluginsTemplate(extractShellApiPlugins(functionName, props))}
|
||||
require=null;
|
||||
async function run() {
|
||||
${
|
||||
props.downloadUrl
|
||||
? `
|
||||
const downloaded=await dbgateApi.download(${JSON.stringify(props.downloadUrl)});
|
||||
const reader=await ${extractShellApiFunctionName(functionName)}(Object.assign(${JSON.stringify(
|
||||
_.omit(props, ['downloadUrl'])
|
||||
)}, { fileName: downloaded }));
|
||||
`
|
||||
: `const reader=await ${extractShellApiFunctionName(functionName)}(${JSON.stringify(props)});`
|
||||
}
|
||||
const reader=await ${extractShellApiFunctionName(functionName)}(${JSON.stringify(props)});
|
||||
const writer=await dbgateApi.collectorWriter({runid: '${runid}'});
|
||||
await dbgateApi.copyStream(reader, writer);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user