Browse Source
feat: add new link endpoint when using globalscale
feat: add new link endpoint when using globalscale
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>pull/55750/head
committed by
nextcloud-command
6 changed files with 72 additions and 16 deletions
-
7apps/files/src/views/FileReferencePickerElement.vue
-
9apps/files/src/views/ReferenceFileWidget.vue
-
6apps/files_sharing/src/components/SharingEntryInherited.vue
-
4apps/files_sharing/src/components/SharingEntryInternal.vue
-
30apps/files_sharing/src/utils/generateUrl.spec.ts
-
32apps/files_sharing/src/utils/generateUrl.ts
@ -0,0 +1,30 @@ |
|||
/** |
|||
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors |
|||
* SPDX-License-Identifier: AGPL-3.0-or-later |
|||
*/ |
|||
|
|||
import { describe, expect, it, vi } from 'vitest' |
|||
import { generateFileUrl } from './generateUrl.ts' |
|||
|
|||
const getCapabilities = vi.hoisted(() => vi.fn()) |
|||
vi.mock('@nextcloud/capabilities', () => ({ getCapabilities })) |
|||
|
|||
describe('generateFileUrl', () => { |
|||
it('should work without globalscale', () => { |
|||
getCapabilities.mockReturnValue({ globalscale: null }) |
|||
const url = generateFileUrl(12345) |
|||
expect(url).toBe('http://nextcloud.local/index.php/f/12345') |
|||
}) |
|||
|
|||
it('should work with older globalscale', () => { |
|||
getCapabilities.mockReturnValue({ globalscale: { enabled: true } }) |
|||
const url = generateFileUrl(12345) |
|||
expect(url).toBe('http://nextcloud.local/index.php/f/12345') |
|||
}) |
|||
|
|||
it('should work with globalscale', () => { |
|||
getCapabilities.mockReturnValue({ globalscale: { enabled: true, token: 'abc123' } }) |
|||
const url = generateFileUrl(12345) |
|||
expect(url).toBe('http://nextcloud.local/index.php/gf/abc123/12345') |
|||
}) |
|||
}) |
|||
@ -0,0 +1,32 @@ |
|||
/** |
|||
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors |
|||
* SPDX-License-Identifier: AGPL-3.0-or-later |
|||
*/ |
|||
|
|||
import { getCapabilities } from '@nextcloud/capabilities' |
|||
import { generateUrl } from '@nextcloud/router' |
|||
|
|||
interface IGlobalScaleCapabilities { |
|||
token?: string |
|||
} |
|||
|
|||
/** |
|||
* @param fileid - The file ID to generate the direct file link for |
|||
*/ |
|||
export function generateFileUrl(fileid: number): string { |
|||
const baseURL = window.location.protocol + '//' + window.location.host |
|||
|
|||
const { globalscale } = getCapabilities() as { globalscale?: IGlobalScaleCapabilities } |
|||
if (globalscale?.token) { |
|||
return generateUrl('/gf/{token}/{fileid}', { |
|||
token: globalscale.token, |
|||
fileid, |
|||
}, { baseURL }) |
|||
} |
|||
|
|||
return generateUrl('/f/{fileid}', { |
|||
fileid, |
|||
}, { |
|||
baseURL, |
|||
}) |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue