diff --git a/src-ui/src/app/components/common/share-links-dropdown/share-links-dropdown.component.spec.ts b/src-ui/src/app/components/common/share-links-dropdown/share-links-dropdown.component.spec.ts index 0abcd4e7c..27955a8a5 100644 --- a/src-ui/src/app/components/common/share-links-dropdown/share-links-dropdown.component.spec.ts +++ b/src-ui/src/app/components/common/share-links-dropdown/share-links-dropdown.component.spec.ts @@ -192,4 +192,24 @@ describe('ShareLinksDropdownComponent', () => { component.share(link) // expect(navigatorSpy).toHaveBeenCalledWith({ url: component.getShareUrl(link) }) }) + + it('should correctly generate share URLs', () => { + environment.apiBaseUrl = 'http://example.com/api/' + expect(component.getShareUrl({ slug: '123abc123' } as any)).toEqual( + 'http://example.com/share/123abc123' + ) + environment.apiBaseUrl = 'http://example.domainwithapiinit.com/api/' + expect(component.getShareUrl({ slug: '123abc123' } as any)).toEqual( + 'http://example.domainwithapiinit.com/share/123abc123' + ) + environment.apiBaseUrl = 'http://example.domainwithapiinit.com:1234/api/' + expect(component.getShareUrl({ slug: '123abc123' } as any)).toEqual( + 'http://example.domainwithapiinit.com:1234/share/123abc123' + ) + environment.apiBaseUrl = + 'http://example.domainwithapiinit.com:1234/subpath/api/' + expect(component.getShareUrl({ slug: '123abc123' } as any)).toEqual( + 'http://example.domainwithapiinit.com:1234/subpath/share/123abc123' + ) + }) }) diff --git a/src-ui/src/app/components/common/share-links-dropdown/share-links-dropdown.component.ts b/src-ui/src/app/components/common/share-links-dropdown/share-links-dropdown.component.ts index 3aff4823d..fa2df3a54 100644 --- a/src-ui/src/app/components/common/share-links-dropdown/share-links-dropdown.component.ts +++ b/src-ui/src/app/components/common/share-links-dropdown/share-links-dropdown.component.ts @@ -80,7 +80,10 @@ export class ShareLinksDropdownComponent implements OnInit { } getShareUrl(link: PaperlessShareLink): string { - return `${environment.apiBaseUrl.replace('api', 'share')}${link.slug}` + const apiURL = new URL(environment.apiBaseUrl) + return `${apiURL.origin}${apiURL.pathname.replace(/\/api\/$/, '/share/')}${ + link.slug + }` } getDaysRemaining(link: PaperlessShareLink): string {