Skip to content

Commit 13af688

Browse files
feat: view E2EE files
Signed-off-by: Luka Trovic <[email protected]>
1 parent b04381e commit 13af688

File tree

2 files changed

+42
-8
lines changed

2 files changed

+42
-8
lines changed

src/components/ViewerComponent.vue

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
4343
import PlainTextReader from './PlainTextReader.vue'
4444
import MarkdownContentEditor from './Editor/MarkdownContentEditor.vue'
4545
import { translate, translatePlural } from '@nextcloud/l10n'
46+
import { getClient, getRootPath } from '@nextcloud/files/dav'
4647
4748
import getEditorInstance from './Editor.singleton.js'
4849
@@ -116,16 +117,27 @@ export default {
116117
useSourceView() {
117118
return (
118119
this.source
119-
&& (this.fileVersion || !this.fileid || this.isEmbedded)
120+
&& (this.fileVersion
121+
|| !this.fileid
122+
|| this.isEmbedded
123+
|| this.isEncrypted)
120124
&& !this.hasToggledInteractiveEmbedding
121125
)
122126
},
123127
128+
isEncrypted() {
129+
return this.$attrs.e2EeIsEncrypted || false
130+
},
131+
132+
isMarkdown() {
133+
return (
134+
this.mime === 'text/markdown' || this.mime === 'text/x-web-markdown'
135+
)
136+
},
137+
124138
/** @return {boolean} */
125139
readerComponent() {
126-
return this.mime === 'text/markdown'
127-
? MarkdownContentEditor
128-
: PlainTextReader
140+
return this.isMarkdown ? MarkdownContentEditor : PlainTextReader
129141
},
130142
},
131143
@@ -143,15 +155,37 @@ export default {
143155
t: translate,
144156
async loadFileContent() {
145157
if (this.useSourceView) {
146-
const response = await axios.get(this.source)
147-
this.content = response.data
148-
this.contentLoaded = true
158+
if (this.isEncrypted) {
159+
this.content = await this.fetchDecryptedContent()
160+
this.contentLoaded = true
161+
} else {
162+
const response = await axios.get(this.source)
163+
this.content = response.data
164+
this.contentLoaded = true
165+
}
149166
}
150167
this.$emit('update:loaded', true)
151168
},
152169
toggleEdit() {
153170
this.hasToggledInteractiveEmbedding = true
154171
},
172+
async fetchDecryptedContent() {
173+
const client = getClient()
174+
const response = await client.getFileContents(
175+
`${getRootPath()}${this.filename}`,
176+
{ details: true },
177+
)
178+
const blob = new Blob([response.data], {
179+
type: response.headers['content-type'],
180+
})
181+
const reader = new FileReader()
182+
reader.readAsText(blob)
183+
return new Promise((resolve) => {
184+
reader.onload = () => {
185+
resolve(reader.result)
186+
}
187+
})
188+
},
155189
},
156190
}
157191
</script>

src/helpers/mime.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
55

6-
const openMimetypesMarkdown = ['text/markdown']
6+
const openMimetypesMarkdown = ['text/markdown', 'text/x-web-markdown']
77

88
const openMimetypesPlainText = [
99
'text/plain',

0 commit comments

Comments
 (0)