Fix: respect baseURI for pdfjs worker URL

This commit is contained in:
shamoon 2023-12-06 09:47:44 -08:00
parent aa858a35e2
commit a4d6cab03b
5 changed files with 11 additions and 11 deletions

View File

@ -33,6 +33,7 @@ import type {
ZoomScale,
} from './typings'
import { PDFSinglePageViewer } from 'pdfjs-dist/web/pdf_viewer'
import { environment } from 'src/environments/environment'
PDFJS['verbosity'] = PDFJS.VerbosityLevel.ERRORS
@ -231,7 +232,8 @@ export class PdfViewerComponent
private element: ElementRef<HTMLElement>,
private ngZone: NgZone
) {
PDFJS.GlobalWorkerOptions['workerSrc'] = '/assets/js/pdf.worker.min.js'
PDFJS.GlobalWorkerOptions['workerSrc'] =
`${environment.baseUrl}assets/js/pdf.worker.min.js`
}
ngAfterViewChecked(): void {

View File

@ -194,20 +194,19 @@ describe('ShareLinksDropdownComponent', () => {
})
it('should correctly generate share URLs', () => {
environment.apiBaseUrl = 'http://example.com/api/'
environment.baseUrl = 'http://example.com/'
expect(component.getShareUrl({ slug: '123abc123' } as any)).toEqual(
'http://example.com/share/123abc123'
)
environment.apiBaseUrl = 'http://example.domainwithapiinit.com/api/'
environment.baseUrl = 'http://example.domainwithapiinit.com/'
expect(component.getShareUrl({ slug: '123abc123' } as any)).toEqual(
'http://example.domainwithapiinit.com/share/123abc123'
)
environment.apiBaseUrl = 'http://example.domainwithapiinit.com:1234/api/'
environment.baseUrl = 'http://example.domainwithapiinit.com:1234/'
expect(component.getShareUrl({ slug: '123abc123' } as any)).toEqual(
'http://example.domainwithapiinit.com:1234/share/123abc123'
)
environment.apiBaseUrl =
'http://example.domainwithapiinit.com:1234/subpath/api/'
environment.baseUrl = 'http://example.domainwithapiinit.com:1234/subpath/'
expect(component.getShareUrl({ slug: '123abc123' } as any)).toEqual(
'http://example.domainwithapiinit.com:1234/subpath/share/123abc123'
)

View File

@ -80,10 +80,7 @@ export class ShareLinksDropdownComponent implements OnInit {
}
getShareUrl(link: PaperlessShareLink): string {
const apiURL = new URL(environment.apiBaseUrl)
return `${apiURL.origin}${apiURL.pathname.replace(/\/api\/$/, '/share/')}${
link.slug
}`
return `${environment.baseUrl}share/${link.slug}`
}
getDaysRemaining(link: PaperlessShareLink): string {

View File

@ -2,7 +2,8 @@ const base_url = new URL(document.baseURI)
export const environment = {
production: true,
apiBaseUrl: document.baseURI + 'api/',
baseUrl: base_url,
apiBaseUrl: `${base_url}api/`,
apiVersion: '3',
appTitle: 'Paperless-ngx',
version: '2.1.0-dev',

View File

@ -4,6 +4,7 @@
export const environment = {
production: false,
baseUrl: 'http://localhost:8000/',
apiBaseUrl: 'http://localhost:8000/api/',
apiVersion: '3',
appTitle: 'Paperless-ngx',