mirror of
https://github.com/nextcloud/server.git
synced 2026-04-26 16:48:59 -04:00
Merge pull request #55798 from nextcloud/backport/55750/stable32
[stable32] feat: add new link endpoint when using globalscale
This commit is contained in:
commit
d65eaa62c5
17 changed files with 82 additions and 28 deletions
|
|
@ -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!))
|
||||
},
|
||||
},
|
||||
})
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
|||
30
apps/files_sharing/src/utils/generateUrl.spec.ts
Normal file
30
apps/files_sharing/src/utils/generateUrl.spec.ts
Normal 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')
|
||||
})
|
||||
})
|
||||
32
apps/files_sharing/src/utils/generateUrl.ts
Normal file
32
apps/files_sharing/src/utils/generateUrl.ts
Normal 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
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
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
1
dist/2357-2357.js.map.license
vendored
Symbolic link
|
|
@ -0,0 +1 @@
|
|||
2357-2357.js.license
|
||||
2
dist/4981-4981.js
vendored
2
dist/4981-4981.js
vendored
File diff suppressed because one or more lines are too long
1
dist/4981-4981.js.map
vendored
1
dist/4981-4981.js.map
vendored
File diff suppressed because one or more lines are too long
1
dist/4981-4981.js.map.license
vendored
1
dist/4981-4981.js.map.license
vendored
|
|
@ -1 +0,0 @@
|
|||
4981-4981.js.license
|
||||
4
dist/files-reference-files.js
vendored
4
dist/files-reference-files.js
vendored
File diff suppressed because one or more lines are too long
2
dist/files-reference-files.js.map
vendored
2
dist/files-reference-files.js.map
vendored
File diff suppressed because one or more lines are too long
4
dist/files_sharing-files_sharing_tab.js
vendored
4
dist/files_sharing-files_sharing_tab.js
vendored
File diff suppressed because one or more lines are too long
2
dist/files_sharing-files_sharing_tab.js.map
vendored
2
dist/files_sharing-files_sharing_tab.js.map
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue