mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-30 03:56:23 -05:00 
			
		
		
		
	Cleanup file upload susbcriptions
This commit is contained in:
		| @@ -6,11 +6,14 @@ import { | |||||||
|   FileStatusPhase, |   FileStatusPhase, | ||||||
| } from './consumer-status.service' | } from './consumer-status.service' | ||||||
| import { DocumentService } from './rest/document.service' | import { DocumentService } from './rest/document.service' | ||||||
|  | import { Subscription } from 'rxjs' | ||||||
|  |  | ||||||
| @Injectable({ | @Injectable({ | ||||||
|   providedIn: 'root', |   providedIn: 'root', | ||||||
| }) | }) | ||||||
| export class UploadDocumentsService { | export class UploadDocumentsService { | ||||||
|  |   private uploadSubscriptions: Array<Subscription> = [] | ||||||
|  |  | ||||||
|   constructor( |   constructor( | ||||||
|     private documentService: DocumentService, |     private documentService: DocumentService, | ||||||
|     private consumerStatusService: ConsumerStatusService |     private consumerStatusService: ConsumerStatusService | ||||||
| @@ -27,36 +30,43 @@ export class UploadDocumentsService { | |||||||
|  |  | ||||||
|           status.message = $localize`Connecting...` |           status.message = $localize`Connecting...` | ||||||
|  |  | ||||||
|           this.documentService.uploadDocument(formData).subscribe({ |           this.uploadSubscriptions[file.name] = this.documentService | ||||||
|             next: (event) => { |             .uploadDocument(formData) | ||||||
|               if (event.type == HttpEventType.UploadProgress) { |             .subscribe({ | ||||||
|                 status.updateProgress( |               next: (event) => { | ||||||
|                   FileStatusPhase.UPLOADING, |                 if (event.type == HttpEventType.UploadProgress) { | ||||||
|                   event.loaded, |                   status.updateProgress( | ||||||
|                   event.total |                     FileStatusPhase.UPLOADING, | ||||||
|                 ) |                     event.loaded, | ||||||
|                 status.message = $localize`Uploading...` |                     event.total | ||||||
|               } else if (event.type == HttpEventType.Response) { |  | ||||||
|                 status.taskId = event.body['task_id'] |  | ||||||
|                 status.message = $localize`Upload complete, waiting...` |  | ||||||
|               } |  | ||||||
|             }, |  | ||||||
|             error: (error) => { |  | ||||||
|               switch (error.status) { |  | ||||||
|                 case 400: { |  | ||||||
|                   this.consumerStatusService.fail(status, error.error.document) |  | ||||||
|                   break |  | ||||||
|                 } |  | ||||||
|                 default: { |  | ||||||
|                   this.consumerStatusService.fail( |  | ||||||
|                     status, |  | ||||||
|                     $localize`HTTP error: ${error.status} ${error.statusText}` |  | ||||||
|                   ) |                   ) | ||||||
|                   break |                   status.message = $localize`Uploading...` | ||||||
|  |                 } else if (event.type == HttpEventType.Response) { | ||||||
|  |                   status.taskId = event.body['task_id'] | ||||||
|  |                   status.message = $localize`Upload complete, waiting...` | ||||||
|  |                   this.uploadSubscriptions[file.name]?.complete() | ||||||
|                 } |                 } | ||||||
|               } |               }, | ||||||
|             }, |               error: (error) => { | ||||||
|           }) |                 switch (error.status) { | ||||||
|  |                   case 400: { | ||||||
|  |                     this.consumerStatusService.fail( | ||||||
|  |                       status, | ||||||
|  |                       error.error.document | ||||||
|  |                     ) | ||||||
|  |                     break | ||||||
|  |                   } | ||||||
|  |                   default: { | ||||||
|  |                     this.consumerStatusService.fail( | ||||||
|  |                       status, | ||||||
|  |                       $localize`HTTP error: ${error.status} ${error.statusText}` | ||||||
|  |                     ) | ||||||
|  |                     break | ||||||
|  |                   } | ||||||
|  |                 } | ||||||
|  |                 this.uploadSubscriptions[file.name]?.complete() | ||||||
|  |               }, | ||||||
|  |             }) | ||||||
|         }) |         }) | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Michael Shamoon
					Michael Shamoon