]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
Fix: share links for URLs containing 'api' incorrect in dropdown (#4701)
authorshamoon <4887959+shamoon@users.noreply.github.com>
Wed, 29 Nov 2023 19:10:55 +0000 (11:10 -0800)
committerGitHub <noreply@github.com>
Wed, 29 Nov 2023 19:10:55 +0000 (11:10 -0800)
src-ui/src/app/components/common/share-links-dropdown/share-links-dropdown.component.spec.ts
src-ui/src/app/components/common/share-links-dropdown/share-links-dropdown.component.ts

index 0abcd4e7c2a0294f523098827a4dfb25447df473..27955a8a5e566f81d8c0c2b5d43260d4f8e1affb 100644 (file)
@@ -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'
+    )
+  })
 })
index 3aff4823dbf79722856e6ba3b972a8c9aac0a63f..fa2df3a54b1741432c973b7b640a8d8f1b085c55 100644 (file)
@@ -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 {