feat: add new link endpoint when using globalscale
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>pull/55750/head
parent
50f287402a
commit
7fbc2ca25e
@ -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,
|
||||||
|
})
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue