Frontend apply version id to retrieval when needed

This commit is contained in:
shamoon
2026-02-12 11:03:50 -08:00
parent aceeb26d32
commit 31e57db7ab
2 changed files with 52 additions and 10 deletions

View File

@@ -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', () => {

View File

@@ -155,11 +155,22 @@ export class DocumentService extends AbstractPaperlessService<Document> {
}).pipe(map((response) => response.results.map((doc) => doc.id)))
}
get(id: number): Observable<Document> {
get(
id: number,
versionID: number = null,
fields: string = null
): Observable<Document> {
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<Document>(this.getResourceUrl(id), {
params: {
full_perms: true,
},
params,
})
}
@@ -179,16 +190,27 @@ export class DocumentService extends AbstractPaperlessService<Document> {
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) {