mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-19 10:19:27 -05:00
code formatting
This commit is contained in:
parent
0136ba504b
commit
db76e1d65f
@ -1,25 +1,25 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core'
|
||||||
import { HttpEventType } from '@angular/common/http';
|
import { HttpEventType } from '@angular/common/http'
|
||||||
import { FileSystemFileEntry, NgxFileDropEntry } from 'ngx-file-drop';
|
import { FileSystemFileEntry, NgxFileDropEntry } from 'ngx-file-drop'
|
||||||
import { ConsumerStatusService, FileStatusPhase } from './consumer-status.service';
|
import {
|
||||||
import { DocumentService } from './rest/document.service';
|
ConsumerStatusService,
|
||||||
|
FileStatusPhase,
|
||||||
|
} from './consumer-status.service'
|
||||||
|
import { DocumentService } from './rest/document.service'
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root',
|
||||||
})
|
})
|
||||||
export class UploadDocumentsService {
|
export class UploadDocumentsService {
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private documentService: DocumentService,
|
private documentService: DocumentService,
|
||||||
private consumerStatusService: ConsumerStatusService
|
private consumerStatusService: ConsumerStatusService
|
||||||
) {
|
) {}
|
||||||
}
|
|
||||||
|
|
||||||
uploadFiles(files: NgxFileDropEntry[]) {
|
uploadFiles(files: NgxFileDropEntry[]) {
|
||||||
for (const droppedFile of files) {
|
for (const droppedFile of files) {
|
||||||
if (droppedFile.fileEntry.isFile) {
|
if (droppedFile.fileEntry.isFile) {
|
||||||
|
const fileEntry = droppedFile.fileEntry as FileSystemFileEntry
|
||||||
const fileEntry = droppedFile.fileEntry as FileSystemFileEntry;
|
|
||||||
fileEntry.file((file: File) => {
|
fileEntry.file((file: File) => {
|
||||||
let formData = new FormData()
|
let formData = new FormData()
|
||||||
formData.append('document', file, file.name)
|
formData.append('document', file, file.name)
|
||||||
@ -27,30 +27,38 @@ export class UploadDocumentsService {
|
|||||||
|
|
||||||
status.message = $localize`Connecting...`
|
status.message = $localize`Connecting...`
|
||||||
|
|
||||||
this.documentService.uploadDocument(formData).subscribe(event => {
|
this.documentService.uploadDocument(formData).subscribe({
|
||||||
|
next: (event) => {
|
||||||
if (event.type == HttpEventType.UploadProgress) {
|
if (event.type == HttpEventType.UploadProgress) {
|
||||||
status.updateProgress(FileStatusPhase.UPLOADING, event.loaded, event.total)
|
status.updateProgress(
|
||||||
|
FileStatusPhase.UPLOADING,
|
||||||
|
event.loaded,
|
||||||
|
event.total
|
||||||
|
)
|
||||||
status.message = $localize`Uploading...`
|
status.message = $localize`Uploading...`
|
||||||
} else if (event.type == HttpEventType.Response) {
|
} else if (event.type == HttpEventType.Response) {
|
||||||
status.taskId = event.body["task_id"]
|
status.taskId = event.body['task_id']
|
||||||
status.message = $localize`Upload complete, waiting...`
|
status.message = $localize`Upload complete, waiting...`
|
||||||
}
|
}
|
||||||
|
},
|
||||||
}, error => {
|
error: (error) => {
|
||||||
switch (error.status) {
|
switch (error.status) {
|
||||||
case 400: {
|
case 400: {
|
||||||
this.consumerStatusService.fail(status, error.error.document)
|
this.consumerStatusService.fail(status, error.error.document)
|
||||||
break;
|
break
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
this.consumerStatusService.fail(status, $localize`HTTP error: ${error.status} ${error.statusText}`)
|
this.consumerStatusService.fail(
|
||||||
break;
|
status,
|
||||||
|
$localize`HTTP error: ${error.status} ${error.statusText}`
|
||||||
|
)
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
})
|
||||||
})
|
})
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user