Skip to content

Commit

Permalink
fix: load folder in media viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasHirt committed Aug 1, 2021
1 parent 3655572 commit 1ba2586
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 56 deletions.
7 changes: 7 additions & 0 deletions changelog/unreleased/bugfix-load-folder-in-media-viewer
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Bugfix: load folder in Media viewer

We've fixed the loading of a folder in the Media viewer extension.
If a user reloads the Media viewer now, it load all the medias both in private and public context.

https://github.com/owncloud/web/issues/5427
https://github.com/owncloud/web/pull/5585
2 changes: 1 addition & 1 deletion packages/web-app-media-viewer/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ export default {
window.addEventListener('popstate', this.handleLocalHistoryEvent)
const filePath = this.$route.params.filePath
await this.$_loader_loadFolder(this.$route.params.contextRouteName, filePath)
await this.$_loader_loadItems(this.$route.params.contextRouteName, filePath)
this.setCurrentFile(filePath)
},
Expand Down
89 changes: 34 additions & 55 deletions packages/web-app-media-viewer/src/mixins/loader.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { mapActions, mapGetters } from 'vuex'
import { mapGetters, mapMutations } from 'vuex'
import queryString from 'query-string'
import { basename, dirname } from 'path'
import { buildResource } from '../../../web-app-files/src/helpers/resources' // TODO: place the helper in more global space not to create dep on files app

// TODO: this file is a first attempt to separate file/folder loading logic out of the mediaviewer
// Discussion how to progress from here can be found in this issue:
// https://github.com/owncloud/web/issues/3301

export default {
computed: {
...mapGetters('Files', ['publicLinkPassword']),
...mapGetters('Files', ['publicLinkPassword', 'davProperties']),
...mapGetters(['configuration']),
$_loader_publicContext() {
// TODO: Can we rely on not being "authenticated" while viewing a public link?
Expand All @@ -28,66 +29,44 @@ export default {
},

methods: {
...mapActions('Files', ['loadFolder']),
...mapMutations('Files', ['CLEAR_CURRENT_FILES_LIST', 'LOAD_FILES', 'SET_CURRENT_FOLDER']),

// This methods ensures the folder is loaded if we don't have a folder loaded currently
$_loader_loadFolder(contextRouteName, filePath) {
// FIXME: handle public-files with passwords and everything, until then we redirect to the main public link page
if (this.$store.getters.activeFile.path === '' && contextRouteName === 'public-files') {
const path = this.$route.params.filePath.substring(1)
const token = path.substr(0, path.indexOf('/'))
this.$nextTick(() => {
this.$router.push({
name: 'publicLink',
params: {
token
}
})
})
throw new Error('public-files')
async $_loader_loadItems(contextRouteName, filePath) {
if (this.$store.getters.activeFile.path !== '') {
return
}

// load files
if (this.$store.getters.activeFile.path === '') {
const absolutePath = filePath.substring(1, filePath.lastIndexOf('/'))

return this.loadFolder({
client: this.$client,
absolutePath: absolutePath,
$gettext: this.$gettext,
routeName: contextRouteName,
loadSharesTree: !this.publicPage()
this.$_internal_loader_folderLoading = true

this.CLEAR_CURRENT_FILES_LIST()

try {
const properties = this.davProperties.concat([
this.$client.publicFiles.PUBLIC_LINK_ITEM_TYPE,
this.$client.publicFiles.PUBLIC_LINK_PERMISSION,
this.$client.publicFiles.PUBLIC_LINK_EXPIRATION,
this.$client.publicFiles.PUBLIC_LINK_SHARE_DATETIME,
this.$client.publicFiles.PUBLIC_LINK_SHARE_OWNER
])
const absolutePath = filePath.substring(0, filePath.lastIndexOf('/'))
const promise =
contextRouteName === 'files-public-list'
? this.$client.publicFiles.list(absolutePath, this.publicLinkPassword, properties)
: this.$client.files.list(absolutePath, 1, this.davProperties)
let resources = await promise

resources = resources.map(buildResource)
this.LOAD_FILES({
currentFolder: resources[0],
files: resources.slice(1)
})
.then(() => {
this.$data.$_internal_loader_folderLoading = false
})
.catch(error => {
// FIXME: Loading of public link folders doesn't work at all and is disabled hence, so this code should be unreachable

// // password for public link shares is missing -> this is handled on the caller side
// if (this.$_loader_publicContext && error.statusCode === 401) {
// this.$router.push({
// name: 'public-link',
// params: {
// token: this.$route.params.item
// }
// })
// return
// }

this.showMessage({
title: this.$gettext('Loading folder failed…'),
desc: error.message,
status: 'danger',
autoClose: {
enabled: true
}
})
})
} catch (error) {
this.SET_CURRENT_FOLDER(null)
console.error(error)
}

// folder already loaded, nothing to do …
this.$data.$_internal_loader_folderLoading = false
this.$_internal_loader_folderLoading = false
},

$_loader_getDavFilePath(mediaFile, query = null) {
Expand Down

0 comments on commit 1ba2586

Please sign in to comment.