import { RepoApi } from '../repo-api' ; import { UploadApi as AdfUploadApi } from '@alfresco/js-api' ; import { browser } from 'protractor' ; import * as fs from 'fs' ; export class UploadApi extends RepoApi { upload = new AdfUploadApi ( this . alfrescoJsApi ) ; e2eRootPath = browser . params . e2eRootPath ; constructor ( username ? , password ? ) { super ( username , password ) ; } async uploadFile ( fileName , parentFolderId = '-my-' ) { const file = fs . createReadStream ( `${ this . e2eRootPath }/resources/test-files/${ fileName }` ) ; const opts = { name : fileName , nodeType : 'cm:content' } ; try { await this . apiAuth ( ) ; return await this . upload . uploadFile ( file , '' , parentFolderId , null , opts ) ; } catch ( error ) { this . handleError ( `${ this . constructor . name } ${ this . uploadFile . name }` , error ) ; } } async uploadFileWithRename ( fileName , parentId = '-my-' , newName , title = '' , description = '' ) { const file = fs . createReadStream ( `${ this . e2eRootPath }/resources/test-files/${ fileName }` ) ; const nodeProps = { properties : { 'cm:title' : title , 'cm:description' : description } } ; const opts = { name : newName , nodeType : 'cm:content' } ; try { await this . apiAuth ( ) ; return await this . upload . uploadFile ( file , '' , parentId , nodeProps , opts ) ; } catch ( error ) { this . handleError ( `${ this . constructor . name } ${ this . uploadFileWithRename . name }` , error ) ; } } }