Skip to content

Commit

Permalink
Hide share owner path
Browse files Browse the repository at this point in the history
  • Loading branch information
JammingBen committed Sep 11, 2023
1 parent 822846d commit 23bb4f7
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down
26 changes: 20 additions & 6 deletions packages/web-app-files/src/services/folder/loaderSpace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 })
Expand Down
5 changes: 2 additions & 3 deletions packages/web-app-files/src/views/spaces/GenericSpace.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
}
Expand Down
3 changes: 2 additions & 1 deletion packages/web-client/src/webdav/listFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand All @@ -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
Expand Down
50 changes: 47 additions & 3 deletions packages/web-pkg/src/composables/driveResolver/useDriveResolver.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
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'
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<any>
Expand Down Expand Up @@ -36,6 +41,32 @@ export const useDriveResolver = (options: DriveResolverOptions = {}): DriveResol
const item: Ref<string> = 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]) => {
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion packages/web-runtime/src/pages/resolvePrivateLink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -272,3 +272,4 @@ export default defineComponent({
}
}
</style>
../../../web-pkg/src/composables/fileInfo

0 comments on commit 23bb4f7

Please sign in to comment.