Merge pull request #55798 from nextcloud/backport/55750/stable32
[stable32] feat: add new link endpoint when using globalscalepull/55279/head
commit
d65eaa62c5
@ -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,
|
||||
})
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -0,0 +1 @@
|
||||
2357-2357.js.license
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1 +0,0 @@
|
||||
4981-4981.js.license
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue