mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-12-11 09:07:18 +01:00
parent
f8c8161a3e
commit
f34202a82a
159 changed files with 3882 additions and 2716 deletions
|
|
@ -1,34 +1,33 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import { Subject } from 'rxjs';
|
||||
import { environment } from 'src/environments/environment';
|
||||
import { WebsocketConsumerStatusMessage } from '../data/websocket-consumer-status-message';
|
||||
import { Injectable } from '@angular/core'
|
||||
import { Subject } from 'rxjs'
|
||||
import { environment } from 'src/environments/environment'
|
||||
import { WebsocketConsumerStatusMessage } from '../data/websocket-consumer-status-message'
|
||||
|
||||
export enum FileStatusPhase {
|
||||
STARTED = 0,
|
||||
UPLOADING = 1,
|
||||
PROCESSING = 2,
|
||||
SUCCESS = 3,
|
||||
FAILED = 4
|
||||
FAILED = 4,
|
||||
}
|
||||
|
||||
export const FILE_STATUS_MESSAGES = {
|
||||
"document_already_exists": $localize`Document already exists.`,
|
||||
"file_not_found": $localize`File not found.`,
|
||||
"pre_consume_script_not_found": $localize`:Pre-Consume is a term that appears like that in the documentation as well and does not need a specific translation:Pre-consume script does not exist.`,
|
||||
"pre_consume_script_error": $localize`:Pre-Consume is a term that appears like that in the documentation as well and does not need a specific translation:Error while executing pre-consume script.`,
|
||||
"post_consume_script_not_found": $localize`:Post-Consume is a term that appears like that in the documentation as well and does not need a specific translation:Post-consume script does not exist.`,
|
||||
"post_consume_script_error": $localize`:Post-Consume is a term that appears like that in the documentation as well and does not need a specific translation:Error while executing post-consume script.`,
|
||||
"new_file": $localize`Received new file.`,
|
||||
"unsupported_type": $localize`File type not supported.`,
|
||||
"parsing_document": $localize`Processing document...`,
|
||||
"generating_thumbnail": $localize`Generating thumbnail...`,
|
||||
"parse_date": $localize`Retrieving date from document...`,
|
||||
"save_document": $localize`Saving document...`,
|
||||
"finished": $localize`Finished.`
|
||||
document_already_exists: $localize`Document already exists.`,
|
||||
file_not_found: $localize`File not found.`,
|
||||
pre_consume_script_not_found: $localize`:Pre-Consume is a term that appears like that in the documentation as well and does not need a specific translation:Pre-consume script does not exist.`,
|
||||
pre_consume_script_error: $localize`:Pre-Consume is a term that appears like that in the documentation as well and does not need a specific translation:Error while executing pre-consume script.`,
|
||||
post_consume_script_not_found: $localize`:Post-Consume is a term that appears like that in the documentation as well and does not need a specific translation:Post-consume script does not exist.`,
|
||||
post_consume_script_error: $localize`:Post-Consume is a term that appears like that in the documentation as well and does not need a specific translation:Error while executing post-consume script.`,
|
||||
new_file: $localize`Received new file.`,
|
||||
unsupported_type: $localize`File type not supported.`,
|
||||
parsing_document: $localize`Processing document...`,
|
||||
generating_thumbnail: $localize`Generating thumbnail...`,
|
||||
parse_date: $localize`Retrieving date from document...`,
|
||||
save_document: $localize`Saving document...`,
|
||||
finished: $localize`Finished.`,
|
||||
}
|
||||
|
||||
export class FileStatus {
|
||||
|
||||
filename: string
|
||||
|
||||
taskId: string
|
||||
|
|
@ -48,16 +47,22 @@ export class FileStatus {
|
|||
case FileStatusPhase.STARTED:
|
||||
return 0.0
|
||||
case FileStatusPhase.UPLOADING:
|
||||
return this.currentPhaseProgress / this.currentPhaseMaxProgress * 0.2
|
||||
return (this.currentPhaseProgress / this.currentPhaseMaxProgress) * 0.2
|
||||
case FileStatusPhase.PROCESSING:
|
||||
return (this.currentPhaseProgress / this.currentPhaseMaxProgress * 0.8) + 0.2
|
||||
return (
|
||||
(this.currentPhaseProgress / this.currentPhaseMaxProgress) * 0.8 + 0.2
|
||||
)
|
||||
case FileStatusPhase.SUCCESS:
|
||||
case FileStatusPhase.FAILED:
|
||||
return 1.0
|
||||
}
|
||||
}
|
||||
|
||||
updateProgress(status: FileStatusPhase, currentProgress?: number, maxProgress?: number) {
|
||||
updateProgress(
|
||||
status: FileStatusPhase,
|
||||
currentProgress?: number,
|
||||
maxProgress?: number
|
||||
) {
|
||||
if (status >= this.phase) {
|
||||
this.phase = status
|
||||
if (currentProgress != null) {
|
||||
|
|
@ -68,15 +73,13 @@ export class FileStatus {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class ConsumerStatusService {
|
||||
|
||||
constructor() { }
|
||||
constructor() {}
|
||||
|
||||
private statusWebSocket: WebSocket
|
||||
|
||||
|
|
@ -87,7 +90,11 @@ export class ConsumerStatusService {
|
|||
private documentConsumptionFailedSubject = new Subject<FileStatus>()
|
||||
|
||||
private get(taskId: string, filename?: string) {
|
||||
let status = this.consumerStatus.find(e => e.taskId == taskId) || this.consumerStatus.find(e => e.filename == filename && e.taskId == null)
|
||||
let status =
|
||||
this.consumerStatus.find((e) => e.taskId == taskId) ||
|
||||
this.consumerStatus.find(
|
||||
(e) => e.filename == filename && e.taskId == null
|
||||
)
|
||||
let created = false
|
||||
if (!status) {
|
||||
status = new FileStatus()
|
||||
|
|
@ -96,7 +103,7 @@ export class ConsumerStatusService {
|
|||
}
|
||||
status.taskId = taskId
|
||||
status.filename = filename
|
||||
return {'status': status, 'created': created}
|
||||
return { status: status, created: created }
|
||||
}
|
||||
|
||||
newFileUpload(filename: string): FileStatus {
|
||||
|
|
@ -108,33 +115,48 @@ export class ConsumerStatusService {
|
|||
|
||||
getConsumerStatus(phase?: FileStatusPhase) {
|
||||
if (phase != null) {
|
||||
return this.consumerStatus.filter(s => s.phase == phase)
|
||||
return this.consumerStatus.filter((s) => s.phase == phase)
|
||||
} else {
|
||||
return this.consumerStatus
|
||||
}
|
||||
}
|
||||
|
||||
getConsumerStatusNotCompleted() {
|
||||
return this.consumerStatus.filter(s => s.phase < FileStatusPhase.SUCCESS)
|
||||
return this.consumerStatus.filter((s) => s.phase < FileStatusPhase.SUCCESS)
|
||||
}
|
||||
|
||||
getConsumerStatusCompleted() {
|
||||
return this.consumerStatus.filter(s => s.phase == FileStatusPhase.FAILED || s.phase == FileStatusPhase.SUCCESS)
|
||||
return this.consumerStatus.filter(
|
||||
(s) =>
|
||||
s.phase == FileStatusPhase.FAILED || s.phase == FileStatusPhase.SUCCESS
|
||||
)
|
||||
}
|
||||
|
||||
connect() {
|
||||
this.disconnect()
|
||||
|
||||
this.statusWebSocket = new WebSocket(`${environment.webSocketProtocol}//${environment.webSocketHost}${environment.webSocketBaseUrl}status/`);
|
||||
this.statusWebSocket = new WebSocket(
|
||||
`${environment.webSocketProtocol}//${environment.webSocketHost}${environment.webSocketBaseUrl}status/`
|
||||
)
|
||||
this.statusWebSocket.onmessage = (ev) => {
|
||||
let statusMessage: WebsocketConsumerStatusMessage = JSON.parse(ev['data'])
|
||||
|
||||
let statusMessageGet = this.get(statusMessage.task_id, statusMessage.filename)
|
||||
let statusMessageGet = this.get(
|
||||
statusMessage.task_id,
|
||||
statusMessage.filename
|
||||
)
|
||||
let status = statusMessageGet.status
|
||||
let created = statusMessageGet.created
|
||||
|
||||
status.updateProgress(FileStatusPhase.PROCESSING, statusMessage.current_progress, statusMessage.max_progress)
|
||||
if (statusMessage.message && statusMessage.message in FILE_STATUS_MESSAGES) {
|
||||
status.updateProgress(
|
||||
FileStatusPhase.PROCESSING,
|
||||
statusMessage.current_progress,
|
||||
statusMessage.max_progress
|
||||
)
|
||||
if (
|
||||
statusMessage.message &&
|
||||
statusMessage.message in FILE_STATUS_MESSAGES
|
||||
) {
|
||||
status.message = FILE_STATUS_MESSAGES[statusMessage.message]
|
||||
} else if (statusMessage.message) {
|
||||
status.message = statusMessage.message
|
||||
|
|
@ -144,11 +166,11 @@ export class ConsumerStatusService {
|
|||
if (created && statusMessage.status == 'STARTING') {
|
||||
this.documentDetectedSubject.next(status)
|
||||
}
|
||||
if (statusMessage.status == "SUCCESS") {
|
||||
if (statusMessage.status == 'SUCCESS') {
|
||||
status.phase = FileStatusPhase.SUCCESS
|
||||
this.documentConsumptionFinishedSubject.next(status)
|
||||
}
|
||||
if (statusMessage.status == "FAILED") {
|
||||
if (statusMessage.status == 'FAILED') {
|
||||
status.phase = FileStatusPhase.FAILED
|
||||
this.documentConsumptionFailedSubject.next(status)
|
||||
}
|
||||
|
|
@ -171,9 +193,11 @@ export class ConsumerStatusService {
|
|||
dismiss(status: FileStatus) {
|
||||
let index
|
||||
if (status.taskId != null) {
|
||||
index = this.consumerStatus.findIndex(s => s.taskId == status.taskId)
|
||||
index = this.consumerStatus.findIndex((s) => s.taskId == status.taskId)
|
||||
} else {
|
||||
index = this.consumerStatus.findIndex(s => s.filename == status.filename)
|
||||
index = this.consumerStatus.findIndex(
|
||||
(s) => s.filename == status.filename
|
||||
)
|
||||
}
|
||||
|
||||
if (index > -1) {
|
||||
|
|
@ -182,7 +206,9 @@ export class ConsumerStatusService {
|
|||
}
|
||||
|
||||
dismissCompleted() {
|
||||
this.consumerStatus = this.consumerStatus.filter(status => status.phase != FileStatusPhase.SUCCESS)
|
||||
this.consumerStatus = this.consumerStatus.filter(
|
||||
(status) => status.phase != FileStatusPhase.SUCCESS
|
||||
)
|
||||
}
|
||||
|
||||
onDocumentConsumptionFinished() {
|
||||
|
|
@ -196,5 +222,4 @@ export class ConsumerStatusService {
|
|||
onDocumentDetected() {
|
||||
return this.documentDetectedSubject
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue