mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-30 03:56:23 -05:00 
			
		
		
		
	Try to hunt down some more unguarded subscriptions
This commit is contained in:
		| @@ -397,13 +397,20 @@ export class DocumentDetailComponent | |||||||
|  |  | ||||||
|   private loadDocument(documentId: number): void { |   private loadDocument(documentId: number): void { | ||||||
|     this.previewUrl = this.documentsService.getPreviewUrl(documentId) |     this.previewUrl = this.documentsService.getPreviewUrl(documentId) | ||||||
|     this.http.get(this.previewUrl, { responseType: 'text' }).subscribe({ |     this.http | ||||||
|       next: (res) => (this.previewText = res.toString()), |       .get(this.previewUrl, { responseType: 'text' }) | ||||||
|       error: (err) => |       .pipe( | ||||||
|         (this.previewText = $localize`An error occurred loading content: ${ |         first(), | ||||||
|           err.message ?? err.toString() |         takeUntil(this.unsubscribeNotifier), | ||||||
|         }`), |         takeUntil(this.docChangeNotifier) | ||||||
|     }) |       ) | ||||||
|  |       .subscribe({ | ||||||
|  |         next: (res) => (this.previewText = res.toString()), | ||||||
|  |         error: (err) => | ||||||
|  |           (this.previewText = $localize`An error occurred loading content: ${ | ||||||
|  |             err.message ?? err.toString() | ||||||
|  |           }`), | ||||||
|  |       }) | ||||||
|     this.thumbUrl = this.documentsService.getThumbUrl(documentId) |     this.thumbUrl = this.documentsService.getThumbUrl(documentId) | ||||||
|     this.documentsService |     this.documentsService | ||||||
|       .get(documentId) |       .get(documentId) | ||||||
| @@ -412,7 +419,9 @@ export class DocumentDetailComponent | |||||||
|           // 404 is handled in the subscribe below |           // 404 is handled in the subscribe below | ||||||
|           return of(null) |           return of(null) | ||||||
|         }), |         }), | ||||||
|         first() |         first(), | ||||||
|  |         takeUntil(this.unsubscribeNotifier), | ||||||
|  |         takeUntil(this.docChangeNotifier) | ||||||
|       ) |       ) | ||||||
|       .subscribe({ |       .subscribe({ | ||||||
|         next: (doc) => { |         next: (doc) => { | ||||||
| @@ -442,7 +451,14 @@ export class DocumentDetailComponent | |||||||
|               ) |               ) | ||||||
|             } |             } | ||||||
|           } else { |           } else { | ||||||
|             this.openDocumentService.openDocument(doc).pipe(first()).subscribe() |             this.openDocumentService | ||||||
|  |               .openDocument(doc) | ||||||
|  |               .pipe( | ||||||
|  |                 first(), | ||||||
|  |                 takeUntil(this.unsubscribeNotifier), | ||||||
|  |                 takeUntil(this.docChangeNotifier) | ||||||
|  |               ) | ||||||
|  |               .subscribe() | ||||||
|           } |           } | ||||||
|           this.updateComponent(useDoc) |           this.updateComponent(useDoc) | ||||||
|           this.titleSubject |           this.titleSubject | ||||||
| @@ -533,21 +549,23 @@ export class DocumentDetailComponent | |||||||
|         this.loadDocument(documentId) |         this.loadDocument(documentId) | ||||||
|       }) |       }) | ||||||
|  |  | ||||||
|     this.route.paramMap.subscribe((paramMap) => { |     this.route.paramMap | ||||||
|       const section = paramMap.get('section') |       .pipe(takeUntil(this.unsubscribeNotifier)) | ||||||
|       if (section) { |       .subscribe((paramMap) => { | ||||||
|         const navIDKey: string = Object.keys(DocumentDetailNavIDs).find( |         const section = paramMap.get('section') | ||||||
|           (navID) => navID.toLowerCase() == section |         if (section) { | ||||||
|         ) |           const navIDKey: string = Object.keys(DocumentDetailNavIDs).find( | ||||||
|         if (navIDKey) { |             (navID) => navID.toLowerCase() == section | ||||||
|           this.activeNavID = DocumentDetailNavIDs[navIDKey] |           ) | ||||||
|  |           if (navIDKey) { | ||||||
|  |             this.activeNavID = DocumentDetailNavIDs[navIDKey] | ||||||
|  |           } | ||||||
|  |         } else if (paramMap.get('id')) { | ||||||
|  |           this.router.navigate(['documents', +paramMap.get('id'), 'details'], { | ||||||
|  |             replaceUrl: true, | ||||||
|  |           }) | ||||||
|         } |         } | ||||||
|       } else if (paramMap.get('id')) { |       }) | ||||||
|         this.router.navigate(['documents', +paramMap.get('id'), 'details'], { |  | ||||||
|           replaceUrl: true, |  | ||||||
|         }) |  | ||||||
|       } |  | ||||||
|     }) |  | ||||||
|  |  | ||||||
|     this.hotKeyService |     this.hotKeyService | ||||||
|       .addShortcut({ |       .addShortcut({ | ||||||
| @@ -777,7 +795,11 @@ export class DocumentDetailComponent | |||||||
|   discard() { |   discard() { | ||||||
|     this.documentsService |     this.documentsService | ||||||
|       .get(this.documentId) |       .get(this.documentId) | ||||||
|       .pipe(first()) |       .pipe( | ||||||
|  |         first(), | ||||||
|  |         takeUntil(this.unsubscribeNotifier), | ||||||
|  |         takeUntil(this.docChangeNotifier) | ||||||
|  |       ) | ||||||
|       .subscribe({ |       .subscribe({ | ||||||
|         next: (doc) => { |         next: (doc) => { | ||||||
|           Object.assign(this.document, doc) |           Object.assign(this.document, doc) | ||||||
| @@ -880,9 +902,10 @@ export class DocumentDetailComponent | |||||||
|       .patch(this.getChangedFields()) |       .patch(this.getChangedFields()) | ||||||
|       .pipe( |       .pipe( | ||||||
|         switchMap((updateResult) => { |         switchMap((updateResult) => { | ||||||
|           return this.documentListViewService |           return this.documentListViewService.getNext(this.documentId).pipe( | ||||||
|             .getNext(this.documentId) |             map((nextDocId) => ({ nextDocId, updateResult })), | ||||||
|             .pipe(map((nextDocId) => ({ nextDocId, updateResult }))) |             takeUntil(this.unsubscribeNotifier) | ||||||
|  |           ) | ||||||
|         }) |         }) | ||||||
|       ) |       ) | ||||||
|       .pipe( |       .pipe( | ||||||
| @@ -892,7 +915,10 @@ export class DocumentDetailComponent | |||||||
|             return this.openDocumentService |             return this.openDocumentService | ||||||
|               .closeDocument(this.document) |               .closeDocument(this.document) | ||||||
|               .pipe( |               .pipe( | ||||||
|                 map((closeResult) => ({ updateResult, nextDocId, closeResult })) |                 map( | ||||||
|  |                   (closeResult) => ({ updateResult, nextDocId, closeResult }), | ||||||
|  |                   takeUntil(this.unsubscribeNotifier) | ||||||
|  |                 ) | ||||||
|               ) |               ) | ||||||
|           } |           } | ||||||
|         }) |         }) | ||||||
| @@ -1412,43 +1438,50 @@ export class DocumentDetailComponent | |||||||
|   } |   } | ||||||
|  |  | ||||||
|   private tryRenderTiff() { |   private tryRenderTiff() { | ||||||
|     this.http.get(this.previewUrl, { responseType: 'arraybuffer' }).subscribe({ |     this.http | ||||||
|       next: (res) => { |       .get(this.previewUrl, { responseType: 'arraybuffer' }) | ||||||
|         /* istanbul ignore next */ |       .pipe( | ||||||
|         try { |         first(), | ||||||
|           // See UTIF.js > _imgLoaded |         takeUntil(this.unsubscribeNotifier), | ||||||
|           const tiffIfds: any[] = UTIF.decode(res) |         takeUntil(this.docChangeNotifier) | ||||||
|           var vsns = tiffIfds, |       ) | ||||||
|             ma = 0, |       .subscribe({ | ||||||
|             page = vsns[0] |         next: (res) => { | ||||||
|           if (tiffIfds[0].subIFD) vsns = vsns.concat(tiffIfds[0].subIFD) |           /* istanbul ignore next */ | ||||||
|           for (var i = 0; i < vsns.length; i++) { |           try { | ||||||
|             var img = vsns[i] |             // See UTIF.js > _imgLoaded | ||||||
|             if (img['t258'] == null || img['t258'].length < 3) continue |             const tiffIfds: any[] = UTIF.decode(res) | ||||||
|             var ar = img['t256'] * img['t257'] |             var vsns = tiffIfds, | ||||||
|             if (ar > ma) { |               ma = 0, | ||||||
|               ma = ar |               page = vsns[0] | ||||||
|               page = img |             if (tiffIfds[0].subIFD) vsns = vsns.concat(tiffIfds[0].subIFD) | ||||||
|  |             for (var i = 0; i < vsns.length; i++) { | ||||||
|  |               var img = vsns[i] | ||||||
|  |               if (img['t258'] == null || img['t258'].length < 3) continue | ||||||
|  |               var ar = img['t256'] * img['t257'] | ||||||
|  |               if (ar > ma) { | ||||||
|  |                 ma = ar | ||||||
|  |                 page = img | ||||||
|  |               } | ||||||
|             } |             } | ||||||
|  |             UTIF.decodeImage(res, page, tiffIfds) | ||||||
|  |             const rgba = UTIF.toRGBA8(page) | ||||||
|  |             const { width: w, height: h } = page | ||||||
|  |             var cnv = document.createElement('canvas') | ||||||
|  |             cnv.width = w | ||||||
|  |             cnv.height = h | ||||||
|  |             var ctx = cnv.getContext('2d'), | ||||||
|  |               imgd = ctx.createImageData(w, h) | ||||||
|  |             for (var i = 0; i < rgba.length; i++) imgd.data[i] = rgba[i] | ||||||
|  |             ctx.putImageData(imgd, 0, 0) | ||||||
|  |             this.tiffURL = cnv.toDataURL() | ||||||
|  |           } catch (err) { | ||||||
|  |             this.tiffError = $localize`An error occurred loading tiff: ${err.toString()}` | ||||||
|           } |           } | ||||||
|           UTIF.decodeImage(res, page, tiffIfds) |         }, | ||||||
|           const rgba = UTIF.toRGBA8(page) |         error: (err) => { | ||||||
|           const { width: w, height: h } = page |  | ||||||
|           var cnv = document.createElement('canvas') |  | ||||||
|           cnv.width = w |  | ||||||
|           cnv.height = h |  | ||||||
|           var ctx = cnv.getContext('2d'), |  | ||||||
|             imgd = ctx.createImageData(w, h) |  | ||||||
|           for (var i = 0; i < rgba.length; i++) imgd.data[i] = rgba[i] |  | ||||||
|           ctx.putImageData(imgd, 0, 0) |  | ||||||
|           this.tiffURL = cnv.toDataURL() |  | ||||||
|         } catch (err) { |  | ||||||
|           this.tiffError = $localize`An error occurred loading tiff: ${err.toString()}` |           this.tiffError = $localize`An error occurred loading tiff: ${err.toString()}` | ||||||
|         } |         }, | ||||||
|       }, |       }) | ||||||
|       error: (err) => { |  | ||||||
|         this.tiffError = $localize`An error occurred loading tiff: ${err.toString()}` |  | ||||||
|       }, |  | ||||||
|     }) |  | ||||||
|   } |   } | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 shamoon
					shamoon