mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-05-03 18:43:58 +00:00
removed fileformatbase
This commit is contained in:
20
packages/types/fileformat.d.ts
vendored
Normal file
20
packages/types/fileformat.d.ts
vendored
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
export interface FileFormatDefinition {
|
||||||
|
storageType: string;
|
||||||
|
extension: string;
|
||||||
|
name: string;
|
||||||
|
readerFunc?: string;
|
||||||
|
writerFunc?: string;
|
||||||
|
args?: any[];
|
||||||
|
addFilesToSourceList: (
|
||||||
|
file: {
|
||||||
|
full: string;
|
||||||
|
},
|
||||||
|
newSources: string[],
|
||||||
|
newValues: {
|
||||||
|
[key: string]: any;
|
||||||
|
}
|
||||||
|
) => void;
|
||||||
|
getDefaultOutputName?: (sourceName, values) => string;
|
||||||
|
getOutputParams?: (sourceName, values) => any;
|
||||||
|
}
|
||||||
|
|
||||||
1
packages/types/index.d.ts
vendored
1
packages/types/index.d.ts
vendored
@@ -39,3 +39,4 @@ export * from './query';
|
|||||||
export * from './dialect';
|
export * from './dialect';
|
||||||
export * from './dumper';
|
export * from './dumper';
|
||||||
export * from './dbtypes';
|
export * from './dbtypes';
|
||||||
|
export * from './fileformat';
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
import fileFormatBase from './fileFormatBase';
|
|
||||||
import { FileFormatDefinition } from './types';
|
import { FileFormatDefinition } from './types';
|
||||||
|
|
||||||
const csvFormat: FileFormatDefinition = {
|
const csvFormat: FileFormatDefinition = {
|
||||||
...fileFormatBase,
|
|
||||||
storageType: 'csv',
|
storageType: 'csv',
|
||||||
extension: 'csv',
|
extension: 'csv',
|
||||||
name: 'CSV',
|
name: 'CSV',
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
import axios from '../utility/axios';
|
import axios from '../utility/axios';
|
||||||
import fileFormatBase from './fileFormatBase';
|
|
||||||
import { FileFormatDefinition } from './types';
|
import { FileFormatDefinition } from './types';
|
||||||
|
|
||||||
const excelFormat: FileFormatDefinition = {
|
const excelFormat: FileFormatDefinition = {
|
||||||
...fileFormatBase,
|
|
||||||
storageType: 'excel',
|
storageType: 'excel',
|
||||||
extension: 'xlsx',
|
extension: 'xlsx',
|
||||||
name: 'MS Excel',
|
name: 'MS Excel',
|
||||||
|
|||||||
@@ -1,11 +0,0 @@
|
|||||||
const fileFormatBase = {
|
|
||||||
addFilesToSourceList: async (file, newSources, newValues) => {
|
|
||||||
const sourceName = file.name;
|
|
||||||
newSources.push(sourceName);
|
|
||||||
newValues[`sourceFile_${sourceName}`] = {
|
|
||||||
fileName: file.full,
|
|
||||||
};
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
export default fileFormatBase;
|
|
||||||
@@ -1,8 +1,6 @@
|
|||||||
import fileFormatBase from './fileFormatBase';
|
|
||||||
import { FileFormatDefinition } from './types';
|
import { FileFormatDefinition } from './types';
|
||||||
|
|
||||||
const jsonlFormat: FileFormatDefinition = {
|
const jsonlFormat: FileFormatDefinition = {
|
||||||
...fileFormatBase,
|
|
||||||
storageType: 'jsonl',
|
storageType: 'jsonl',
|
||||||
extension: 'jsonl',
|
extension: 'jsonl',
|
||||||
name: 'JSON lines',
|
name: 'JSON lines',
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ export interface FileFormatDefinition {
|
|||||||
readerFunc?: string;
|
readerFunc?: string;
|
||||||
writerFunc?: string;
|
writerFunc?: string;
|
||||||
args?: any[];
|
args?: any[];
|
||||||
addFilesToSourceList: (
|
addFilesToSourceList?: (
|
||||||
file: {
|
file: {
|
||||||
full: string;
|
full: string;
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -97,14 +97,22 @@ function getFileFilters(storageType) {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function addFilesToSourceListDefault(file, newSources, newValues) {
|
||||||
|
const sourceName = file.name;
|
||||||
|
newSources.push(sourceName);
|
||||||
|
newValues[`sourceFile_${sourceName}`] = {
|
||||||
|
fileName: file.full,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
async function addFilesToSourceList(files, values, setValues, preferedStorageType, setPreviewSource) {
|
async function addFilesToSourceList(files, values, setValues, preferedStorageType, setPreviewSource) {
|
||||||
const newSources = [];
|
const newSources = [];
|
||||||
const newValues = {};
|
const newValues = {};
|
||||||
const storage = preferedStorageType || values.sourceStorageType;
|
const storage = preferedStorageType || values.sourceStorageType;
|
||||||
for (const file of getAsArray(files)) {
|
for (const file of getAsArray(files)) {
|
||||||
const format = findFileFormat(storage);
|
const format = findFileFormat(storage);
|
||||||
if (format && format.addFilesToSourceList) {
|
if (format) {
|
||||||
await format.addFilesToSourceList(file, newSources, newValues);
|
await (format.addFilesToSourceList || addFilesToSourceListDefault)(file, newSources, newValues);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
newValues['sourceList'] = [...(values.sourceList || []).filter((x) => !newSources.includes(x)), ...newSources];
|
newValues['sourceList'] = [...(values.sourceList || []).filter((x) => !newSources.includes(x)), ...newSources];
|
||||||
|
|||||||
6
packages/web/src/utility/fileformats.js
Normal file
6
packages/web/src/utility/fileformats.js
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
import { usePlugins } from '../plugins/PluginsProvider';
|
||||||
|
|
||||||
|
export function useFileFormats() {
|
||||||
|
const plugins = usePlugins();
|
||||||
|
return [];
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user