diff --git a/packages/api/src/controllers/uploads.js b/packages/api/src/controllers/uploads.js index 54407d4da..fc48f9b8d 100644 --- a/packages/api/src/controllers/uploads.js +++ b/packages/api/src/controllers/uploads.js @@ -2,20 +2,20 @@ const path = require('path'); const { uploadsdir } = require('../utility/directories'); const uuidv1 = require('uuid/v1'); -const extensions = [ - { - ext: '.xlsx', - type: 'excel', - }, - { - ext: '.jsonl', - type: 'jsonl', - }, - { - ext: '.csv', - type: 'csv', - }, -]; +// const extensions = [ +// { +// ext: '.xlsx', +// type: 'excel', +// }, +// { +// ext: '.jsonl', +// type: 'jsonl', +// }, +// { +// ext: '.csv', +// type: 'csv', +// }, +// ]; module.exports = { upload_meta: { @@ -31,19 +31,19 @@ module.exports = { const uploadName = uuidv1(); const filePath = path.join(uploadsdir(), uploadName); console.log(`Uploading file ${data.name}, size=${data.size}`); - let storageType = null; - let shortName = data.name; - for (const { ext, type } of extensions) { - if (data.name.endsWith(ext)) { - storageType = type; - shortName = data.name.slice(0, -ext.length); - } - } + // let storageType = null; + // let shortName = data.name; + // for (const { ext, type } of extensions) { + // if (data.name.endsWith(ext)) { + // storageType = type; + // shortName = data.name.slice(0, -ext.length); + // } + // } data.mv(filePath, () => { res.json({ originalName: data.name, - shortName, - storageType, + // shortName, + // storageType, uploadName, filePath, }); diff --git a/packages/types/extensions.d.ts b/packages/types/extensions.d.ts new file mode 100644 index 000000000..5bd430ddb --- /dev/null +++ b/packages/types/extensions.d.ts @@ -0,0 +1,30 @@ +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; +} + +export interface PluginDefinition { + packageName: string; + manifest: any; + content: any; +} + +export interface ExtensionsDirectory { + plugins: PluginDefinition[]; + fileFormats: FileFormatDefinition[]; +} diff --git a/packages/types/fileformat.d.ts b/packages/types/fileformat.d.ts deleted file mode 100644 index ccc569085..000000000 --- a/packages/types/fileformat.d.ts +++ /dev/null @@ -1,20 +0,0 @@ -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; - } - \ No newline at end of file diff --git a/packages/types/index.d.ts b/packages/types/index.d.ts index 12530325e..6134439fb 100644 --- a/packages/types/index.d.ts +++ b/packages/types/index.d.ts @@ -39,4 +39,4 @@ export * from './query'; export * from './dialect'; export * from './dumper'; export * from './dbtypes'; -export * from './fileformat'; +export * from './extensions'; diff --git a/packages/web/src/utility/UploadsProvider.js b/packages/web/src/utility/UploadsProvider.js index f75ab1b8f..09c0c38b0 100644 --- a/packages/web/src/utility/UploadsProvider.js +++ b/packages/web/src/utility/UploadsProvider.js @@ -30,6 +30,7 @@ export function useUploadsZone() { return; } + console.log('FILE', file); const formData = new FormData(); formData.append('data', file); @@ -42,6 +43,15 @@ export function useUploadsZone() { const resp = await fetch(`${apiBase}/uploads/upload`, fetchOptions); const fileData = await resp.json(); + fileData.shortName = file.name; + + for (const format of extensions.fileFormats) { + if (file.name.endsWith('.' + format.extension)) { + fileData.shortName = file.name.slice(-format.extension.length - 1); + fileData.storageType = format.storageType; + } + } + if (uploadListener) { uploadListener(fileData); } else { diff --git a/packages/web/src/utility/fileformats.js b/packages/web/src/utility/fileformats.js index 49be420ef..9fee0859a 100644 --- a/packages/web/src/utility/fileformats.js +++ b/packages/web/src/utility/fileformats.js @@ -56,6 +56,7 @@ const jsonlFormat = { writerFunc: 'jsonLinesWriter', }; +/** @returns {import('dbgate-types').FileFormatDefinition[]} */ export function buildFileFormats(plugins) { const res = [excelFormat, jsonlFormat]; for (const { content } of plugins) { diff --git a/packages/web/src/utility/useExtensions.js b/packages/web/src/utility/useExtensions.js index 712209138..71a92b6ce 100644 --- a/packages/web/src/utility/useExtensions.js +++ b/packages/web/src/utility/useExtensions.js @@ -11,6 +11,7 @@ export function ExtensionsProvider({ children }) { } export function buildExtensions(plugins) { + /** @type {import('dbgate-types').ExtensionsDirectory} */ const extensions = { plugins, fileFormats: buildFileFormats(plugins), @@ -18,6 +19,7 @@ export function buildExtensions(plugins) { return extensions; } +/** @returns {import('dbgate-types').ExtensionsDirectory} */ export default function useExtensions() { return React.useContext(ExtensionsContext); }