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

feat: Migrate to files:node:updated #6427

Merged
merged 1 commit into from
Dec 13, 2024
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.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 { loadState } from '@nextcloud/initial-state'
import { isPublicShare } from '@nextcloud/sharing/public'
import { emit, subscribe, unsubscribe } from '@nextcloud/event-bus'
import { File } from '@nextcloud/files'

Check warning on line 79 in src/components/Editor.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor.vue#L79

Added line #L79 was not covered by tests
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 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'

Check warning on line 126 in src/components/Editor.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor.vue#L125-L126

Added lines #L125 - L126 were not covered by tests

export default {
name: 'Editor',
Expand Down Expand Up @@ -246,6 +249,7 @@
document: null,
sessions: [],
currentSession: null,
fileNode: null,

Check warning on line 252 in src/components/Editor.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor.vue#L252

Added line #L252 was not covered by tests

filteredSessions: {},

Expand Down Expand Up @@ -515,6 +519,16 @@
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 }))
}

Check warning on line 531 in src/components/Editor.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor.vue#L522-L531

Added lines #L522 - L531 were not covered by tests
},

onLoaded({ document, documentSource, documentState }) {
Expand Down Expand Up @@ -676,7 +690,10 @@
},

onSave() {
emit('files:file:updated', { fileid: this.fileId })
if (this.fileNode) {
this.fileNode.mtime = new Date()
emit('files:node:updated', this.fileNode)
}

Check warning on line 696 in src/components/Editor.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor.vue#L693-L696

Added lines #L693 - L696 were not covered by tests
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()

Check warning on line 9 in src/services/WebdavClient.ts

View check run for this annotation

Codecov / codecov/patch

src/services/WebdavClient.ts#L9

Added line #L9 was not covered by tests

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)
}

Check warning on line 18 in src/services/WebdavClient.ts

View check run for this annotation

Codecov / codecov/patch

src/services/WebdavClient.ts#L11-L18

Added lines #L11 - L18 were not covered by tests
Loading