From 0e2292922fe1d86150ef5d6ebccfe48e5e3611de Mon Sep 17 00:00:00 2001 From: Jack Wilburn Date: Tue, 21 Feb 2023 15:21:17 -0700 Subject: [PATCH 1/2] Allow the json table route for uploading --- src/axios.ts | 21 +++++++++++++++++---- src/index.ts | 5 +++-- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/axios.ts b/src/axios.ts index a636060..80f9236 100644 --- a/src/axios.ts +++ b/src/axios.ts @@ -159,7 +159,7 @@ export function multinetAxiosInstance(config: AxiosRequestConfig): MultinetAxios }; Proto.uploadTable = async function(workspace: string, table: string, options: TableUploadOptionsSpec): Promise>> { - const { data, edgeTable, columnTypes, delimiter, quoteChar } = options; + const { data, edgeTable, columnTypes, fileType, delimiter, quoteChar } = options; const s3ffClient = new S3FileFieldClient({ baseUrl: `${this.defaults.baseURL}/s3-upload/`, apiConfig: this.defaults, @@ -167,14 +167,27 @@ export function multinetAxiosInstance(config: AxiosRequestConfig): MultinetAxios const fieldValue = await s3ffClient.uploadFile(data, 'api.Upload.blob'); - return this.post(`workspaces/${workspace}/uploads/csv/`, { + console.log('js', fileType); + + if (fileType === 'csv') { + return this.post(`workspaces/${workspace}/uploads/csv/`, { + field_value: fieldValue.value, + edge: edgeTable, + table_name: table, + columns: columnTypes, + delimiter, + quotechar: quoteChar, + }); + } + + // else if json + return this.post(`workspaces/${workspace}/uploads/json/`, { field_value: fieldValue.value, edge: edgeTable, table_name: table, columns: columnTypes, - delimiter, - quotechar: quoteChar, }); + }; Proto.downloadTable = function(workspace: string, table: string): AxiosPromise { diff --git a/src/index.ts b/src/index.ts index 39a94b4..9b9b6f6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -126,8 +126,9 @@ export interface TableUploadOptionsSpec { columnTypes?: { [key: string]: ColumnType; }; - delimiter: string; - quoteChar: string; + fileType: 'json' | 'csv'; + delimiter?: string; + quoteChar?: string; } export interface NetworkUploadOptionsSpec { From 2eb685b2a8273592643dc9407cbcf59a8e0dd575 Mon Sep 17 00:00:00 2001 From: Jack Wilburn Date: Tue, 21 Feb 2023 16:45:43 -0700 Subject: [PATCH 2/2] Fix linting issues --- src/axios.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/axios.ts b/src/axios.ts index 80f9236..6ec89be 100644 --- a/src/axios.ts +++ b/src/axios.ts @@ -167,8 +167,6 @@ export function multinetAxiosInstance(config: AxiosRequestConfig): MultinetAxios const fieldValue = await s3ffClient.uploadFile(data, 'api.Upload.blob'); - console.log('js', fileType); - if (fileType === 'csv') { return this.post(`workspaces/${workspace}/uploads/csv/`, { field_value: fieldValue.value, @@ -187,7 +185,6 @@ export function multinetAxiosInstance(config: AxiosRequestConfig): MultinetAxios table_name: table, columns: columnTypes, }); - }; Proto.downloadTable = function(workspace: string, table: string): AxiosPromise {