Skip to content

Commit 12df66f

Browse files
Merge pull request #2677 from nextcloud/fix/stop-using-propfind-for-workspace
fix: use own workspace endpoint instead of PROPFIND properties
2 parents 329b9b7 + ecb59d2 commit 12df66f

14 files changed

+85
-125
lines changed

js/editor-rich.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/editor-rich.js.LICENSE.txt

-22
Original file line numberDiff line numberDiff line change
@@ -1,23 +1 @@
1-
/*
2-
* @copyright Copyright (c) 2019 Julius Härtl <[email protected]>
3-
*
4-
* @author Julius Härtl <[email protected]>
5-
*
6-
* @license GNU AGPL version 3 or any later version
7-
*
8-
* This program is free software: you can redistribute it and/or modify
9-
* it under the terms of the GNU Affero General Public License as
10-
* published by the Free Software Foundation, either version 3 of the
11-
* License, or (at your option) any later version.
12-
*
13-
* This program is distributed in the hope that it will be useful,
14-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16-
* GNU Affero General Public License for more details.
17-
*
18-
* You should have received a copy of the GNU Affero General Public License
19-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20-
*
21-
*/
22-
231
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */

js/editor-rich.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/text-files.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/text-files.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/text-public.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/text-public.js.LICENSE.txt

+9
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
@@ -45,4 +52,6 @@ object-assign
4552
* @license MIT
4653
*/
4754

55+
/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
56+
4857
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */

js/text-public.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/text-text.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/text-text.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/text-viewer.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/text-viewer.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/helpers/files.js

+4-66
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

+57-22
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)