Skip to content

Commit f6ca3df

Browse files
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 <[email protected]> Signed-off-by: nextcloud-command <[email protected]>
1 parent b5aac79 commit f6ca3df

File tree

3 files changed

+67
-78
lines changed

3 files changed

+67
-78
lines changed

js/text-public.js.LICENSE.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ object-assign
3333
* @license MIT
3434
*/
3535

36+
/*!
37+
* The buffer module from node.js, for the browser.
38+
*
39+
* @author Feross Aboukhadijeh <https://feross.org>
40+
* @license MIT
41+
*/
42+
3643
/*!
3744
* Vue.js v2.6.14
3845
* (c) 2014-2021 Evan You

src/helpers/files.js

Lines changed: 4 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ const registerFileActionFallback = () => {
136136
const FilesWorkspacePlugin = {
137137

138138
el: null,
139-
vm: null,
140139

141140
attach(fileList) {
142141
if (fileList.id !== 'files' && fileList.id !== 'files.public') {
@@ -150,51 +149,6 @@ const FilesWorkspacePlugin = {
150149
render: this.render.bind(this),
151150
priority: 10,
152151
})
153-
154-
const PROPERTY_WORKSPACE_FILE = `{${OC.Files.Client.NS_NEXTCLOUD}}rich-workspace-file`
155-
156-
const oldGetWebdavProperties = fileList._getWebdavProperties
157-
fileList._getWebdavProperties = function() {
158-
return [
159-
...oldGetWebdavProperties.apply(this, arguments),
160-
PROPERTY_WORKSPACE_FILE,
161-
]
162-
}
163-
164-
let readmeId = null
165-
166-
fileList.filesClient.addFileInfoParser((response, data) => {
167-
if (data.mimetype === 'httpd/unix-directory') {
168-
const props = response.propStat[0].properties
169-
const dir = data.path + (data.path.endsWith('/') ? '' : '/') + data.name
170-
if (dir === fileList.getCurrentDirectory()) {
171-
readmeId = props[PROPERTY_WORKSPACE_FILE]
172-
this.vm.folder = {
173-
permissions: data.permissions,
174-
}
175-
this.vm.loaded = true
176-
// in case no file is found we are done
177-
this.vm.ready = true
178-
}
179-
}
180-
if (readmeId && data.id === readmeId) {
181-
if (data.mimetype !== 'text/markdown') {
182-
console.warn('Expected workspace file to be markdown:', data)
183-
}
184-
this.open(data)
185-
return
186-
}
187-
/*
188-
* Handle the creation of 'Readme.md'.
189-
* The PROPFIND after the creation does not include the parent dir.
190-
*/
191-
if (data.name === 'Readme.md'
192-
&& data.mimetype === 'text/markdown'
193-
&& data.path === fileList.getCurrentDirectory()) {
194-
this.open(data)
195-
}
196-
})
197-
198152
},
199153

200154
render(fileList) {
@@ -209,37 +163,21 @@ const FilesWorkspacePlugin = {
209163
Vue.prototype.n = window.n
210164
Vue.prototype.OCA = window.OCA
211165
const View = Vue.extend(RichWorkspace)
212-
this.vm = new View({
166+
const vm = new View({
213167
propsData: {
214-
file: null,
215-
folder: null,
168+
path: fileList.getCurrentDirectory(),
216169
},
217170
store,
218171
}).$mount(this.el)
219172

220173
fileList.$el.on('urlChanged', data => {
221-
this.vm.file = null
222-
this.vm.folder = null
174+
vm.path = data.dir.toString()
223175
})
224176
fileList.$el.on('changeDirectory', data => {
225-
this.vm.file = null
226-
this.vm.folder = null
177+
vm.path = data.dir.toString()
227178
})
228179
})
229180
},
230-
231-
open(data) {
232-
const previous = this.vm.file
233-
const id = parseInt(data.id)
234-
this.vm.file = {
235-
...data,
236-
id,
237-
}
238-
if (previous?.id !== id) {
239-
// Editor loads new file. Wait for it to be ready.
240-
this.vm.ready = false
241-
}
242-
},
243181
}
244182

