11import axios , { AxiosInstance , AxiosPromise , AxiosRequestConfig , AxiosResponse } from 'axios' ;
2+ import S3FileFieldClient , { S3FileFieldProgress , S3FileFieldProgressState } from 'django-s3-file-field' ;
23
34import {
45 CreateGraphOptionsSpec ,
56 TableMetadata ,
6- FileUploadOptionsSpec ,
7+ TableUploadOptionsSpec ,
8+ NetworkUploadOptionsSpec ,
79 EdgesSpec ,
810 EdgesOptionsSpec ,
911 Graph ,
@@ -51,10 +53,11 @@ export interface MultinetAxiosInstance extends AxiosInstance {
5153 createWorkspace ( workspace : string ) : AxiosPromise < string > ;
5254 deleteWorkspace ( workspace : string ) : AxiosPromise < string > ;
5355 renameWorkspace ( workspace : string , name : string ) : AxiosPromise < any > ;
54- uploadTable ( workspace : string , table : string , options : FileUploadOptionsSpec , config ?: AxiosRequestConfig ) : AxiosPromise < Array < { } > > ;
56+ uploadTable ( workspace : string , table : string , options : TableUploadOptionsSpec , config ?: AxiosRequestConfig ) : AxiosPromise < Array < { } > > ;
5557 downloadTable ( workspace : string , table : string ) : AxiosPromise < any > ;
5658 deleteTable ( workspace : string , table : string ) : AxiosPromise < string > ;
5759 tableMetadata ( workspace : string , table : string ) : AxiosPromise < TableMetadata > ;
60+ uploadNetwork ( workspace : string , network : string , options : NetworkUploadOptionsSpec , config ?: AxiosRequestConfig ) : AxiosPromise < Array < { } > > ;
5861 createGraph ( workspace : string , graph : string , options : CreateGraphOptionsSpec ) : AxiosPromise < CreateGraphOptionsSpec > ;
5962 deleteGraph ( workspace : string , graph : string ) : AxiosPromise < string > ;
6063 aql ( workspace : string , query : string ) : AxiosPromise < any [ ] > ;
@@ -144,38 +147,20 @@ export function multinetAxiosInstance(config: AxiosRequestConfig): MultinetAxios
144147 } ) ;
145148 } ;
146149
147- Proto . uploadTable = async function ( workspace : string , table : string , options : FileUploadOptionsSpec , cfg ?: AxiosRequestConfig ) : Promise < AxiosResponse < Array < { } > > > {
148- const headers = cfg ? cfg . headers : undefined ;
149- const params = cfg ? cfg . params : undefined ;
150- const { type, data, key, overwrite, columnTypes } = options ;
151-
152- let text ;
153-
154- if ( typeof data === 'string' ) {
155- text = data ;
156- } else {
157- text = await fileToText ( data ) ;
158- }
159-
160- let metadata ;
161- if ( columnTypes ) {
162- const columns = Object . keys ( columnTypes ) . map ( ( column ) => ( {
163- key : column ,
164- type : columnTypes [ column ] ,
165- } ) ) ;
166-
167- metadata = { columns } ;
168- }
169-
170- return this . post ( `/${ type } /${ workspace } /${ table } ` , text , {
171- ...cfg ,
172- headers : { ...headers , 'Content-Type' : 'text/plain' } ,
173- params : {
174- ...params ,
175- key : key || undefined ,
176- overwrite : overwrite || undefined ,
177- metadata : metadata || undefined ,
178- } ,
150+ Proto . uploadTable = async function ( workspace : string , table : string , options : TableUploadOptionsSpec ) : Promise < AxiosResponse < Array < { } > > > {
151+ const { data, edgeTable, columnTypes } = options ;
152+ const s3ffClient = new S3FileFieldClient ( {
153+ baseUrl : `${ this . defaults . baseURL } /s3-upload/` ,
154+ apiConfig : this . defaults ,
155+ } ) ;
156+
157+ const fieldValue = await s3ffClient . uploadFile ( data , 'api.Upload.blob' ) ;
158+
159+ return this . post ( `/workspaces/${ workspace } /uploads/csv/` , {
160+ field_value : fieldValue . value ,
161+ edge : edgeTable ,
162+ table_name : table ,
163+ columns : columnTypes
179164 } ) ;
180165 } ;
181166
@@ -191,6 +176,21 @@ export function multinetAxiosInstance(config: AxiosRequestConfig): MultinetAxios
191176 return this . get ( `/workspaces/${ workspace } /tables/${ table } /metadata` ) ;
192177 } ;
193178
179+ Proto . uploadNetwork = async function ( workspace : string , network : string , options : NetworkUploadOptionsSpec ) : Promise < AxiosResponse < Array < { } > > > {
180+ const { type, data } = options ;
181+ const s3ffClient = new S3FileFieldClient ( {
182+ baseUrl : `${ this . defaults . baseURL } /s3-upload/` ,
183+ apiConfig : this . defaults ,
184+ } ) ;
185+
186+ const fieldValue = await s3ffClient . uploadFile ( data , 'api.Upload.blob' ) ;
187+
188+ return this . post ( `/workspaces/${ workspace } /uploads/${ type } /` , {
189+ field_value : fieldValue . value ,
190+ network_name : network
191+ } ) ;
192+ } ;
193+
194194 Proto . createGraph = function ( workspace : string , graph : string , options : CreateGraphOptionsSpec ) : AxiosPromise < CreateGraphOptionsSpec > {
195195 return this . post ( `/workspaces/${ workspace } /networks/` , {
196196 name : graph ,
0 commit comments