-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: resolving external URLs via file ID
- Loading branch information
1 parent
b850502
commit 3ccacf6
Showing
6 changed files
with
190 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...runtime/src/composables/fileInfo/index.ts → ...eb-pkg/src/composables/resources/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './useGetResourcePath' | ||
export * from './useLoadFileInfoById' |
81 changes: 81 additions & 0 deletions
81
packages/web-pkg/src/composables/resources/useGetResourcePath.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { | ||
Resource, | ||
SpaceResource, | ||
buildShareSpaceResource, | ||
isMountPointSpaceResource | ||
} from '@ownclouders/web-client/src/helpers' | ||
import { computed, unref } from 'vue' | ||
import { useStore } from '../store' | ||
import { useClientService } from '../clientService' | ||
import { urlJoin } from '@ownclouders/web-client/src/utils' | ||
import { useConfigurationManager } from '../configuration' | ||
import { useLoadFileInfoById } from './useLoadFileInfoById' | ||
import { useCapabilitySpacesEnabled } from '../capability' | ||
import { useGetMatchingSpace } from '../spaces/useGetMatchingSpace' | ||
|
||
export const useGetResourcePath = () => { | ||
const store = useStore() | ||
const clientService = useClientService() | ||
const configurationManager = useConfigurationManager() | ||
const { loadFileInfoByIdTask } = useLoadFileInfoById({ clientService }) | ||
const { getPersonalSpace } = useGetMatchingSpace() | ||
|
||
const hasSpaces = useCapabilitySpacesEnabled(store) | ||
const spaces = computed<SpaceResource[]>(() => store.getters['runtime/spaces/spaces']) | ||
|
||
const getMatchingSpaceByFileId = (id: Resource['id']) => { | ||
if (!unref(hasSpaces)) { | ||
return getPersonalSpace() | ||
} | ||
return unref(spaces).find((space) => id.toString().startsWith(space.id.toString())) | ||
} | ||
const getMatchingMountPoint = (id: Resource['id']) => { | ||
return unref(spaces).find( | ||
(space) => isMountPointSpaceResource(space) && space.root?.remoteItem?.id === id | ||
) | ||
} | ||
|
||
const getResourcePath = async (id: string) => { | ||
let path: string | ||
let resource: Resource | ||
let space = getMatchingSpaceByFileId(id) | ||
|
||
if (space) { | ||
path = await clientService.webdav.getPathForFileId(id) | ||
resource = await clientService.webdav.getFileInfo(space, { path }) | ||
return { space, resource, path } | ||
} | ||
|
||
// no matching space found => the file doesn't lie in own spaces => it's a share. | ||
// do PROPFINDs on parents until root of accepted share is found in `mountpoint` spaces | ||
await store.dispatch('runtime/spaces/loadMountPoints', { | ||
graphClient: clientService.graphAuthenticated | ||
}) | ||
|
||
let mountPoint = getMatchingMountPoint(id) | ||
resource = await loadFileInfoByIdTask.perform(id) | ||
const sharePathSegments = mountPoint ? [] : [unref(resource).name] | ||
let tmpResource = unref(resource) | ||
|
||
while (!mountPoint) { | ||
tmpResource = await loadFileInfoByIdTask.perform(tmpResource.parentFolderId) | ||
mountPoint = getMatchingMountPoint(tmpResource.id) | ||
if (!mountPoint) { | ||
sharePathSegments.unshift(tmpResource.name) | ||
} | ||
} | ||
|
||
space = buildShareSpaceResource({ | ||
shareId: mountPoint.nodeId, | ||
shareName: mountPoint.name, | ||
serverUrl: configurationManager.serverUrl | ||
}) | ||
|
||
path = urlJoin(...sharePathSegments) | ||
return { space, resource, path } | ||
} | ||
|
||
return { | ||
getResourcePath | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
...mposables/fileInfo/useLoadFileInfoById.ts → ...posables/resources/useLoadFileInfoById.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.