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
88 changes: 37 additions & 51 deletions js/viewer-main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/viewer-main.js.map

Large diffs are not rendered by default.

32 changes: 27 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"dependencies": {
"@nextcloud/auth": "^1.3.0",
"@nextcloud/axios": "^1.3.3",
"@nextcloud/dialogs": "^2.0.0",
"@nextcloud/paths": "^1.1.2",
"@nextcloud/router": "^1.1.0",
"@nextcloud/vue": "^2.6.1",
Expand Down
36 changes: 21 additions & 15 deletions src/views/Viewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -102,22 +102,25 @@
</template>

<script>
import { getRootPath } from '../utils/davUtils'
import Vue from 'vue'

import '@nextcloud/dialogs/styles/toast.scss'
import { showError } from '@nextcloud/dialogs'

import ActionButton from '@nextcloud/vue/dist/Components/ActionButton'
import isFullscreen from '@nextcloud/vue/dist/Mixins/isFullscreen'
import isMobile from '@nextcloud/vue/dist/Mixins/isMobile'
import Modal from '@nextcloud/vue/dist/Components/Modal'
import Vue from 'vue'

import { extractFilePaths, sortCompare } from '../utils/fileUtils'
import { getRootPath } from '../utils/davUtils'
import cancelableRequest from '../utils/CancelableRequest'
import Error from '../components/Error'
import File from '../models/file'
import Mime from '../mixins/Mime'
import getFileList from '../services/FileList'
import getFileInfo from '../services/FileInfo'
import filesActionHandler from '../services/FilesActionHandler'

import cancelableRequest from '../utils/CancelableRequest'
import getFileInfo from '../services/FileInfo'
import getFileList from '../services/FileList'
import Mime from '../mixins/Mime'

export default {
name: 'Viewer',
Expand Down Expand Up @@ -341,6 +344,14 @@ export default {
// get original mime
let mime = fileInfo.mime

// if we don't have a handler for this mime, abort
if (!(mime in this.components)) {
console.error('The following file could not be displayed', fileName, fileInfo)
showError(t('viewer', 'There is no plugin available to display this file type'))
this.close()
return
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to check that upfront as an app calling openFile?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless we use the filename to detect type, unfortunately no.
I started by doing this, but in the end nextcloud server have different mimetypes than some libraries you can find (and apps can register custom ones)

Unless we have a dedicated service that allow us to match the mimetype against server, I don't see how I can do it without :/

}

// check if part of a group, if so retrieve full files list
const group = this.mimeGroups[mime]
if (this.files && this.files.length > 0) {
Expand Down Expand Up @@ -381,14 +392,9 @@ export default {
mime = mime.split('/')[0]
}

// if we have a valid mime, show it!
if (this.components[mime]) {
this.currentFile = new File(fileInfo, mime, this.components[mime])
this.updatePreviousNext()
} else {
console.error('The following file could not be displayed', fileName, fileInfo)
this.close()
}
// show file
this.currentFile = new File(fileInfo, mime, this.components[mime])
this.updatePreviousNext()

// if sidebar was opened before, let's update the file
this.changeSidebar()
Expand Down
4 changes: 4 additions & 0 deletions webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ const config = {
test: /\.m?js$/,
loader: 'babel-loader',
exclude: BabelLoaderExcludeNodeModulesExcept([
'@nextcloud/dialogs',
'@nextcloud/event-bus',
'camelcase',
'fast-xml-parser',
'hot-patcher',
'semver',
'vue-plyr',
'webdav',
'toastify-js',
]),
},
],
Expand Down