From 1ba25866702da479dedaa2574b26187ad1371302 Mon Sep 17 00:00:00 2001 From: Lukas Hirt Date: Thu, 29 Jul 2021 14:21:07 +0200 Subject: [PATCH] fix: load folder in media viewer --- .../bugfix-load-folder-in-media-viewer | 7 ++ packages/web-app-media-viewer/src/App.vue | 2 +- .../web-app-media-viewer/src/mixins/loader.js | 89 +++++++------------ 3 files changed, 42 insertions(+), 56 deletions(-) create mode 100644 changelog/unreleased/bugfix-load-folder-in-media-viewer diff --git a/changelog/unreleased/bugfix-load-folder-in-media-viewer b/changelog/unreleased/bugfix-load-folder-in-media-viewer new file mode 100644 index 00000000000..c707e06b2d5 --- /dev/null +++ b/changelog/unreleased/bugfix-load-folder-in-media-viewer @@ -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 \ No newline at end of file diff --git a/packages/web-app-media-viewer/src/App.vue b/packages/web-app-media-viewer/src/App.vue index 2482db93c8c..2642f30a35a 100644 --- a/packages/web-app-media-viewer/src/App.vue +++ b/packages/web-app-media-viewer/src/App.vue @@ -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) }, diff --git a/packages/web-app-media-viewer/src/mixins/loader.js b/packages/web-app-media-viewer/src/mixins/loader.js index 8a236b0b44f..9b9a4794beb 100644 --- a/packages/web-app-media-viewer/src/mixins/loader.js +++ b/packages/web-app-media-viewer/src/mixins/loader.js @@ -1,6 +1,7 @@ -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: @@ -8,7 +9,7 @@ import { basename, dirname } from 'path' 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? @@ -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) {