diff --git a/packages/api/src/controllers/runners.js b/packages/api/src/controllers/runners.js index 957e88647..b87ae7776 100644 --- a/packages/api/src/controllers/runners.js +++ b/packages/api/src/controllers/runners.js @@ -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); } diff --git a/packages/api/src/shell/download.js b/packages/api/src/shell/download.js index bfe9e474b..158d535ab 100644 --- a/packages/api/src/shell/download.js +++ b/packages/api/src/shell/download.js @@ -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; diff --git a/packages/types/extensions.d.ts b/packages/types/extensions.d.ts index 94476a4c4..ad6560e43 100644 --- a/packages/types/extensions.d.ts +++ b/packages/types/extensions.d.ts @@ -1,4 +1,4 @@ -import { EngineDriver } from "./engines"; +import { EngineDriver } from './engines'; export interface FileFormatDefinition { storageType: string; @@ -7,9 +7,10 @@ export interface FileFormatDefinition { readerFunc?: string; writerFunc?: string; args?: any[]; - addFilesToSourceList?: ( + addFileToSourceList?: ( file: { - full: string; + fileName: string; + shortName: string; }, newSources: string[], newValues: { diff --git a/packages/web/src/impexp/ImportExportConfigurator.js b/packages/web/src/impexp/ImportExportConfigurator.js index 9267aa32d..6ab301b16 100644 --- a/packages/web/src/impexp/ImportExportConfigurator.js +++ b/packages/web/src/impexp/ImportExportConfigurator.js @@ -109,12 +109,11 @@ function getFileFilters(extensions, storageType) { return res; } -async function addFilesToSourceListDefault(file, newSources, newValues) { - const sourceName = file.name; +async function addFileToSourceListDefault({ fileName, shortName }, newSources, newValues) { + const sourceName = shortName; newSources.push(sourceName); newValues[`sourceFile_${sourceName}`] = { - fileName: file.full, - downloadUrl: file.url, + fileName, }; } @@ -125,7 +124,7 @@ async function addFilesToSourceList(extensions, files, values, setValues, prefer for (const file of getAsArray(files)) { const format = findFileFormat(extensions, storage); if (format) { - await (format.addFilesToSourceList || addFilesToSourceListDefault)(file, newSources, newValues); + await (format.addFileToSourceList || addFileToSourceListDefault)(file, newSources, newValues); } } newValues['sourceList'] = [...(values.sourceList || []).filter((x) => !newSources.includes(x)), ...newSources]; @@ -159,8 +158,8 @@ function ElectronFilesInput() { await addFilesToSourceList( extensions, files.map((full) => ({ - full, - ...path.parse(full), + fileName: full, + shortName: path.parse(full).name, })), values, setValues @@ -202,8 +201,9 @@ function FilesInput({ setPreviewSource = undefined }) { extensions, [ { - url, - name: extractUrlName(url), + fileName: url, + shortName: extractUrlName(url), + isDownload: true, }, ], values, @@ -385,11 +385,11 @@ function SourceName({ name }) { ); }; const doChangeUrl = (url) => { - setFieldValue(`sourceFile_${name}`, { downloadUrl: url }); + setFieldValue(`sourceFile_${name}`, { fileName: url }); }; const handleChangeUrl = () => { showModal((modalState) => ( - + )); }; @@ -397,7 +397,7 @@ function SourceName({ name }) {
{name}
- {obj && !!obj.downloadUrl && ( + {obj && !!obj.isDownload && ( @@ -427,8 +427,8 @@ export default function ImportExportConfigurator({ uploadedFile = undefined, onC extensions, [ { - full: file.filePath, - name: file.shortName, + fileName: file.filePath, + shortName: file.shortName, }, ], values, diff --git a/packages/web/src/impexp/ScriptWriter.js b/packages/web/src/impexp/ScriptWriter.js index f85dcccfb..f4f6e29b1 100644 --- a/packages/web/src/impexp/ScriptWriter.js +++ b/packages/web/src/impexp/ScriptWriter.js @@ -20,17 +20,7 @@ export default class ScriptWriter { } assign(variableName, functionName, props) { - if (props.downloadUrl) { - const fileNameVar = this.allocVariable(); - this.put(`const ${fileNameVar} = await dbgateApi.download(${JSON.stringify(props.downloadUrl)});`); - this.put( - `const ${variableName} = await ${extractShellApiFunctionName(functionName)}(Object.assign(${JSON.stringify( - _.omit(props, ['downloadUrl']) - )}, { fileName: ${fileNameVar} }));` - ); - } else { - this.put(`const ${variableName} = await ${extractShellApiFunctionName(functionName)}(${JSON.stringify(props)});`); - } + this.put(`const ${variableName} = await ${extractShellApiFunctionName(functionName)}(${JSON.stringify(props)});`); this.packageNames.push(...extractShellApiPlugins(functionName, props)); }