Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[full-ci] fix: load folder in media viewer #5585

Merged
merged 2 commits into from
Aug 4, 2021
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
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(filePath)
this.setCurrentFile(filePath)
},

Expand Down
93 changes: 34 additions & 59 deletions packages/web-app-media-viewer/src/mixins/loader.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
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?
// Currently it works. We cannot use publicPage() because that will still return
// true when opening the mediaviewer from authenticated routes
return !this.isAuthenticated
return this.$route.params.contextRouteName === 'files-public-list'
},
$_loader_folderLoading() {
return this.$_internal_loader_folderLoading
Expand All @@ -28,66 +26,43 @@ 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(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 = this.$_loader_publicContext
? 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