From 7c0f33383fef51fbb67d38db7f7255b6ba7eda0c Mon Sep 17 00:00:00 2001 From: Jan Prochazka Date: Sun, 27 Mar 2022 20:35:30 +0200 Subject: [PATCH] ndjson direct support --- packages/api/src/utility/getJslFileName.js | 4 +++ packages/web/src/plugins/fileformats.ts | 5 ++-- packages/web/src/tabs/ArchiveFileTab.svelte | 2 +- packages/web/src/utility/clipboard.ts | 4 +-- packages/web/src/utility/openElectronFile.ts | 26 ++++++++++++++++++-- 5 files changed, 34 insertions(+), 7 deletions(-) diff --git a/packages/api/src/utility/getJslFileName.js b/packages/api/src/utility/getJslFileName.js index 8c8ac4c6..439deede 100644 --- a/packages/api/src/utility/getJslFileName.js +++ b/packages/api/src/utility/getJslFileName.js @@ -6,6 +6,10 @@ function getJslFileName(jslid) { if (archiveMatch) { return path.join(resolveArchiveFolder(archiveMatch[1]), `${archiveMatch[2]}.jsonl`); } + const fileMatch = jslid.match(/^file:\/\/(.*)$/); + if (fileMatch) { + return fileMatch[1]; + } return path.join(jsldir(), `${jslid}.jsonl`); } diff --git a/packages/web/src/plugins/fileformats.ts b/packages/web/src/plugins/fileformats.ts index e1008289..070cf5b5 100644 --- a/packages/web/src/plugins/fileformats.ts +++ b/packages/web/src/plugins/fileformats.ts @@ -3,7 +3,8 @@ import { FileFormatDefinition, QuickExportDefinition } from 'dbgate-types'; const jsonlFormat = { storageType: 'jsonl', extension: 'jsonl', - name: 'JSON lines', + extensions: ['jsonl', 'ndjson'], + name: 'JSON lines/NDJSON', readerFunc: 'jsonLinesReader', writerFunc: 'jsonLinesWriter', }; @@ -23,7 +24,7 @@ const sqlFormat = { }; const jsonlQuickExport = { - label: 'JSON lines', + label: 'JSON lines/NDJSON', extension: 'jsonl', createWriter: fileName => ({ functionName: 'jsonLinesWriter', diff --git a/packages/web/src/tabs/ArchiveFileTab.svelte b/packages/web/src/tabs/ArchiveFileTab.svelte index 71ba9889..dae86dd9 100644 --- a/packages/web/src/tabs/ArchiveFileTab.svelte +++ b/packages/web/src/tabs/ArchiveFileTab.svelte @@ -1,5 +1,5 @@