Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions apps/files/src/views/FileReferencePickerElement.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import type { Node as NcNode } from '@nextcloud/files'

import { FilePickerBuilder } from '@nextcloud/dialogs'
import { t } from '@nextcloud/l10n'
import { generateUrl } from '@nextcloud/router'
import { onMounted } from 'vue'
import { generateFileUrl } from '../../../files_sharing/src/utils/generateUrl.ts'
import logger from '../logger.ts'

defineProps<{
Expand Down Expand Up @@ -74,9 +74,6 @@ function buttonFactory(selected: NcNode[]): IFilePickerButton[] {
* @param node - selected node
*/
function onSubmit(node: NcNode) {
const url = new URL(window.location.href)
url.pathname = generateUrl('/f/{fileId}', { fileId: node.fileid! })
url.search = ''
emit('submit', url.href)
emit('submit', generateFileUrl(node.fileid!))
}
</script>
9 changes: 4 additions & 5 deletions apps/files/src/views/ReferenceFileWidget.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import path from 'path'
import { defineComponent } from 'vue'
import FileIcon from 'vue-material-design-icons/File.vue'
import FolderIcon from 'vue-material-design-icons/Folder.vue'
import { generateFileUrl } from '../../../files_sharing/src/utils/generateUrl.ts'
import logger from '../logger.ts'

// see lib/private/Collaboration/Reference/File/FileReferenceProvider.php
Expand Down Expand Up @@ -234,11 +235,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',
Expand Down
6 changes: 2 additions & 4 deletions apps/files_sharing/src/components/SharingEntryInherited.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@

<script>
import { basename } from '@nextcloud/paths'
import { generateUrl } from '@nextcloud/router'
import NcActionButton from '@nextcloud/vue/components/NcActionButton'
import NcActionLink from '@nextcloud/vue/components/NcActionLink'
import NcActionText from '@nextcloud/vue/components/NcActionText'
import NcAvatar from '@nextcloud/vue/components/NcAvatar'
import SharingEntrySimple from '../components/SharingEntrySimple.vue'
import SharesMixin from '../mixins/SharesMixin.js'
import Share from '../models/Share.js'
import { generateFileUrl } from '../utils/generateUrl.js'

export default {
name: 'SharingEntryInherited',
Expand All @@ -65,9 +65,7 @@ export default {

computed: {
viaFileTargetUrl() {
return generateUrl('/f/{fileid}', {
fileid: this.share.viaFileid,
})
return generateFileUrl(this.share.viaFileid)
},

viaFolderName() {
Expand Down
4 changes: 2 additions & 2 deletions apps/files_sharing/src/components/SharingEntryInternal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@

<script>
import { showSuccess } from '@nextcloud/dialogs'
import { generateUrl } from '@nextcloud/router'
import NcActionButton from '@nextcloud/vue/components/NcActionButton'
import CheckIcon from 'vue-material-design-icons/Check.vue'
import ClipboardIcon from 'vue-material-design-icons/ContentCopy.vue'
import SharingEntrySimple from './SharingEntrySimple.vue'
import logger from '../services/logger.ts'
import { generateFileUrl } from '../utils/generateUrl.ts'

export default {
name: 'SharingEntryInternal',
Expand Down Expand Up @@ -69,7 +69,7 @@ export default {
* @return {string}
*/
internalLink() {
return window.location.protocol + '//' + window.location.host + generateUrl('/f/') + this.fileInfo.id
return generateFileUrl(this.fileInfo.id)
},

/**
Expand Down
30 changes: 30 additions & 0 deletions apps/files_sharing/src/utils/generateUrl.spec.ts
Original file line number Diff line number Diff line change
@@ -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 changes: 32 additions & 0 deletions apps/files_sharing/src/utils/generateUrl.ts
Original file line number Diff line number Diff line change
@@ -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 changes: 0 additions & 2 deletions dist/1814-1814.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/1814-1814.js.map

This file was deleted.

1 change: 0 additions & 1 deletion dist/1814-1814.js.map.license

This file was deleted.

2 changes: 2 additions & 0 deletions dist/8906-8906.js

Large diffs are not rendered by default.

File renamed without changes.
1 change: 1 addition & 0 deletions dist/8906-8906.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/8906-8906.js.map.license
4 changes: 2 additions & 2 deletions dist/files-reference-files.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/files-reference-files.js.map

Large diffs are not rendered by default.

Loading
Loading