diff options
author | Max <max@nextcloud.com> | 2022-07-06 13:37:06 +0300 |
---|---|---|
committer | Jonas (Rebase PR Action) <jonas@freesources.org> | 2022-07-07 00:40:08 +0300 |
commit | bc23086d27cf081df67fa655dfad29c6d76b6901 (patch) | |
tree | 5a4e327de9ab6e8d26547206cc0663d63d931e58 | |
parent | b50b44f26f3b4ef137abd22a55436418519b0418 (diff) |
fix: use own workspace endpoint instead of PROPFIND properties
With a lot of subdirectories the depth=1 PROPFIND will take quite a long time.
It has to look for workspace files in all the subdirectories.
Stop overloading the PROPFIND and rely on our own workspace endpoint
for that particular directory instead.
Signed-off-by: Max <max@nextcloud.com>
Signed-off-by: nextcloud-command <nextcloud-command@users.noreply.github.com>
-rw-r--r-- | js/text-public.js.LICENSE.txt | 7 | ||||
-rw-r--r-- | src/helpers/files.js | 70 | ||||
-rw-r--r-- | src/views/RichWorkspace.vue | 68 |
3 files changed, 67 insertions, 78 deletions
diff --git a/js/text-public.js.LICENSE.txt b/js/text-public.js.LICENSE.txt index 0f3a4ff1b..74436c6cd 100644 --- a/js/text-public.js.LICENSE.txt +++ b/js/text-public.js.LICENSE.txt @@ -34,6 +34,13 @@ object-assign */ /*! + * The buffer module from node.js, for the browser. + * + * @author Feross Aboukhadijeh <https://feross.org> + * @license MIT + */ + +/*! * Vue.js v2.6.14 * (c) 2014-2021 Evan You * Released under the MIT License. diff --git a/src/helpers/files.js b/src/helpers/files.js index f4b5625d0..46a7b058b 100644 --- a/src/helpers/files.js +++ b/src/helpers/files.js @@ -136,7 +136,6 @@ const registerFileActionFallback = () => { const FilesWorkspacePlugin = { el: null, - vm: null, attach(fileList) { if (fileList.id !== 'files' && fileList.id !== 'files.public') { @@ -150,51 +149,6 @@ const FilesWorkspacePlugin = { render: this.render.bind(this), priority: 10, }) - - const PROPERTY_WORKSPACE_FILE = `{${OC.Files.Client.NS_NEXTCLOUD}}rich-workspace-file` - - const oldGetWebdavProperties = fileList._getWebdavProperties - fileList._getWebdavProperties = function() { - return [ - ...oldGetWebdavProperties.apply(this, arguments), - PROPERTY_WORKSPACE_FILE, - ] - } - - let readmeId = null - - fileList.filesClient.addFileInfoParser((response, data) => { - if (data.mimetype === 'httpd/unix-directory') { - const props = response.propStat[0].properties - const dir = data.path + (data.path.endsWith('/') ? '' : '/') + data.name - if (dir === fileList.getCurrentDirectory()) { - readmeId = props[PROPERTY_WORKSPACE_FILE] - this.vm.folder = { - permissions: data.permissions, - } - this.vm.loaded = true - // in case no file is found we are done - this.vm.ready = true - } - } - if (readmeId && data.id === readmeId) { - if (data.mimetype !== 'text/markdown') { - console.warn('Expected workspace file to be markdown:', data) - } - this.open(data) - return - } - /* - * Handle the creation of 'Readme.md'. - * The PROPFIND after the creation does not include the parent dir. - */ - if (data.name === 'Readme.md' - && data.mimetype === 'text/markdown' - && data.path === fileList.getCurrentDirectory()) { - this.open(data) - } - }) - }, render(fileList) { @@ -209,37 +163,21 @@ const FilesWorkspacePlugin = { Vue.prototype.n = window.n Vue.prototype.OCA = window.OCA const View = Vue.extend(RichWorkspace) - this.vm = new View({ + const vm = new View({ propsData: { - file: null, - folder: null, + path: fileList.getCurrentDirectory(), }, store, }).$mount(this.el) fileList.$el.on('urlChanged', data => { - this.vm.file = null - this.vm.folder = null + vm.path = data.dir.toString() }) fileList.$el.on('changeDirectory', data => { - this.vm.file = null - this.vm.folder = null + vm.path = data.dir.toString() }) }) }, - - open(data) { - const previous = this.vm.file - const id = parseInt(data.id) - this.vm.file = { - ...data, - id, - } - if (previous?.id !== id) { - // Editor loads new file. Wait for it to be ready. - this.vm.ready = false - } - }, } export { diff --git a/src/views/RichWorkspace.vue b/src/views/RichWorkspace.vue index f67a5d376..1d9f18eec 100644 --- a/src/views/RichWorkspace.vue +++ b/src/views/RichWorkspace.vue @@ -32,7 +32,7 @@ v-show="ready" :key="file.path" :file-id="file.id" - :relative-path="filepath" + :relative-path="file.path" :share-token="shareToken" :active="true" :autohide="true" @@ -46,26 +46,29 @@ </template> <script> +import axios from '@nextcloud/axios' +import { generateOcsUrl } from '@nextcloud/router' import { subscribe } from '@nextcloud/event-bus' +const IS_PUBLIC = !!(document.getElementById('isPublic')) +const WORKSPACE_URL = generateOcsUrl('apps/text' + (IS_PUBLIC ? '/public' : '') + '/workspace', 2) + export default { name: 'RichWorkspace', components: { EditorWrapper: () => import(/* webpackChunkName: "editor" */'./../components/EditorWrapper.vue'), }, props: { - file: { - type: Object, - default: null, - }, - folder: { - type: Object, - default: null, + path: { + type: String, + required: true, }, }, data() { return { focus: false, + folder: null, + file: null, loaded: false, ready: false, autofocus: false, @@ -89,6 +92,9 @@ export default { }, }, watch: { + path() { + this.getFileInfo() + }, focus(newValue) { if (!newValue) { document.querySelector('#editor').scrollTo(0, 0) @@ -96,8 +102,12 @@ export default { }, }, async mounted() { + if (this.enabled) { + this.getFileInfo() + } subscribe('Text::showRichWorkspace', () => { this.enabled = true + this.getFileInfo() }) subscribe('Text::hideRichWorkspace', () => { this.enabled = false @@ -108,9 +118,39 @@ export default { // setTimeout(() => this.focus = false, 2000) }, reset() { + this.file = null this.focus = false this.$nextTick(() => { this.creating = false + this.getFileInfo() + }) + }, + getFileInfo() { + this.loaded = false + this.autofocus = false + this.ready = false + const params = { path: this.path } + if (IS_PUBLIC) { + params.shareToken = this.shareToken + } + return axios.get(WORKSPACE_URL, { params }).then((response) => { + const data = response.data.ocs.data + this.folder = data.folder || null + this.file = data.file + this.editing = true + this.loaded = true + return true + }).catch((error) => { + if (error.response.data.ocs && error.response.data.ocs.data.folder) { + this.folder = error.response.data.ocs.data.folder + } else { + this.folder = null + } + this.file = null + this.loaded = true + this.ready = true + this.creating = false + return false }) }, createNew() { @@ -118,10 +158,14 @@ export default { return } this.creating = true - this.autofocus = true - if (!this.file) { - window.FileList.createFile('Readme.md', { scrollTo: false, animate: false }) - } + this.getFileInfo().then((workspaceFileExists) => { + this.autofocus = true + if (!workspaceFileExists) { + window.FileList.createFile('Readme.md', { scrollTo: false, animate: false }).then((status, data) => { + this.getFileInfo() + }) + } + }) }, }, } |