@@ -15,6 +15,7 @@ import {
1515 OFSGetPropertiesParams ,
1616} from "./model" ;
1717
18+ export * from "./model" ;
1819export class OFS {
1920 private _credentials ! : OFSCredentials ;
2021 private _hash ! : string ;
@@ -57,7 +58,8 @@ export class OFS {
5758
5859 private _get (
5960 partialURL : string ,
60- params : any = undefined
61+ params : any = undefined ,
62+ extraHeaders : Headers = new Headers ( )
6163 ) : Promise < OFSResponse > {
6264 var theURL = new URL ( partialURL , this . _baseURL ) ;
6365 if ( params != undefined ) {
@@ -66,6 +68,10 @@ export class OFS {
6668 }
6769 var myHeaders = new Headers ( ) ;
6870 myHeaders . append ( "Authorization" , this . authorization ) ;
71+ extraHeaders . forEach ( ( value , key ) => {
72+ console . log ( key , value ) ;
73+ myHeaders . append ( key , value ) ;
74+ } ) ;
6975 var requestOptions = {
7076 method : "GET" ,
7177 headers : myHeaders ,
@@ -74,12 +80,24 @@ export class OFS {
7480 . then ( async function ( response ) {
7581 // Your code for handling the data you get from the API
7682 if ( response . status < 400 ) {
77- var data = await response . json ( ) ;
83+ var data ;
84+ if (
85+ response . headers . get ( "Content-Type" ) ?. includes ( "json" )
86+ ) {
87+ data = await response . json ( ) ;
88+ } else if (
89+ response . headers . get ( "Content-Type" ) ?. includes ( "text" )
90+ ) {
91+ data = await response . text ( ) ;
92+ } else {
93+ data = await response . blob ( ) ;
94+ }
7895 return new OFSResponse (
7996 theURL ,
8097 response . status ,
8198 undefined ,
82- data
99+ data ,
100+ response . headers . get ( "Content-Type" ) || undefined
83101 ) ;
84102 } else {
85103 return new OFSResponse (
@@ -134,27 +152,51 @@ export class OFS {
134152 return fetchPromise ;
135153 }
136154
137- private _put ( partialURL : string , requestData : any ) : Promise < OFSResponse > {
155+ private _put (
156+ partialURL : string ,
157+ requestData : any ,
158+ contentType : string = "application/json" ,
159+ fileName ?: string
160+ ) : Promise < OFSResponse > {
138161 var theURL = new URL ( partialURL , this . _baseURL ) ;
139162 var myHeaders = new Headers ( ) ;
140163 myHeaders . append ( "Authorization" , this . authorization ) ;
141- myHeaders . append ( "Content-Type" , "application/json" ) ;
164+ myHeaders . append ( "Content-Type" , contentType ) ;
165+ if ( contentType == "application/json" ) {
166+ requestData = JSON . stringify ( requestData ) ;
167+ }
168+ if ( fileName ) {
169+ myHeaders . append (
170+ "Content-Disposition" ,
171+ `attachment; filename=${ fileName } `
172+ ) ;
173+ }
142174 var requestOptions : RequestInit = {
143175 method : "PUT" ,
144176 headers : myHeaders ,
145- body : JSON . stringify ( requestData ) ,
177+ body : requestData ,
146178 } ;
147179 const fetchPromise = fetch ( theURL , requestOptions )
148180 . then ( async function ( response ) {
149181 // Your code for handling the data you get from the API
150182 if ( response . status < 400 ) {
151- var data = await response . json ( ) ;
152- return new OFSResponse (
153- theURL ,
154- response . status ,
155- undefined ,
156- data
157- ) ;
183+ if ( response . status == 204 ) {
184+ //No data here
185+ return new OFSResponse (
186+ theURL ,
187+ response . status ,
188+ undefined ,
189+ undefined
190+ ) ;
191+ } else {
192+ var data = await response . json ( ) ;
193+ return new OFSResponse (
194+ theURL ,
195+ response . status ,
196+ undefined ,
197+ data
198+ ) ;
199+ }
158200 } else {
159201 return new OFSResponse (
160202 theURL ,
@@ -319,6 +361,69 @@ export class OFS {
319361 return this . _patch ( partialURL , data ) ;
320362 }
321363
364+ async getActivityFilePropertyContent (
365+ aid : number ,
366+ propertyLabel : string ,
367+ nediaType : string = "*/*"
368+ ) : Promise < OFSResponse > {
369+ var myHeaders = new Headers ( ) ;
370+ myHeaders . append ( "Accept" , nediaType ) ;
371+ const partialURL = `/rest/ofscCore/v1/activities/${ aid } /${ propertyLabel } ` ;
372+ return this . _get ( partialURL , undefined , myHeaders ) ;
373+ }
374+
375+ async getActivityFilePropertyMetadata (
376+ aid : number ,
377+ propertyLabel : string
378+ ) : Promise < OFSResponse > {
379+ var myHeaders = new Headers ( ) ;
380+ myHeaders . append ( "Accept" , "*/*" ) ;
381+ const partialURL = `/rest/ofscCore/v1/activities/${ aid } /${ propertyLabel } ` ;
382+ return this . _get ( partialURL , undefined , myHeaders ) ;
383+ }
384+
385+ async getActivityFileProperty (
386+ aid : number ,
387+ propertyLabel : string
388+ ) : Promise < OFSResponse > {
389+ var myHeaders = new Headers ( ) ;
390+ const partialURL = `/rest/ofscCore/v1/activities/${ aid } /${ propertyLabel } ` ;
391+ var metadata = await this . getActivityFilePropertyMetadata (
392+ aid ,
393+ propertyLabel
394+ ) ;
395+ if ( metadata . status < 400 ) {
396+ var contentType = metadata . contentType ;
397+ if ( contentType ) {
398+ myHeaders . append ( "Accept" , contentType ) ;
399+ }
400+ var content = this . _get ( partialURL , undefined , myHeaders ) ;
401+ return new OFSResponse (
402+ metadata . url ,
403+ metadata . status ,
404+ metadata . description ,
405+ {
406+ ...metadata . data ,
407+ content : ( await content ) . data ,
408+ } ,
409+ metadata . contentType
410+ ) ;
411+ } else {
412+ return metadata ;
413+ }
414+ }
415+
416+ async setActivityFileProperty (
417+ aid : number ,
418+ propertyLabel : string ,
419+ blob : Blob ,
420+ fileName : string ,
421+ contentType : string = "*/*"
422+ ) : Promise < OFSResponse > {
423+ const partialURL = `/rest/ofscCore/v1/activities/${ aid } /${ propertyLabel } ` ;
424+ return this . _put ( partialURL , blob , contentType , fileName ) ;
425+ }
426+
322427 // Core: User Management
323428 async getUsers (
324429 offset : number = 0 ,
0 commit comments