|
31 | 31 | <script> |
32 | 32 | import { translate as t } from '@nextcloud/l10n' |
33 | 33 | import { showError } from '@nextcloud/dialogs' |
34 | | -import { getClient, getDefaultPropfind, resultToNode, defaultRootPath } from '@nextcloud/files/dav' |
| 34 | +import { getCurrentUser } from '@nextcloud/auth' |
| 35 | +import { getClient, getDefaultPropfind, resultToNode } from '@nextcloud/files/dav' |
35 | 36 | import { emit } from '@nextcloud/event-bus' |
| 37 | +import { isPublicShare, getSharingToken } from '@nextcloud/sharing/public' |
36 | 38 |
|
37 | 39 | import NcButton from '@nextcloud/vue/dist/Components/NcButton.js' |
38 | 40 | import NcModal from '@nextcloud/vue/dist/Components/NcModal.js' |
39 | 41 | import NcTextField from '@nextcloud/vue/dist/Components/NcTextField.js' |
40 | | -
|
| 42 | +import Config from '../../services/config.tsx' |
41 | 43 | export default { |
42 | 44 | name: 'SaveAs', |
43 | 45 | components: { |
@@ -75,6 +77,12 @@ export default { |
75 | 77 | } |
76 | 78 | }, |
77 | 79 | computed: { |
| 80 | + rootPath() { |
| 81 | + if (isPublicShare()) { |
| 82 | + return `/files/${getSharingToken()}` |
| 83 | + } |
| 84 | + return `/files/${getCurrentUser()?.uid ?? Config.get('userId')}` |
| 85 | + }, |
78 | 86 | newFileName: { |
79 | 87 | get() { |
80 | 88 | if (this.selectedPath !== '') { |
@@ -113,25 +121,31 @@ export default { |
113 | 121 | const client = getClient() |
114 | 122 | const filename = this.newFileName |
115 | 123 |
|
116 | | - try { |
117 | | - const result = await client.stat(`${defaultRootPath}${filename}`, { |
118 | | - details: true, |
119 | | - data: getDefaultPropfind(), |
120 | | - }) |
| 124 | + // In direct editing sessions there is no authenticated DAV session |
| 125 | + // so we skip the existence check and let the backend handle conflicts. |
| 126 | + // A future improvement could use a dedicated API endpoint that validates |
| 127 | + // the WOPI token and checks file existence on behalf of the user. |
| 128 | + if (!Config.get('direct')) { |
| 129 | + try { |
| 130 | + const result = await client.stat(`${this.rootPath}/${filename}`, { |
| 131 | + details: true, |
| 132 | + data: getDefaultPropfind(), |
| 133 | + }) |
121 | 134 |
|
122 | | - if (result) { |
123 | | - showError(t('richdocuments', 'A file with that name already exists.')) |
124 | | - const node = resultToNode(result.data) |
125 | | - emit('files:node:updated', node) |
126 | | - this.isChecking = false |
127 | | - return |
128 | | - } |
129 | | - } catch (error) { |
130 | | - if (error.response?.status !== 404) { |
131 | | - console.error('Error checking file existence:', error) |
132 | | - showError(t('richdocuments', 'Error checking if file exists.')) |
133 | | - this.isChecking = false |
134 | | - return |
| 135 | + if (result) { |
| 136 | + showError(t('richdocuments', 'A file with that name already exists.')) |
| 137 | + const node = resultToNode(result.data) |
| 138 | + emit('files:node:updated', node) |
| 139 | + this.isChecking = false |
| 140 | + return |
| 141 | + } |
| 142 | + } catch (error) { |
| 143 | + if (error.response?.status !== 404) { |
| 144 | + console.error('Error checking file existence:', error) |
| 145 | + showError(t('richdocuments', 'Error checking if file exists.')) |
| 146 | + this.isChecking = false |
| 147 | + return |
| 148 | + } |
135 | 149 | } |
136 | 150 | } |
137 | 151 |
|
|
0 commit comments