Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable30] feat: Migrate to files:node:updated #6853

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.21"
Expand Down
19 changes: 18 additions & 1 deletion src/components/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ import Vue, { ref, set, watch } from 'vue'
import { getCurrentUser } from '@nextcloud/auth'
import { loadState } from '@nextcloud/initial-state'
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 @@ -114,6 +115,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 @@ -239,6 +242,7 @@ export default {
document: null,
sessions: [],
currentSession: null,
fileNode: null,

filteredSessions: {},

Expand Down Expand Up @@ -494,6 +498,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 @@ -652,7 +666,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)
}
Loading