From 31e57db7abdbc353979b8e435824faaf2c1599a9 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Thu, 12 Feb 2026 11:03:50 -0800 Subject: [PATCH] Frontend apply version id to retrieval when needed --- .../services/rest/document.service.spec.ts | 20 +++++++++ .../src/app/services/rest/document.service.ts | 42 ++++++++++++++----- 2 files changed, 52 insertions(+), 10 deletions(-) diff --git a/src-ui/src/app/services/rest/document.service.spec.ts b/src-ui/src/app/services/rest/document.service.spec.ts index a8dff81cc..233755539 100644 --- a/src-ui/src/app/services/rest/document.service.spec.ts +++ b/src-ui/src/app/services/rest/document.service.spec.ts @@ -253,6 +253,10 @@ describe(`DocumentService`, () => { expect(url).toEqual( `${environment.apiBaseUrl}${endpoint}/${documents[0].id}/thumb/` ) + url = service.getThumbUrl(documents[0].id, 123) + expect(url).toEqual( + `${environment.apiBaseUrl}${endpoint}/${documents[0].id}/thumb/?version=123` + ) }) it('should return the correct download URL for a single document', () => { @@ -264,6 +268,22 @@ describe(`DocumentService`, () => { expect(url).toEqual( `${environment.apiBaseUrl}${endpoint}/${documents[0].id}/download/?original=true` ) + url = service.getDownloadUrl(documents[0].id, false, 123) + expect(url).toEqual( + `${environment.apiBaseUrl}${endpoint}/${documents[0].id}/download/?version=123` + ) + url = service.getDownloadUrl(documents[0].id, true, 123) + expect(url).toEqual( + `${environment.apiBaseUrl}${endpoint}/${documents[0].id}/download/?original=true&version=123` + ) + }) + + it('should pass optional get params for version and fields', () => { + subscription = service.get(documents[0].id, 123, 'content').subscribe() + const req = httpTestingController.expectOne( + `${environment.apiBaseUrl}${endpoint}/${documents[0].id}/?full_perms=true&version=123&fields=content` + ) + expect(req.request.method).toEqual('GET') }) it('should set search query', () => { diff --git a/src-ui/src/app/services/rest/document.service.ts b/src-ui/src/app/services/rest/document.service.ts index 00e894278..41b7b2e22 100644 --- a/src-ui/src/app/services/rest/document.service.ts +++ b/src-ui/src/app/services/rest/document.service.ts @@ -155,11 +155,22 @@ export class DocumentService extends AbstractPaperlessService { }).pipe(map((response) => response.results.map((doc) => doc.id))) } - get(id: number): Observable { + get( + id: number, + versionID: number = null, + fields: string = null + ): Observable { + const params: { full_perms: boolean; version?: string; fields?: string } = { + full_perms: true, + } + if (versionID) { + params.version = versionID.toString() + } + if (fields) { + params.fields = fields + } return this.http.get(this.getResourceUrl(id), { - params: { - full_perms: true, - }, + params, }) } @@ -179,16 +190,27 @@ export class DocumentService extends AbstractPaperlessService { return url.toString() } - getThumbUrl(id: number): string { - return this.getResourceUrl(id, 'thumb') + getThumbUrl(id: number, versionID: number = null): string { + let url = new URL(this.getResourceUrl(id, 'thumb')) + if (versionID) { + url.searchParams.append('version', versionID.toString()) + } + return url.toString() } - getDownloadUrl(id: number, original: boolean = false): string { - let url = this.getResourceUrl(id, 'download') + getDownloadUrl( + id: number, + original: boolean = false, + versionID: number = null + ): string { + let url = new URL(this.getResourceUrl(id, 'download')) if (original) { - url += '?original=true' + url.searchParams.append('original', 'true') } - return url + if (versionID) { + url.searchParams.append('version', versionID.toString()) + } + return url.toString() } uploadVersion(documentId: number, file: File, versionLabel?: string) {