Skip to content

Commit 01ae49b

Browse files
feat: Migrate to files:node:updated
Signed-off-by: Luka Trovic <[email protected]>
1 parent 03ea77f commit 01ae49b

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed

package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
"vue-click-outside": "^1.1.0",
108108
"vue-material-design-icons": "^5.3.1",
109109
"vuex": "^3.6.2",
110+
"webdav": "^5.7.1",
110111
"y-prosemirror": "^1.2.15",
111112
"y-protocols": "^1.0.6",
112113
"yjs": "^13.6.20"

src/components/Editor.vue

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ import { getCurrentUser } from '@nextcloud/auth'
7676
import { loadState } from '@nextcloud/initial-state'
7777
import { isPublicShare } from '@nextcloud/sharing/public'
7878
import { emit, subscribe, unsubscribe } from '@nextcloud/event-bus'
79+
import { File } from '@nextcloud/files'
7980
import { Collaboration } from '@tiptap/extension-collaboration'
8081
import Autofocus from '../extensions/Autofocus.js'
8182
import { Doc } from 'yjs'
@@ -121,6 +122,8 @@ import Wrapper from './Editor/Wrapper.vue'
121122
import SkeletonLoading from './SkeletonLoading.vue'
122123
import Assistant from './Assistant.vue'
123124
import Translate from './Modal/Translate.vue'
125+
import { generateRemoteUrl } from '@nextcloud/router'
126+
import { fetchNode } from '../services/WebdavClient.ts'
124127
125128
export default {
126129
name: 'Editor',
@@ -246,6 +249,7 @@ export default {
246249
document: null,
247250
sessions: [],
248251
currentSession: null,
252+
fileNode: null,
249253
250254
filteredSessions: {},
251255
@@ -515,6 +519,16 @@ export default {
515519
shareToken: this.shareToken,
516520
currentDirectory: this.currentDirectory,
517521
})
522+
if (this.currentSession?.userId && this.relativePath?.length) {
523+
const node = new File({
524+
id: this.fileId,
525+
source: generateRemoteUrl(`dav/files/${this.currentSession.userId}${this.relativePath}`),
526+
mime: this.mime,
527+
})
528+
fetchNode(node)
529+
.then((n) => { this.fileNode = n })
530+
.catch(err => logger.warn('Failed to fetch node', { err }))
531+
}
518532
},
519533
520534
onLoaded({ document, documentSource, documentState }) {
@@ -676,7 +690,10 @@ export default {
676690
},
677691
678692
onSave() {
679-
emit('files:file:updated', { fileid: this.fileId })
693+
if (this.fileNode) {
694+
this.fileNode.mtime = new Date()
695+
emit('files:node:updated', this.fileNode)
696+
}
680697
this.$nextTick(() => {
681698
this.emit('sync-service:save')
682699
})

src/services/WebdavClient.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
import { davGetClient, davGetDefaultPropfind, davResultToNode, davRootPath } from '@nextcloud/files'
6+
import type { FileStat, ResponseDataDetailed } from 'webdav'
7+
import type { Node } from '@nextcloud/files'
8+
9+
export const client = davGetClient()
10+
11+
export const fetchNode = async (node: Node): Promise<Node> => {
12+
const propfindPayload = davGetDefaultPropfind()
13+
const result = await client.stat(`${davRootPath}${node.path}`, {
14+
details: true,
15+
data: propfindPayload,
16+
}) as ResponseDataDetailed<FileStat>
17+
return davResultToNode(result.data)
18+
}

0 commit comments

Comments
 (0)