245183
export {

src/views/RichWorkspace.vue

Lines changed: 56 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
v-show="ready"
3333
:key="file.path"
3434
:file-id="file.id"
35-
:relative-path="filepath"
35+
:relative-path="file.path"
3636
:share-token="shareToken"
3737
:active="true"
3838
:autohide="true"
@@ -46,26 +46,29 @@
4646
</template>
4747

4848
<script>
49+
import axios from '@nextcloud/axios'
50+
import { generateOcsUrl } from '@nextcloud/router'
4951
import { subscribe } from '@nextcloud/event-bus'
5052
53+
const IS_PUBLIC = !!(document.getElementById('isPublic'))
54+
const WORKSPACE_URL = generateOcsUrl('apps/text' + (IS_PUBLIC ? '/public' : '') + '/workspace', 2)
55+
5156
export default {
5257
name: 'RichWorkspace',
5358
components: {
5459
EditorWrapper: () => import(/* webpackChunkName: "editor" */'./../components/EditorWrapper.vue'),
5560
},
5661
props: {
57-
file: {
58-
type: Object,
59-
default: null,
60-
},
61-
folder: {
62-
type: Object,
63-
default: null,
62+
path: {
63+
type: String,
64+
required: true,
6465
},
6566
},
6667
data() {
6768
return {
6869
focus: false,
70+
folder: null,
71+
file: null,
6972
loaded: false,
7073
ready: false,
7174
autofocus: false,
@@ -89,15 +92,22 @@ export default {
8992
},
9093
},
9194
watch: {
95+
path() {
96+
this.getFileInfo()
97+
},
9298
focus(newValue) {
9399
if (!newValue) {
94100
document.querySelector('#editor').scrollTo(0, 0)
95101
}
96102
},
97103
},
98104
async mounted() {
105+
if (this.enabled) {
106+
this.getFileInfo()
107+
}
99108
subscribe('Text::showRichWorkspace', () => {
100109
this.enabled = true
110+
this.getFileInfo()
101111
})
102112
subscribe('Text::hideRichWorkspace', () => {
103113
this.enabled = false
@@ -108,20 +118,54 @@ export default {
108118
// setTimeout(() => this.focus = false, 2000)
109119
},
110120
reset() {
121+
this.file = null
111122
this.focus = false
112123
this.$nextTick(() => {
113124
this.creating = false
125+
this.getFileInfo()
126+
})
127+
},
128+
getFileInfo() {
129+
this.loaded = false
130+
this.autofocus = false
131+
this.ready = false
132+
const params = { path: this.path }
133+
if (IS_PUBLIC) {
134+
params.shareToken = this.shareToken
135+
}
136+
return axios.get(WORKSPACE_URL, { params }).then((response) => {
137+
const data = response.data.ocs.data
138+
this.folder = data.folder || null
139+
this.file = data.file
140+
this.editing = true
141+
this.loaded = true
142+
return true
143+
}).catch((error) => {
144+
if (error.response.data.ocs && error.response.data.ocs.data.folder) {
145+
this.folder = error.response.data.ocs.data.folder
146+
} else {
147+
this.folder = null
148+
}
149+
this.file = null
150+
this.loaded = true
151+
this.ready = true
152+
this.creating = false
153+
return false
114154
})
115155
},
116156
createNew() {
117157
if (this.creating) {
118158
return
119159
}
120160
this.creating = true
121-
this.autofocus = true
122-
if (!this.file) {
123-
window.FileList.createFile('Readme.md', { scrollTo: false, animate: false })
124-
}
161+
this.getFileInfo().then((workspaceFileExists) => {
162+
this.autofocus = true
163+
if (!workspaceFileExists) {
164+
window.FileList.createFile('Readme.md', { scrollTo: false, animate: false }).then((status, data) => {
165+
this.getFileInfo()
166+
})
167+
}
168+
})
125169
},
126170
},
127171
}

0 commit comments

Comments
 (0)