Skip to content

Commit ccb3c09

Browse files
max-nextcloudjuliusknorr
authored andcommitted
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>
1 parent 329b9b7 commit ccb3c09

File tree

2 files changed

+61
-88
lines changed

2 files changed

+61
-88
lines changed

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: 57 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,41 +32,44 @@
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
:mime="file.mimetype"
3838
:autofocus="autofocus"
3939
active
4040
autohide
4141
rich-workspace
42-
@ready="ready=true; loaded=true"
42+
@ready="ready=true"
4343
@focus="focus=true"
4444
@blur="unfocus"
4545
@error="reset" />
4646
</div>
4747
</template>
4848

4949
<script>
50+
import axios from '@nextcloud/axios'
51+
import { generateOcsUrl } from '@nextcloud/router'
5052
import { subscribe } from '@nextcloud/event-bus'
5153
54+
const IS_PUBLIC = !!(document.getElementById('isPublic'))
55+
const WORKSPACE_URL = generateOcsUrl('apps/text' + (IS_PUBLIC ? '/public' : '') + '/workspace', 2)
56+
5257
export default {
5358
name: 'RichWorkspace',
5459
components: {
5560
EditorWrapper: () => import(/* webpackChunkName: "editor" */'./../components/EditorWrapper.vue'),
5661
},
5762
props: {
58-
file: {
59-
type: Object,
60-
default: null,
61-
},
62-
folder: {
63-
type: Object,
64-
default: null,
63+
path: {
64+
type: String,
65+
required: true,
6566
},
6667
},
6768
data() {
6869
return {
6970
focus: false,
71+
folder: null,
72+
file: null,
7073
loaded: false,
7174
ready: false,
7275
autofocus: false,
@@ -84,26 +87,24 @@ export default {
8487
showEmptyWorkspace() {
8588
return (!this.file || (this.autofocus && !this.ready)) && this.canCreate
8689
},
87-
filepath() {
88-
const { path, name } = this.file || {}
89-
if (!path) {
90-
return undefined
91-
}
92-
93-
return path + (path.endsWith('/') ? '' : '/') + name
94-
},
9590
},
9691
watch: {
92+
path() {
93+
this.getFileInfo()
94+
},
9795
focus(newValue) {
9896
if (!newValue) {
99-
// TODO: change
10097
document.querySelector('#editor').scrollTo(0, 0)
10198
}
10299
},
103100
},
104101
async mounted() {
102+
if (this.enabled) {
103+
this.getFileInfo()
104+
}
105105
subscribe('Text::showRichWorkspace', () => {
106106
this.enabled = true
107+
this.getFileInfo()
107108
})
108109
subscribe('Text::hideRichWorkspace', () => {
109110
this.enabled = false
@@ -114,20 +115,54 @@ export default {
114115
// setTimeout(() => this.focus = false, 2000)
115116
},
116117
reset() {
118+
this.file = null
117119
this.focus = false
118120
this.$nextTick(() => {
119121
this.creating = false
122+
this.getFileInfo()
123+
})
124+
},
125+
getFileInfo() {
126+
this.loaded = false
127+
this.autofocus = false
128+
this.ready = false
129+
const params = { path: this.path }
130+
if (IS_PUBLIC) {
131+
params.shareToken = this.shareToken
132+
}
133+
return axios.get(WORKSPACE_URL, { params }).then((response) => {
134+
const data = response.data.ocs.data
135+
this.folder = data.folder || null
136+
this.file = data.file
137+
this.editing = true
138+
this.loaded = true
139+
return true
140+
}).catch((error) => {
141+
if (error.response.data.ocs && error.response.data.ocs.data.folder) {
142+
this.folder = error.response.data.ocs.data.folder
143+
} else {
144+
this.folder = null
145+
}
146+
this.file = null
147+
this.loaded = true
148+
this.ready = true
149+
this.creating = false
150+
return false
120151
})
121152
},
122153
createNew() {
123154
if (this.creating) {
124155
return
125156
}
126157
this.creating = true
127-
this.autofocus = true
128-
if (!this.file) {
129-
window.FileList.createFile('Readme.md', { scrollTo: false, animate: false })
130-
}
158+
this.getFileInfo().then((workspaceFileExists) => {
159+
this.autofocus = true
160+
if (!workspaceFileExists) {
161+
window.FileList.createFile('Readme.md', { scrollTo: false, animate: false }).then((status, data) => {
162+
this.getFileInfo()
163+
})
164+
}
165+
})
131166
},
132167
},
133168
}

0 commit comments

Comments
 (0)