From f19786f6bbd72a4b22a9d0ece6e391801ec29db7 Mon Sep 17 00:00:00 2001 From: Benedikt Kulmann Date: Fri, 18 Mar 2022 10:54:09 +0100 Subject: [PATCH] WIP fix share routing --- .../components/FilesList/ResourceTable.vue | 29 ++++++++++++++----- packages/web-app-files/src/router/spaces.ts | 4 ++- .../src/services/folder/loaderSharedWithMe.ts | 11 ++++--- .../services/folder/spaces/loaderPersonal.ts | 6 +--- .../src/services/folder/spaces/loaderShare.ts | 19 ++++++++---- .../src/views/shares/SharedResource.vue | 16 +++++----- .../src/views/shares/SharedWithMe.vue | 1 + 7 files changed, 52 insertions(+), 34 deletions(-) diff --git a/packages/web-app-files/src/components/FilesList/ResourceTable.vue b/packages/web-app-files/src/components/FilesList/ResourceTable.vue index 3e546abe6df..ea6adec651e 100644 --- a/packages/web-app-files/src/components/FilesList/ResourceTable.vue +++ b/packages/web-app-files/src/components/FilesList/ResourceTable.vue @@ -249,6 +249,15 @@ export default defineComponent({ required: false, default: null }, + /** + * Mapping with template `:` which maps a field of a resource to a param of the target route. + * Defaults to `storageId:storageId` to map the `storageId` field of a resource to the `storageId` param of the target route. + */ + targetRouteParamMapper: { + type: String, + required: false, + default: 'storageId:storageId' + }, /** * Asserts whether clicking on the resource name triggers any action */ @@ -532,23 +541,27 @@ export default defineComponent({ this.openWithPanel('sharing-item') }, folderLink(file) { - return this.createFolderLink(file.path, file.storageId) + return this.createFolderLink(file.path, file) }, parentFolderLink(file) { - return this.createFolderLink(path.dirname(file.path), file.storageId) + return this.createFolderLink(path.dirname(file.path), file) }, - createFolderLink(path, storageId) { + createFolderLink(path, file) { if (this.targetRoute === null) { return {} } + const params = { + item: path.replace(/^\//, ''), + ...this.targetRoute.params + } + const [fileKey, routeParamKey] = this.targetRouteParamMapper.split(':') + if (file[fileKey]) { + params[routeParamKey] = file[fileKey] + } return { name: this.targetRoute.name, query: this.targetRoute.query, - params: { - item: path.replace(/^\//, ''), - ...this.targetRoute.params, - ...(storageId && { storageId }) - } + params } }, fileDragged(file) { diff --git a/packages/web-app-files/src/router/spaces.ts b/packages/web-app-files/src/router/spaces.ts index c977e5bbfc1..72edbc960c3 100644 --- a/packages/web-app-files/src/router/spaces.ts +++ b/packages/web-app-files/src/router/spaces.ts @@ -64,7 +64,9 @@ export const buildRoutes = (components: RouteComponents): RouteConfig[] => [ } }, { - path: 'shares/:item*', + // FIXME: this is cheating. We rely on shares having a drive alias of `shares/` and hardcode it here until we have dynamic routes with drive aliases. + path: 'shares/:shareName?', + // path: 'shares/:shareName?/:item*', name: locationSpacesShare.name, component: components.SharedResource, meta: { diff --git a/packages/web-app-files/src/services/folder/loaderSharedWithMe.ts b/packages/web-app-files/src/services/folder/loaderSharedWithMe.ts index 52641eef2e7..ea700854672 100644 --- a/packages/web-app-files/src/services/folder/loaderSharedWithMe.ts +++ b/packages/web-app-files/src/services/folder/loaderSharedWithMe.ts @@ -1,7 +1,7 @@ import { FolderLoader, FolderLoaderTask, TaskContext } from '../folder' import Router from 'vue-router' import { useTask } from 'vue-concurrency' -import { aggregateResourceShares } from '../../helpers/resources' +import { aggregateResourceShares, buildWebDavSpacesPath } from '../../helpers/resources' import { isLocationSharesActive } from '../../router' import { Store } from 'vuex' import get from 'lodash-es/get' @@ -47,13 +47,12 @@ export class FolderLoaderSharedWithMe implements FolderLoader { getToken ) - // FIXME, HACK 1: `/Shares` path prefix needs to be removed backend side. We remove it client side in the meantime. - // FIXME, HACK 2: webDavPath points to `files//Shares/xyz` but now needs to point to a shares webDavPath according to the storageId of the share. meh. + // FIXME, HACK 1: path needs to be empty because the share has it's own webdav endpoint (we access it's root and thus don't need any relative path). should ideally be removed backend side. + // FIXME, HACK 2: webDavPath points to `files//Shares/xyz` but now needs to point to a shares webdav root. if (get(store, 'getters.capabilities.spaces.enabled', false)) { resources.forEach((resource) => { - if (resource.path.startsWith('/Shares')) { - resource.path = resource.path.substring('/Shares'.length) - } + resource.path = '' + resource.webDavPath = buildWebDavSpacesPath(resource.storageId, '') }) } } diff --git a/packages/web-app-files/src/services/folder/spaces/loaderPersonal.ts b/packages/web-app-files/src/services/folder/spaces/loaderPersonal.ts index e8f94ae226b..8fd7e8dc62d 100644 --- a/packages/web-app-files/src/services/folder/spaces/loaderPersonal.ts +++ b/packages/web-app-files/src/services/folder/spaces/loaderPersonal.ts @@ -2,11 +2,7 @@ import { FolderLoader, FolderLoaderTask, TaskContext } from '../../folder' import Router from 'vue-router' import { useTask } from 'vue-concurrency' import { DavProperties } from 'web-pkg/src/constants' -import { - buildResource, - buildWebDavFilesPath, - buildWebDavSpacesPath -} from '../../../helpers/resources' +import { buildResource, buildWebDavSpacesPath } from '../../../helpers/resources' import { isLocationSpacesActive } from '../../../router' import { Store } from 'vuex' import { fetchResources } from '../util' diff --git a/packages/web-app-files/src/services/folder/spaces/loaderShare.ts b/packages/web-app-files/src/services/folder/spaces/loaderShare.ts index b7dfdc8db8c..e4bd2938e2d 100644 --- a/packages/web-app-files/src/services/folder/spaces/loaderShare.ts +++ b/packages/web-app-files/src/services/folder/spaces/loaderShare.ts @@ -16,15 +16,22 @@ export class FolderLoaderSpacesShare implements FolderLoader { } public getTask(context: TaskContext): FolderLoaderTask { - const { - store, - clientService: { owncloudSdk: client } - } = context + const { store, clientService } = context + const graphClient = clientService.graphAuthenticated( + store.getters.configuration.server, + store.getters.getToken + ) - return useTask(function* (signal1, signal2, ref, storageId, path = null) { + return useTask(function* (signal1, signal2, ref, shareName, path = null) { store.commit('Files/CLEAR_CURRENT_FILES_LIST') - const webDavResponse = yield client.files.list(buildWebDavSpacesPath(storageId, path || '')) + const drives = yield graphClient.drives.listMyDrives('', `name eq '${shareName}'`) + console.log(drives.data.value) + + const webDavResponse = yield clientService.owncloudSdk.files.list( + buildWebDavSpacesPath(shareName, path || '') + ) + console.log(webDavResponse) const resources = webDavResponse.map(buildResource) const currentFolder = resources.shift() diff --git a/packages/web-app-files/src/views/shares/SharedResource.vue b/packages/web-app-files/src/views/shares/SharedResource.vue index 43ec78d247f..d33ee9e071c 100644 --- a/packages/web-app-files/src/views/shares/SharedResource.vue +++ b/packages/web-app-files/src/views/shares/SharedResource.vue @@ -1,6 +1,6 @@