Skip to content

Commit a955382

Browse files
authored
Merge pull request #56409 from nextcloud/fix/webroot-public-link
fix(files_sharing): use webroot for public links
2 parents 6c83be9 + e768070 commit a955382

File tree

8 files changed

+24
-12
lines changed

8 files changed

+24
-12
lines changed

apps/files_sharing/src/utils/generateUrl.spec.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,25 @@
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
55

6-
import { describe, expect, it, vi } from 'vitest'
6+
import { beforeEach, describe, expect, it, vi } from 'vitest'
77
import { generateFileUrl } from './generateUrl.ts'
88

99
const getCapabilities = vi.hoisted(() => vi.fn())
1010
vi.mock('@nextcloud/capabilities', () => ({ getCapabilities }))
1111

1212
describe('generateFileUrl', () => {
13+
beforeEach(() => window._oc_webroot = '')
14+
15+
/**
16+
* Regression test of https://github.com/nextcloud/server/issues/56374
17+
*/
18+
it('should work without globalscale and webroot', () => {
19+
window._oc_webroot = '/nextcloud'
20+
getCapabilities.mockReturnValue({ globalscale: null })
21+
const url = generateFileUrl(12345)
22+
expect(url).toBe('http://nextcloud.local/nextcloud/index.php/f/12345')
23+
})
24+
1325
it('should work without globalscale', () => {
1426
getCapabilities.mockReturnValue({ globalscale: null })
1527
const url = generateFileUrl(12345)

apps/files_sharing/src/utils/generateUrl.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
import { getCapabilities } from '@nextcloud/capabilities'
7-
import { generateUrl } from '@nextcloud/router'
7+
import { generateUrl, getBaseUrl } from '@nextcloud/router'
88

99
interface IGlobalScaleCapabilities {
1010
token?: string
@@ -14,7 +14,7 @@ interface IGlobalScaleCapabilities {
1414
* @param fileid - The file ID to generate the direct file link for
1515
*/
1616
export function generateFileUrl(fileid: number): string {
17-
const baseURL = window.location.protocol + '//' + window.location.host
17+
const baseURL = getBaseUrl()
1818

1919
const { globalscale } = getCapabilities() as { globalscale?: IGlobalScaleCapabilities }
2020
if (globalscale?.token) {

dist/5660-5660.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/5660-5660.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/files-reference-files.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/files-reference-files.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/files_sharing-files_sharing_tab.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/files_sharing-files_sharing_tab.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)