Skip to content

Commit c0df7e5

Browse files
moodyjmzbackportbot[bot]
authored andcommitted
fix: 🐛 Update SaveAs component to use Config service for saveAs checking
Signed-off-by: James Manuel <moodyjmz@users.noreply.github.com>
1 parent 1985835 commit c0df7e5

1 file changed

Lines changed: 34 additions & 20 deletions

File tree

src/components/Modal/SaveAs.vue

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,15 @@
3131
<script>
3232
import { translate as t } from '@nextcloud/l10n'
3333
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'
3536
import { emit } from '@nextcloud/event-bus'
37+
import { isPublicShare, getSharingToken } from '@nextcloud/sharing/public'
3638
3739
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
3840
import NcModal from '@nextcloud/vue/dist/Components/NcModal.js'
3941
import NcTextField from '@nextcloud/vue/dist/Components/NcTextField.js'
40-
42+
import Config from '../../services/config.tsx'
4143
export default {
4244
name: 'SaveAs',
4345
components: {
@@ -75,6 +77,12 @@ export default {
7577
}
7678
},
7779
computed: {
80+
rootPath() {
81+
if (isPublicShare()) {
82+
return `/files/${getSharingToken()}`
83+
}
84+
return `/files/${getCurrentUser()?.uid ?? Config.get('userId')}`
85+
},
7886
newFileName: {
7987
get() {
8088
if (this.selectedPath !== '') {
@@ -113,25 +121,31 @@ export default {
113121
const client = getClient()
114122
const filename = this.newFileName
115123
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+
})
121134
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+
}
135149
}
136150
}
137151

0 commit comments

Comments
 (0)