Skip to content

Commit

Permalink
feat: Migrate to files:node:updated
Browse files Browse the repository at this point in the history
Signed-off-by: Luka Trovic <luka@nextcloud.com>
  • Loading branch information
luka-nextcloud committed Dec 13, 2024
1 parent 03ea77f commit 01ae49b
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
19 changes: 18 additions & 1 deletion src/components/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -246,6 +249,7 @@ export default {
document: null,
sessions: [],
currentSession: null,
fileNode: null,

filteredSessions: {},

Expand Down Expand Up @@ -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 }) {
Expand Down Expand Up @@ -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')
})
Expand Down
18 changes: 18 additions & 0 deletions src/services/WebdavClient.ts
Original file line number Diff line number Diff line change
@@ -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<Node> => {
const propfindPayload = davGetDefaultPropfind()
const result = await client.stat(`${davRootPath}${node.path}`, {
details: true,
data: propfindPayload,
}) as ResponseDataDetailed<FileStat>
return davResultToNode(result.data)
}

0 comments on commit 01ae49b

Please sign in to comment.