Update versions after upload finishes

This commit is contained in:
shamoon
2026-02-10 11:11:23 -08:00
parent 79001c280d
commit 3a5a32771e

View File

@@ -29,6 +29,7 @@ import {
first, first,
map, map,
switchMap, switchMap,
take,
takeUntil, takeUntil,
tap, tap,
} from 'rxjs/operators' } from 'rxjs/operators'
@@ -80,6 +81,7 @@ import { TagService } from 'src/app/services/rest/tag.service'
import { UserService } from 'src/app/services/rest/user.service' import { UserService } from 'src/app/services/rest/user.service'
import { SettingsService } from 'src/app/services/settings.service' import { SettingsService } from 'src/app/services/settings.service'
import { ToastService } from 'src/app/services/toast.service' import { ToastService } from 'src/app/services/toast.service'
import { WebsocketStatusService } from 'src/app/services/websocket-status.service'
import { getFilenameFromContentDisposition } from 'src/app/utils/http' import { getFilenameFromContentDisposition } from 'src/app/utils/http'
import { ISODateAdapter } from 'src/app/utils/ngb-iso-date-adapter' import { ISODateAdapter } from 'src/app/utils/ngb-iso-date-adapter'
import * as UTIF from 'utif' import * as UTIF from 'utif'
@@ -207,6 +209,7 @@ export class DocumentDetailComponent
private componentRouterService = inject(ComponentRouterService) private componentRouterService = inject(ComponentRouterService)
private deviceDetectorService = inject(DeviceDetectorService) private deviceDetectorService = inject(DeviceDetectorService)
private savedViewService = inject(SavedViewService) private savedViewService = inject(SavedViewService)
private websocketStatusService = inject(WebsocketStatusService)
@ViewChild('inputTitle') @ViewChild('inputTitle')
titleInput: TextComponent titleInput: TextComponent
@@ -1238,15 +1241,51 @@ export class DocumentDetailComponent
const label = this.newVersionLabel?.trim() const label = this.newVersionLabel?.trim()
this.documentsService this.documentsService
.uploadVersion(this.documentId, file, label) .uploadVersion(this.documentId, file, label)
.pipe(first()) .pipe(
.subscribe({ first(),
next: () => { tap(() => {
this.toastService.showInfo( this.toastService.showInfo(
$localize`Uploading new version. Processing will happen in the background.` $localize`Uploading new version. Processing will happen in the background.`
) )
this.newVersionLabel = '' this.newVersionLabel = ''
// Refresh metadata to reflect that versions changed (when ready) }),
this.openDocumentService.refreshDocument(this.documentId) map((taskId) =>
typeof taskId === 'string'
? taskId
: (taskId as { task_id?: string })?.task_id
),
switchMap((taskId) => {
if (!taskId) {
return of(null)
}
return this.websocketStatusService
.onDocumentConsumptionFinished()
.pipe(
filter((status) => status.taskId === taskId),
take(1)
)
}),
switchMap((status) => {
if (!status) {
return of(null)
}
return this.documentsService.getVersions(this.documentId)
}),
takeUntil(this.unsubscribeNotifier),
takeUntil(this.docChangeNotifier)
)
.subscribe({
next: (doc) => {
if (doc?.versions) {
this.document.versions = doc.versions
const openDoc = this.openDocumentService.getOpenDocument(
this.documentId
)
if (openDoc) {
openDoc.versions = doc.versions
this.openDocumentService.save()
}
}
}, },
error: (error) => { error: (error) => {
this.toastService.showError( this.toastService.showError(