mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-21 00:06:01 +00:00
SYNC: Merge pull request #3 from dbgate/feature/zip
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
import { getConnectionLabel } from 'dbgate-tools';
|
||||
|
||||
export let allowChooseModel = false;
|
||||
export let direction;
|
||||
export let direction = 'source';
|
||||
|
||||
$: connections = useConnectionList();
|
||||
$: connectionOptions = [
|
||||
|
||||
@@ -25,6 +25,9 @@
|
||||
import { _t } from '../translations';
|
||||
import { showModal } from '../modals/modalTools';
|
||||
import InputTextModal from '../modals/InputTextModal.svelte';
|
||||
import FormCheckboxField from '../forms/FormCheckboxField.svelte';
|
||||
import { isProApp } from '../utility/proTools';
|
||||
import FormTextField from '../forms/FormTextField.svelte';
|
||||
|
||||
export let direction;
|
||||
export let storageTypeField;
|
||||
@@ -133,6 +136,41 @@
|
||||
label="Storage type"
|
||||
/>
|
||||
|
||||
{#if format && isProApp()}
|
||||
{#if direction == 'source'}
|
||||
<FormCheckboxField
|
||||
name={`importFromZipFile`}
|
||||
label={_t('importExport.importFromZipFile', { defaultMessage: 'Import from ZIP file (in archive folder)' })}
|
||||
/>
|
||||
{#if $values.importFromZipFile}
|
||||
<FormArchiveFolderSelect
|
||||
label={_t('importExport.importFromZipArchive', { defaultMessage: 'Input ZIP archive' })}
|
||||
name={archiveFolderField}
|
||||
additionalFolders={_.compact([$values[archiveFolderField]])}
|
||||
zipFilesOnly
|
||||
/>
|
||||
{/if}
|
||||
{/if}
|
||||
{#if direction == 'target'}
|
||||
<FormCheckboxField
|
||||
name={`exportToZipFile`}
|
||||
label={_t('importExport.exportToZipFile', { defaultMessage: 'Export to ZIP file' })}
|
||||
/>
|
||||
{#if $values.exportToZipFile}
|
||||
<FormCheckboxField
|
||||
name={`createZipFileInArchive`}
|
||||
label={_t('importExport.createZipFileInArchive', { defaultMessage: 'Create ZIP file in archive' })}
|
||||
/>
|
||||
|
||||
<FormTextField
|
||||
label={_t('importExport.exportToZipArchive', { defaultMessage: 'Output ZIP archive' })}
|
||||
name={archiveFolderField}
|
||||
placeholder={'zip-archive-yyyy-mm-dd-hh-mm-ss.zip'}
|
||||
/>
|
||||
{/if}
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
{#if storageType == 'database' || storageType == 'query'}
|
||||
<FormConnectionSelect name={connectionIdField} label="Server" {direction} />
|
||||
<FormDatabaseSelect conidName={connectionIdField} name={databaseNameField} label="Database" />
|
||||
@@ -173,18 +211,20 @@
|
||||
label="Archive folder"
|
||||
name={archiveFolderField}
|
||||
additionalFolders={_.compact([$values[archiveFolderField]])}
|
||||
allowCreateNew={direction == 'target'}
|
||||
/>
|
||||
{/if}
|
||||
|
||||
{#if storageType == 'archive' && direction == 'source'}
|
||||
{#if direction == 'source' && (storageType == 'archive' || $values.importFromZipFile)}
|
||||
<FormArchiveFilesSelect
|
||||
label={_t('importExport.sourceFiles', { defaultMessage: 'Source files' })}
|
||||
folderName={$values[archiveFolderField]}
|
||||
name={tablesField}
|
||||
filterExtension={format?.extension}
|
||||
/>
|
||||
{/if}
|
||||
|
||||
{#if format && direction == 'source'}
|
||||
{#if format && direction == 'source' && !$values.importFromZipFile}
|
||||
<FilesInput {setPreviewSource} />
|
||||
{/if}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import _ from 'lodash';
|
||||
import moment from 'moment';
|
||||
import { ScriptWriter, ScriptWriterJson } from 'dbgate-tools';
|
||||
import getAsArray from '../utility/getAsArray';
|
||||
import { getConnectionInfo } from '../utility/metadataLoaders';
|
||||
@@ -93,7 +94,13 @@ function getSourceExpr(extensions, sourceName, values, sourceConnection, sourceD
|
||||
return [
|
||||
format.readerFunc,
|
||||
{
|
||||
..._.omit(sourceFile, ['isDownload']),
|
||||
...(sourceFile
|
||||
? _.omit(sourceFile, ['isDownload'])
|
||||
: {
|
||||
fileName: values.importFromZipFile
|
||||
? `zip://archive:${values.sourceArchiveFolder}//${sourceName}`
|
||||
: sourceName,
|
||||
}),
|
||||
...extractFormatApiParameters(values, 'source', format),
|
||||
},
|
||||
];
|
||||
@@ -237,6 +244,13 @@ export default async function createImpExpScript(extensions, values, forceScript
|
||||
script.copyStream(sourceVar, targetVar, colmapVar, sourceName);
|
||||
script.endLine();
|
||||
}
|
||||
|
||||
if (values.exportToZipFile) {
|
||||
let zipFileName = values.exportToZipFileName || `zip-archive-${moment().format('YYYY-MM-DD-HH-mm-ss')}.zip`;
|
||||
if (!zipFileName.endsWith('.zip')) zipFileName += '.zip';
|
||||
script.zipDirectory('.', values.createZipFileInArchive ? 'archive:' + zipFileName : zipFileName);
|
||||
}
|
||||
|
||||
return script.getScript(values.schedule);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user