From f963c6d15ebafe376ff5aa37be0d353e11727475 Mon Sep 17 00:00:00 2001 From: Vito Date: Tue, 28 Sep 2021 11:47:04 +0100 Subject: [PATCH] [ADF-5173] - improved fix for closing pdfjs worker error (#7225) * [ACA-3847] - fixed download for external source file * [ADF-5173] - improved fix for closing pdfjs worker error * Fixed lint error --- .gitignore | 2 ++ lib/core/viewer/components/pdf-viewer.component.ts | 11 +++++++++-- .../attach-file-widget-dialog.service.ts | 5 +++-- .../content-widget/attach-file-widget.component.ts | 5 +++-- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 232d436eda..e95c71a25d 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ workspace.xml dist/ e2e/.env.cloud tmp +temp e2e-output*/ /e2e/downloads/ *.npmrc @@ -28,3 +29,4 @@ out-tsc /reports/ e2e-result-* licenses.txt +.DS_Store diff --git a/lib/core/viewer/components/pdf-viewer.component.ts b/lib/core/viewer/components/pdf-viewer.component.ts index 43c8ec703e..54ebe6d405 100644 --- a/lib/core/viewer/components/pdf-viewer.component.ts +++ b/lib/core/viewer/components/pdf-viewer.component.ts @@ -33,7 +33,8 @@ import { RenderingQueueServices } from '../services/rendering-queue.services'; import { PdfPasswordDialogComponent } from './pdf-viewer-password-dialog'; import { AppConfigService } from './../../app-config/app-config.service'; import { PDFDocumentProxy, PDFSource } from 'pdfjs-dist'; -import { timer } from 'rxjs'; +import { Subject } from 'rxjs'; +import { catchError, delay, takeUntil } from 'rxjs/operators'; declare const pdfjsLib: any; declare const pdfjsViewer: any; @@ -106,6 +107,8 @@ export class PdfViewerComponent implements OnChanges, OnDestroy { disableAutoFetch: true, disableStream: true }; + private pdfjsWorkerDestroy$ = new Subject(); + private onDestroy$ = new Subject(); constructor( private dialog: MatDialog, @@ -118,6 +121,7 @@ export class PdfViewerComponent implements OnChanges, OnDestroy { this.onPageRendered = this.onPageRendered.bind(this); this.randomPdfId = this.generateUuid(); this.currentScale = this.getUserScaling(); + this.pdfjsWorkerDestroy$.pipe(catchError(() => null), delay(700), takeUntil(this.onDestroy$)).subscribe(() => this.destroyPdJsWorker()); } getUserScaling(): number { @@ -237,8 +241,11 @@ export class PdfViewerComponent implements OnChanges, OnDestroy { } if (this.loadingTask) { - timer(700).subscribe(() => this.destroyPdJsWorker()); + this.pdfjsWorkerDestroy$.next(); } + this.onDestroy$.next(); + this.pdfjsWorkerDestroy$.complete(); + this.onDestroy$.complete(); } private destroyPdJsWorker() { diff --git a/lib/process-services/src/lib/content-widget/attach-file-widget-dialog.service.ts b/lib/process-services/src/lib/content-widget/attach-file-widget-dialog.service.ts index 948486d13f..7a189a9c86 100644 --- a/lib/process-services/src/lib/content-widget/attach-file-widget-dialog.service.ts +++ b/lib/process-services/src/lib/content-widget/attach-file-widget-dialog.service.ts @@ -45,7 +45,7 @@ export class AttachFileWidgetDialogService { * @param currentFolderId Upload file from specific folder * @returns Information about the chosen file(s) */ - openLogin(repository: AlfrescoEndpointRepresentation, currentFolderId = '-my-'): Observable { + openLogin(repository: AlfrescoEndpointRepresentation, currentFolderId = '-my-', accountIdentifier?: string): Observable { const { title, ecmHost, selected, registerExternalHost } = this.constructPayload(repository); const data: AttachFileWidgetDialogComponentData = { title, @@ -54,7 +54,8 @@ export class AttachFileWidgetDialogService { currentFolderId, isSelectionValid: (entry: Node) => entry.isFile, showFilesInResult: true, - registerExternalHost + registerExternalHost, + accountIdentifier }; this.openLoginDialog(data, 'adf-attach-file-widget-dialog', '630px'); diff --git a/lib/process-services/src/lib/content-widget/attach-file-widget.component.ts b/lib/process-services/src/lib/content-widget/attach-file-widget.component.ts index 5845dbcb6a..2c95add7d0 100644 --- a/lib/process-services/src/lib/content-widget/attach-file-widget.component.ts +++ b/lib/process-services/src/lib/content-widget/attach-file-widget.component.ts @@ -238,11 +238,12 @@ export class AttachFileWidgetComponent extends UploadWidgetComponent implements } private uploadFileFromExternalCS(repository: AlfrescoEndpointRepresentation, currentFolderId?: string) { - this.attachDialogService.openLogin(repository, currentFolderId).subscribe( + const accountIdentifier = `alfresco-${repository.id}-${repository.name}`; + this.attachDialogService.openLogin(repository, currentFolderId, accountIdentifier).subscribe( (selections: any[]) => { selections.forEach((node) => node.isExternal = true); this.tempFilesList.push(...selections); - this.uploadFileFromCS(selections, `alfresco-${repository.id}-${repository.name}`); + this.uploadFileFromCS(selections, accountIdentifier); }); }