From 01ae49b33e1040367e462abe40faf0554f232163 Mon Sep 17 00:00:00 2001 From: Luka Trovic Date: Wed, 18 Sep 2024 18:56:45 +0200 Subject: [PATCH] feat: Migrate to files:node:updated Signed-off-by: Luka Trovic --- package-lock.json | 1 + package.json | 1 + src/components/Editor.vue | 19 ++++++++++++++++++- src/services/WebdavClient.ts | 18 ++++++++++++++++++ 4 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 src/services/WebdavClient.ts diff --git a/package-lock.json b/package-lock.json index d2a40bbd7df..4f4c86fe168 100644 --- a/package-lock.json +++ b/package-lock.json @@ -83,6 +83,7 @@ "vue-click-outside": "^1.1.0", "vue-material-design-icons": "^5.3.1", "vuex": "^3.6.2", + "webdav": "^5.7.1", "y-prosemirror": "^1.2.15", "y-protocols": "^1.0.6", "yjs": "^13.6.20" diff --git a/package.json b/package.json index 2206f3155d2..58d023677ba 100644 --- a/package.json +++ b/package.json @@ -107,6 +107,7 @@ "vue-click-outside": "^1.1.0", "vue-material-design-icons": "^5.3.1", "vuex": "^3.6.2", + "webdav": "^5.7.1", "y-prosemirror": "^1.2.15", "y-protocols": "^1.0.6", "yjs": "^13.6.20" diff --git a/src/components/Editor.vue b/src/components/Editor.vue index 8c3e59f4d21..01d02ba583a 100644 --- a/src/components/Editor.vue +++ b/src/components/Editor.vue @@ -76,6 +76,7 @@ import { getCurrentUser } from '@nextcloud/auth' import { loadState } from '@nextcloud/initial-state' import { isPublicShare } from '@nextcloud/sharing/public' import { emit, subscribe, unsubscribe } from '@nextcloud/event-bus' +import { File } from '@nextcloud/files' import { Collaboration } from '@tiptap/extension-collaboration' import Autofocus from '../extensions/Autofocus.js' import { Doc } from 'yjs' @@ -121,6 +122,8 @@ import Wrapper from './Editor/Wrapper.vue' import SkeletonLoading from './SkeletonLoading.vue' import Assistant from './Assistant.vue' import Translate from './Modal/Translate.vue' +import { generateRemoteUrl } from '@nextcloud/router' +import { fetchNode } from '../services/WebdavClient.ts' export default { name: 'Editor', @@ -246,6 +249,7 @@ export default { document: null, sessions: [], currentSession: null, + fileNode: null, filteredSessions: {}, @@ -515,6 +519,16 @@ export default { shareToken: this.shareToken, currentDirectory: this.currentDirectory, }) + if (this.currentSession?.userId && this.relativePath?.length) { + const node = new File({ + id: this.fileId, + source: generateRemoteUrl(`dav/files/${this.currentSession.userId}${this.relativePath}`), + mime: this.mime, + }) + fetchNode(node) + .then((n) => { this.fileNode = n }) + .catch(err => logger.warn('Failed to fetch node', { err })) + } }, onLoaded({ document, documentSource, documentState }) { @@ -676,7 +690,10 @@ export default { }, onSave() { - emit('files:file:updated', { fileid: this.fileId }) + if (this.fileNode) { + this.fileNode.mtime = new Date() + emit('files:node:updated', this.fileNode) + } this.$nextTick(() => { this.emit('sync-service:save') }) diff --git a/src/services/WebdavClient.ts b/src/services/WebdavClient.ts new file mode 100644 index 00000000000..cd33147b03f --- /dev/null +++ b/src/services/WebdavClient.ts @@ -0,0 +1,18 @@ +/** + * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +import { davGetClient, davGetDefaultPropfind, davResultToNode, davRootPath } from '@nextcloud/files' +import type { FileStat, ResponseDataDetailed } from 'webdav' +import type { Node } from '@nextcloud/files' + +export const client = davGetClient() + +export const fetchNode = async (node: Node): Promise => { + const propfindPayload = davGetDefaultPropfind() + const result = await client.stat(`${davRootPath}${node.path}`, { + details: true, + data: propfindPayload, + }) as ResponseDataDetailed + return davResultToNode(result.data) +}