import { Injectable } from '@angular/core' ; import { Observable , of } from 'rxjs' ; import { AppStore , getRepositoryStatus } from '@alfresco/aca-shared/store' ; import { take , map , catchError , mergeMap } from 'rxjs/operators' ; import { Store } from '@ngrx/store' ; import { ContentApiService } from '@alfresco/aca-shared' ; import { DirectAccessUrlEntry } from '@alfresco/js-api' ; import { ContentVersionService } from '@alfresco/adf-content-services' ; import { AlfrescoApiService } from '@alfresco/adf-core' ; @ Injectable ( { providedIn : 'root' } ) export class ContentUrlService extends ContentVersionService { constructor ( private store , private contentApiService , alfrescoApiService ) { super ( alfrescoApiService ) ; } getNodeContentUrl ( nodeId , attachment = true ) { return this . isDirectAccessUrlEnabled ( ) . pipe ( mergeMap ( ( dauEnabled ) => { if ( dauEnabled ) { return this . contentApiService . requestNodeDirectAccessUrl ( nodeId ) . pipe ( map ( ( dauObj ) => dauObj . entry . contentUrl ) , catchError ( ( ) => of ( this . contentApiService . getContentUrl ( nodeId , true ) ) ) ) ; } else { return of ( this . contentApiService . getContentUrl ( nodeId , attachment ) ) ; } } ) ) ; } getVersionContentUrl ( nodeId , versionId , attachment = true ) { return this . isDirectAccessUrlEnabled ( ) . pipe ( mergeMap ( ( dauEnabled ) => { if ( dauEnabled ) { return this . contentApiService . requestVersionDirectAccessUrl ( nodeId , versionId ) . pipe ( map ( ( dauObj ) => dauObj . entry . contentUrl ) , catchError ( ( ) => of ( this . contentApiService . getVersionContentUrl ( nodeId , versionId , true ) ) ) ) ; } else { return of ( this . contentApiService . getVersionContentUrl ( nodeId , versionId , attachment ) ) ; } } ) ) ; } private isDirectAccessUrlEnabled ( ) { return this . store . select ( getRepositoryStatus ) . pipe ( take ( 1 ) , map ( ( repository ) => ! ! repository ?. status ?. isDirectAccessUrlEnabled ) ) ; } }