Merge pull request #55798 from nextcloud/backport/55750/stable32

[stable32] feat: add new link endpoint when using globalscale
This commit is contained in:
Andy Scherzinger 2025-10-16 00:43:42 +02:00 committed by GitHub
commit d65eaa62c5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 82 additions and 28 deletions

View file

@ -15,8 +15,8 @@ import type { IFilePickerButton } from '@nextcloud/dialogs'
import { FilePickerVue as FilePicker } from '@nextcloud/dialogs/filepicker.js'
import { translate as t } from '@nextcloud/l10n'
import { generateUrl } from '@nextcloud/router'
import { defineComponent } from 'vue'
import { generateFileUrl } from '../../../files_sharing/src/utils/generateUrl'
export default defineComponent({
name: 'FileReferencePickerElement',
@ -76,10 +76,7 @@ export default defineComponent({
},
onSubmit(node: NcNode) {
const url = new URL(window.location.href)
url.pathname = generateUrl('/f/{fileId}', { fileId: node.fileid! })
url.search = ''
this.$emit('submit', url.href)
this.$emit('submit', generateFileUrl(node.fileid!))
},
},
})

View file

@ -62,6 +62,7 @@ import { Node } from '@nextcloud/files'
import FileIcon from 'vue-material-design-icons/File.vue'
import FolderIcon from 'vue-material-design-icons/Folder.vue'
import path from 'path'
import { generateFileUrl } from '../../../files_sharing/src/utils/generateUrl.ts'
// see lib/private/Collaboration/Reference/File/FileReferenceProvider.php
type Ressource = {
@ -218,11 +219,9 @@ export default defineComponent({
.addButton({
id: 'open',
label: this.t('settings', 'Open in files'),
callback(nodes: Node[]) {
if (nodes[0]) {
window.open(generateUrl('/f/{fileid}', {
fileid: nodes[0].fileid,
}))
callback([node]: Node[]) {
if (node) {
window.open(generateFileUrl(node.fileid!))
}
},
type: 'primary',

View file

@ -29,17 +29,15 @@
</template>
<script>
import { generateUrl } from '@nextcloud/router'
import { basename } from '@nextcloud/paths'
import NcAvatar from '@nextcloud/vue/components/NcAvatar'
import NcActionButton from '@nextcloud/vue/components/NcActionButton'
import NcActionLink from '@nextcloud/vue/components/NcActionLink'
import NcActionText from '@nextcloud/vue/components/NcActionText'
// eslint-disable-next-line no-unused-vars
import Share from '../models/Share.js'
import SharesMixin from '../mixins/SharesMixin.js'
import SharingEntrySimple from '../components/SharingEntrySimple.vue'
import { generateFileUrl } from '../utils/generateUrl.js'
export default {
name: 'SharingEntryInherited',
@ -63,9 +61,7 @@ export default {
computed: {
viaFileTargetUrl() {
return generateUrl('/f/{fileid}', {
fileid: this.share.viaFileid,
})
return generateFileUrl(this.share.viaFileid)
},
viaFolderName() {

View file

@ -27,7 +27,6 @@
</template>
<script>
import { generateUrl } from '@nextcloud/router'
import { showSuccess } from '@nextcloud/dialogs'
import NcActionButton from '@nextcloud/vue/components/NcActionButton'
@ -35,6 +34,7 @@ import CheckIcon from 'vue-material-design-icons/Check.vue'
import ClipboardIcon from 'vue-material-design-icons/ContentCopy.vue'
import SharingEntrySimple from './SharingEntrySimple.vue'
import { generateFileUrl } from '../utils/generateUrl.ts'
export default {
name: 'SharingEntryInternal',
@ -68,7 +68,7 @@ export default {
* @return {string}
*/
internalLink() {
return window.location.protocol + '//' + window.location.host + generateUrl('/f/') + this.fileInfo.id
return generateFileUrl(this.fileInfo.id)
},
/**

View file

@ -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')
})
})

View file

@ -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,
})
}

2
dist/2357-2357.js vendored Normal file

File diff suppressed because one or more lines are too long

1
dist/2357-2357.js.map vendored Normal file

File diff suppressed because one or more lines are too long

1
dist/2357-2357.js.map.license vendored Symbolic link
View file

@ -0,0 +1 @@
2357-2357.js.license

2
dist/4981-4981.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -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