From 23bb4f7ad06688bbc64935b58a2928fe69293b6f Mon Sep 17 00:00:00 2001 From: Jannik Stehle Date: Wed, 16 Aug 2023 18:23:25 +0200 Subject: [PATCH] Hide share owner path --- .../filesList/useResourceRouteResolver.ts | 1 + .../src/services/folder/loaderSpace.ts | 26 +++++++--- .../src/views/spaces/GenericSpace.vue | 5 +- packages/web-client/src/webdav/listFiles.ts | 3 +- .../driveResolver/useDriveResolver.ts | 50 +++++++++++++++++-- .../src/composables/fileInfo/index.ts | 0 .../fileInfo/useLoadFileInfoById.ts | 0 .../src/pages/resolvePrivateLink.vue | 3 +- 8 files changed, 74 insertions(+), 14 deletions(-) rename packages/{web-runtime => web-pkg}/src/composables/fileInfo/index.ts (100%) rename packages/{web-runtime => web-pkg}/src/composables/fileInfo/useLoadFileInfoById.ts (100%) diff --git a/packages/web-app-files/src/composables/filesList/useResourceRouteResolver.ts b/packages/web-app-files/src/composables/filesList/useResourceRouteResolver.ts index e40f1157e29..997e84124d0 100644 --- a/packages/web-app-files/src/composables/filesList/useResourceRouteResolver.ts +++ b/packages/web-app-files/src/composables/filesList/useResourceRouteResolver.ts @@ -34,6 +34,7 @@ export const useResourceRouteResolver = (options: ResourceRouteResolverOptions, if (!space) { return {} } + console.log('path', path) return createLocationSpaces( 'files-spaces-generic', createFileRouteOptions(space, { path, fileId }) diff --git a/packages/web-app-files/src/services/folder/loaderSpace.ts b/packages/web-app-files/src/services/folder/loaderSpace.ts index d3ddb44916c..2d84e1b52c5 100644 --- a/packages/web-app-files/src/services/folder/loaderSpace.ts +++ b/packages/web-app-files/src/services/folder/loaderSpace.ts @@ -10,6 +10,7 @@ import { authService } from 'web-runtime/src/services/auth' import { useFileRouteReplace } from 'web-pkg/src/composables/router/useFileRouteReplace' import { aggregateResourceShares } from '../../helpers/resources' import { getIndicators } from 'web-app-files/src/helpers/statusIndicators' +import { urlJoin } from 'web-client/src/utils' export class FolderLoaderSpace implements FolderLoader { public isEnabled(): boolean { @@ -45,19 +46,32 @@ export class FolderLoaderSpace implements FolderLoader { store.commit('Files/CLEAR_CURRENT_FILES_LIST') let { resource: currentFolder, children: resources } = yield webdav.listFiles(space, { - path, fileId }) + const mountPoint = store.getters['runtime/spaces/spaces'].find( - (s) => - isMountPointSpaceResource(s) && currentFolder.path.startsWith(s.root.remoteItem.path) + (s) => isMountPointSpaceResource(s) && path.startsWith(s.root.remoteItem.path) ) if (mountPoint && !configurationManager.options.routing.fullShareOwnerPaths) { - const hiddenPath = mountPoint.root.remoteItem.path.split('/').slice(0, -1).join('/') - const visiiblePath = currentFolder.path.replace(hiddenPath, '...') - currentFolder.visiblePath = visiiblePath + currentFolder.path = mountPoint.root.remoteItem.path + console.log('currentFolder.path', currentFolder.path) + const hiddenPath = currentFolder.path.split('/').slice(0, -1).join('/') + console.log('hidden', hiddenPath) + currentFolder.visiblePath = currentFolder.path.replace(hiddenPath, '...') + resources.forEach((r) => { + r.path = urlJoin(path, r.path) + r.visiblePath = r.path.replace(hiddenPath, '...') + console.log('r path', r.path) + }) + } else { + currentFolder.path = path + resources.forEach((r) => { + r.path = urlJoin(path, r.path) + }) } + console.log('current folder path', currentFolder.path) + // if current folder has no id (= singe file public link) we must not correct the route if (currentFolder.id) { yield replaceInvalidFileRoute({ space, resource: currentFolder, path, fileId }) diff --git a/packages/web-app-files/src/views/spaces/GenericSpace.vue b/packages/web-app-files/src/views/spaces/GenericSpace.vue index 2f172523114..1bef5045df4 100644 --- a/packages/web-app-files/src/views/spaces/GenericSpace.vue +++ b/packages/web-app-files/src/views/spaces/GenericSpace.vue @@ -273,11 +273,10 @@ export default defineComponent({ ]) const resourceTargetRouteCallback = ({ - path, - fileId + resource }: CreateTargetRouteOptions): RouteLocationNamedRaw => { // TODO: can we move that to useResourceRouteResolver and remove this callback? - const { params, query } = createFileRouteOptions(props.space, { path, fileId }) + const { params, query } = createFileRouteOptions(props.space, resource) if (isPublicSpaceResource(props.space)) { return createLocationPublic('files-public-link', { params, query }) } diff --git a/packages/web-client/src/webdav/listFiles.ts b/packages/web-client/src/webdav/listFiles.ts index 6c4025089a7..aa94ff2b3e7 100644 --- a/packages/web-client/src/webdav/listFiles.ts +++ b/packages/web-client/src/webdav/listFiles.ts @@ -55,7 +55,7 @@ export const ListFilesFactory = ({ sdk }: WebDavOptions) => { try { webDavResources = await sdk.files.list( - urlJoin(space.webDavPath, path), + path || !fileId ? urlJoin(space.webDavPath, path) : `spaces/${fileId}`, `${depth}`, davProperties || DavProperties.Default ) @@ -66,6 +66,7 @@ export const ListFilesFactory = ({ sdk }: WebDavOptions) => { return { resource: resources[0], children: resources.slice(1) } as ListFilesResult } catch (e) { if (e.statusCode === 404 && fileId) { + console.log(2222) return listFilesCorrectedPath() } throw e diff --git a/packages/web-pkg/src/composables/driveResolver/useDriveResolver.ts b/packages/web-pkg/src/composables/driveResolver/useDriveResolver.ts index 30fcf0b0298..af447c6008e 100644 --- a/packages/web-pkg/src/composables/driveResolver/useDriveResolver.ts +++ b/packages/web-pkg/src/composables/driveResolver/useDriveResolver.ts @@ -1,7 +1,11 @@ import { useStore } from '../store' import { Store } from 'vuex' import { computed, Ref, ref, unref, watch } from 'vue' -import { SpaceResource } from 'web-client/src/helpers' +import { + isMountPointSpaceResource, + isPersonalSpaceResource, + SpaceResource +} from 'web-client/src/helpers' import { useRouteQuery } from '../router' import { Resource } from 'web-client' import { useSpacesLoading } from './useSpacesLoading' @@ -9,6 +13,7 @@ import { queryItemAsString } from '../appDefaults' import { urlJoin } from 'web-client/src/utils' import { useCapabilitySpacesEnabled } from '../capability' import { useClientService } from 'web-pkg/src/composables' +import { useLoadFileInfoById } from 'web-pkg/src/composables/fileInfo' interface DriveResolverOptions { store?: Store @@ -36,6 +41,32 @@ export const useDriveResolver = (options: DriveResolverOptions = {}): DriveResol const item: Ref = ref(null) const loading = ref(false) + const { loadFileInfoByIdTask } = useLoadFileInfoById({ clientService }) + const findMatchingMountPoint = (id: string | number): SpaceResource => { + return store.getters['runtime/spaces/spaces'].find( + (space) => isMountPointSpaceResource(space) && space.root?.remoteItem?.id === id + ) + } + + const findMountPoint = async (fileId: Resource['id']) => { + let mountPoint = findMatchingMountPoint(fileId) + let resource = await loadFileInfoByIdTask.perform(fileId) + const sharePathSegments = mountPoint ? [] : [unref(resource).name] + while (!mountPoint) { + try { + resource = await loadFileInfoByIdTask.perform(resource.parentFolderId) + } catch (e) { + throw Error(e) + } + mountPoint = findMatchingMountPoint(resource.id) + if (!mountPoint) { + sharePathSegments.unshift(resource.name) + } + } + + return mountPoint + } + watch( [options.driveAliasAndItem, areSpacesLoading], async ([driveAliasAndItem]) => { @@ -94,8 +125,21 @@ export const useDriveResolver = (options: DriveResolverOptions = {}): DriveResol }) } if (matchingSpace) { - console.log(44, driveAliasAndItem) - path = driveAliasAndItem.slice(matchingSpace.driveAlias.length) + if ( + isPersonalSpaceResource(matchingSpace) && + matchingSpace.ownerId !== store.getters.user.uuid && + driveAliasAndItem.includes('...') //FIXME + ) { + const mountPoint = await findMountPoint(unref(fileId)) + path = driveAliasAndItem.slice(matchingSpace.driveAlias.length) + path = `${urlJoin(mountPoint.root.remoteItem.path, path.split('/').slice(3).join('/'))}` + } else { + path = driveAliasAndItem.slice(matchingSpace.driveAlias.length) + } + // const mountPoint = store.getters['runtime/spaces/spaces'].find( + // (s) => + // isMountPointSpaceResource(s) && currentFolder.path.startsWith(s.root.remoteItem.path) + // ) } } space.value = matchingSpace diff --git a/packages/web-runtime/src/composables/fileInfo/index.ts b/packages/web-pkg/src/composables/fileInfo/index.ts similarity index 100% rename from packages/web-runtime/src/composables/fileInfo/index.ts rename to packages/web-pkg/src/composables/fileInfo/index.ts diff --git a/packages/web-runtime/src/composables/fileInfo/useLoadFileInfoById.ts b/packages/web-pkg/src/composables/fileInfo/useLoadFileInfoById.ts similarity index 100% rename from packages/web-runtime/src/composables/fileInfo/useLoadFileInfoById.ts rename to packages/web-pkg/src/composables/fileInfo/useLoadFileInfoById.ts diff --git a/packages/web-runtime/src/pages/resolvePrivateLink.vue b/packages/web-runtime/src/pages/resolvePrivateLink.vue index e369a1a94ac..9f25242e6a6 100644 --- a/packages/web-runtime/src/pages/resolvePrivateLink.vue +++ b/packages/web-runtime/src/pages/resolvePrivateLink.vue @@ -68,7 +68,7 @@ import { } from 'web-client/src/helpers' import { configurationManager } from 'web-pkg/src/configuration' import { RouteLocationRaw } from 'vue-router' -import { useLoadFileInfoById } from '../composables/fileInfo' +import { useLoadFileInfoById } from 'web-pkg/src/composables/fileInfo' import { useGettext } from 'vue3-gettext' export default defineComponent({ @@ -272,3 +272,4 @@ export default defineComponent({ } } +../../../web-pkg/src/composables/fileInfo