Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 41 additions & 7 deletions src/components/ViewerComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import PlainTextReader from './PlainTextReader.vue'
import MarkdownContentEditor from './Editor/MarkdownContentEditor.vue'
import { translate, translatePlural } from '@nextcloud/l10n'
import { getClient, getRootPath } from '@nextcloud/files/dav'

import getEditorInstance from './Editor.singleton.js'

Expand Down Expand Up @@ -116,16 +117,27 @@
useSourceView() {
return (
this.source
&& (this.fileVersion || !this.fileid || this.isEmbedded)
&& (this.fileVersion
|| !this.fileid
|| this.isEmbedded
|| this.isEncrypted)

Check warning on line 123 in src/components/ViewerComponent.vue

View check run for this annotation

Codecov / codecov/patch

src/components/ViewerComponent.vue#L120-L123

Added lines #L120 - L123 were not covered by tests
&& !this.hasToggledInteractiveEmbedding
)
},

isEncrypted() {
return this.$attrs.e2EeIsEncrypted || false

Check warning on line 129 in src/components/ViewerComponent.vue

View check run for this annotation

Codecov / codecov/patch

src/components/ViewerComponent.vue#L128-L129

Added lines #L128 - L129 were not covered by tests
},

isMarkdown() {
return (
this.mime === 'text/markdown' || this.mime === 'text/x-web-markdown'

Check warning on line 134 in src/components/ViewerComponent.vue

View check run for this annotation

Codecov / codecov/patch

src/components/ViewerComponent.vue#L132-L134

Added lines #L132 - L134 were not covered by tests
)
},

Check warning on line 136 in src/components/ViewerComponent.vue

View check run for this annotation

Codecov / codecov/patch

src/components/ViewerComponent.vue#L136

Added line #L136 was not covered by tests

/** @return {boolean} */
readerComponent() {
return this.mime === 'text/markdown'
? MarkdownContentEditor
: PlainTextReader
return this.isMarkdown ? MarkdownContentEditor : PlainTextReader

Check warning on line 140 in src/components/ViewerComponent.vue

View check run for this annotation

Codecov / codecov/patch

src/components/ViewerComponent.vue#L140

Added line #L140 was not covered by tests
},
},

Expand All @@ -143,15 +155,37 @@
t: translate,
async loadFileContent() {
if (this.useSourceView) {
const response = await axios.get(this.source)
this.content = response.data
this.contentLoaded = true
if (this.isEncrypted) {
this.content = await this.fetchDecryptedContent()
this.contentLoaded = true

Check warning on line 160 in src/components/ViewerComponent.vue

View check run for this annotation

Codecov / codecov/patch

src/components/ViewerComponent.vue#L158-L160

Added lines #L158 - L160 were not covered by tests
} else {
const response = await axios.get(this.source)
this.content = response.data
this.contentLoaded = true
}

Check warning on line 165 in src/components/ViewerComponent.vue

View check run for this annotation

Codecov / codecov/patch

src/components/ViewerComponent.vue#L162-L165

Added lines #L162 - L165 were not covered by tests
}
this.$emit('update:loaded', true)
},
toggleEdit() {
this.hasToggledInteractiveEmbedding = true
},
async fetchDecryptedContent() {

Check warning on line 172 in src/components/ViewerComponent.vue

View check run for this annotation

Codecov / codecov/patch

src/components/ViewerComponent.vue#L172

Added line #L172 was not covered by tests
const client = getClient()
const response = await client.getFileContents(
`${getRootPath()}${this.filename}`,
{ details: true },
)
const blob = new Blob([response.data], {
type: response.headers['content-type'],

Check warning on line 179 in src/components/ViewerComponent.vue

View check run for this annotation

Codecov / codecov/patch

src/components/ViewerComponent.vue#L174-L179

Added lines #L174 - L179 were not covered by tests
})
const reader = new FileReader()
reader.readAsText(blob)
return new Promise((resolve) => {
reader.onload = () => {
resolve(reader.result)

Check warning on line 185 in src/components/ViewerComponent.vue

View check run for this annotation

Codecov / codecov/patch

src/components/ViewerComponent.vue#L181-L185

Added lines #L181 - L185 were not covered by tests
}
})
},
},
}
</script>
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/mime.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

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

Check warning on line 6 in src/helpers/mime.js

View check run for this annotation

Codecov / codecov/patch

src/helpers/mime.js#L6

Added line #L6 was not covered by tests

const openMimetypesPlainText = [
'text/plain',
Expand Down
Loading