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 @@ -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',
Expand Down Expand Up @@ -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!))
},
},
})
Expand Down
9 changes: 4 additions & 5 deletions apps/files/src/views/ReferenceFileWidget.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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',
Expand Down
8 changes: 2 additions & 6 deletions apps/files_sharing/src/components/SharingEntryInherited.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -63,9 +61,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 @@ -27,14 +27,14 @@
</template>

<script>
import { generateUrl } from '@nextcloud/router'
import { showSuccess } from '@nextcloud/dialogs'
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 { generateFileUrl } from '../utils/generateUrl.ts'

export default {
name: 'SharingEntryInternal',
Expand Down Expand Up @@ -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)
},

/**
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: 2 additions & 0 deletions dist/2357-2357.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/2357-2357.js.map.license
2 changes: 0 additions & 2 deletions dist/4981-4981.js

This file was deleted.

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

This file was deleted.

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

This file was deleted.

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.

4 changes: 2 additions & 2 deletions dist/files_sharing-files_sharing_tab.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/files_sharing-files_sharing_tab.js.map

Large diffs are not rendered by default.

Loading