Skip to content

Commit 0b17f6a

Browse files
feat: view E2EE files
Signed-off-by: Luka Trovic <luka@nextcloud.com>
1 parent 67efbd4 commit 0b17f6a

File tree

2 files changed

+43
-10
lines changed

2 files changed

+43
-10
lines changed

src/components/ViewerComponent.vue

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -115,17 +115,28 @@ export default {
115115
/** @return {boolean} */
116116
useSourceView() {
117117
return (
118-
this.source &&
119-
(this.fileVersion || !this.fileid || this.isEmbedded) &&
120-
!this.hasToggledInteractiveEmbedding
118+
this.source
119+
&& (this.fileVersion
120+
|| !this.fileid
121+
|| this.isEmbedded
122+
|| this.isEncrypted)
123+
&& !this.hasToggledInteractiveEmbedding
124+
)
125+
},
126+
127+
isEncrypted() {
128+
return this.$attrs.e2EeIsEncrypted || false
129+
},
130+
131+
isMarkdown() {
132+
return (
133+
this.mime === 'text/markdown' || this.mime === 'text/x-web-markdown'
121134
)
122135
},
123136
124137
/** @return {boolean} */
125138
readerComponent() {
126-
return this.mime === 'text/markdown'
127-
? MarkdownContentEditor
128-
: PlainTextReader
139+
return this.isMarkdown ? MarkdownContentEditor : PlainTextReader
129140
},
130141
},
131142
@@ -143,15 +154,37 @@ export default {
143154
t: translate,
144155
async loadFileContent() {
145156
if (this.useSourceView) {
146-
const response = await axios.get(this.source)
147-
this.content = response.data
148-
this.contentLoaded = true
157+
if (this.isEncrypted) {
158+
this.content = await this.fetchDecryptedContent()
159+
this.contentLoaded = true
160+
} else {
161+
const response = await axios.get(this.source)
162+
this.content = response.data
163+
this.contentLoaded = true
164+
}
149165
}
150166
this.$emit('update:loaded', true)
151167
},
152168
toggleEdit() {
153169
this.hasToggledInteractiveEmbedding = true
154170
},
171+
async fetchDecryptedContent() {
172+
const client = getClient()
173+
const response = await client.getFileContents(
174+
`${getRootPath()}${this.filename}`,
175+
{ details: true },
176+
)
177+
const blob = new Blob([response.data], {
178+
type: response.headers['content-type'],
179+
})
180+
const reader = new FileReader()
181+
reader.readAsText(blob)
182+
return new Promise((resolve) => {
183+
reader.onload = () => {
184+
resolve(reader.result)
185+
}
186+
})
187+
},
155188
},
156189
}
157190
</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)