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, | ||||
| } from './consumer-status.service' | ||||
| import { DocumentService } from './rest/document.service' | ||||
| import { Subscription } from 'rxjs' | ||||
|  | ||||
| @Injectable({ | ||||
|   providedIn: 'root', | ||||
| }) | ||||
| export class UploadDocumentsService { | ||||
|   private uploadSubscriptions: Array<Subscription> = [] | ||||
|  | ||||
|   constructor( | ||||
|     private documentService: DocumentService, | ||||
|     private consumerStatusService: ConsumerStatusService | ||||
| @@ -27,7 +30,9 @@ export class UploadDocumentsService { | ||||
|  | ||||
|           status.message = $localize`Connecting...` | ||||
|  | ||||
|           this.documentService.uploadDocument(formData).subscribe({ | ||||
|           this.uploadSubscriptions[file.name] = this.documentService | ||||
|             .uploadDocument(formData) | ||||
|             .subscribe({ | ||||
|               next: (event) => { | ||||
|                 if (event.type == HttpEventType.UploadProgress) { | ||||
|                   status.updateProgress( | ||||
| @@ -39,12 +44,16 @@ export class UploadDocumentsService { | ||||
|                 } 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) | ||||
|                     this.consumerStatusService.fail( | ||||
|                       status, | ||||
|                       error.error.document | ||||
|                     ) | ||||
|                     break | ||||
|                   } | ||||
|                   default: { | ||||
| @@ -55,6 +64,7 @@ export class UploadDocumentsService { | ||||
|                     break | ||||
|                   } | ||||
|                 } | ||||
|                 this.uploadSubscriptions[file.name]?.complete() | ||||
|               }, | ||||
|             }) | ||||
|         }) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Michael Shamoon
					Michael Shamoon