mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-02-16 00:19:32 -06:00
Frontend apply version id to retrieval when needed
This commit is contained in:
@@ -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', () => {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user