Skip to content

Commit

Permalink
WIP: Share resolving
Browse files Browse the repository at this point in the history
  • Loading branch information
JammingBen committed Oct 10, 2022
1 parent dc8a92e commit e55cd41
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 25 deletions.
11 changes: 7 additions & 4 deletions packages/web-app-files/src/services/folder/loaderSpace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,17 @@ export class FolderLoaderSpace implements FolderLoader {
options: FolderLoaderOptions = {}
) {
try {
console.log('FOLDER LOADER')
store.commit('Files/CLEAR_CURRENT_FILES_LIST')

console.log('path', path)
console.log('fileId', fileId)
const resources = yield webdav.listFiles(space, { path, fileId })
let currentFolder = resources.shift()
replaceInvalidFileRoute({ space, resource: currentFolder, path, fileId })
console.log('currentFolder', currentFolder.path)
// replaceInvalidFileRoute({ space, resource: currentFolder, path, fileId })

if (path === '/') {
if (space.driveType === 'share') {
if (space.driveType === 'share' && space.shareId) {
const parentShare = yield client.shares.getShare(space.shareId)
const aggregatedShares = aggregateResourceShares(
[parentShare.shareInfo],
Expand All @@ -67,7 +70,7 @@ export class FolderLoaderSpace implements FolderLoader {
true
)
currentFolder = aggregatedShares[0]
} else if (!['personal', 'public'].includes(space.driveType)) {
} else if (!['personal', 'public', 'share'].includes(space.driveType)) {
// note: in the future we might want to show the space as root for personal spaces as well (to show quota and the like). Currently not needed.
currentFolder = space
}
Expand Down
7 changes: 4 additions & 3 deletions packages/web-client/src/helpers/space/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,18 @@ export function buildShareSpaceResource({
shareName,
serverUrl
}: {
shareId: string | number
shareId?: string | number
shareName: string
serverUrl: string
}): ShareSpaceResource {
const space = buildSpace({
id: [SHARE_JAIL_ID, shareId].join('!'),
id: [SHARE_JAIL_ID, shareId].filter(Boolean).join('!'),
driveAlias: `share/${shareName}`,
driveType: 'share',
name: shareName,
shareId,
serverUrl
serverUrl,
...(!shareId && { webDavPath: buildWebDavSpacesPath(SHARE_JAIL_ID, shareName) })
}) as ShareSpaceResource
space.rename = (newName: string) => {
space.driveAlias = `share/${newName}`
Expand Down
2 changes: 1 addition & 1 deletion packages/web-client/src/helpers/space/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// or all types get different members, the underscored props can be removed.
import { Resource } from '../resource'

export const SHARE_JAIL_ID = 'a0ca6a90-a365-4782-871e-d44447bbc668'
export const SHARE_JAIL_ID = 'a0ca6a90-a365-4782-871e-d44447bbc668$a0ca6a90-a365-4782-871e-d44447bbc668'

export interface SpaceResource extends Resource {
disabled?: boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ export const useDriveResolver = (options: DriveResolverOptions = {}) => {
serverUrl: configurationManager.serverUrl
})
path = item.join('/')
console.log('drive resolver: matching space', matchingSpace)
console.log('drive resolver: path', path)
} else {
if (unref(hasSpaces) && unref(fileId)) {
matchingSpace = unref(spaces).find((s) => {
Expand Down
43 changes: 26 additions & 17 deletions packages/web-runtime/src/pages/resolveAliasLink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ import {
useRouteParam,
useStore,
useTranslations,
useUserContext,
useRouter
} from "web-pkg/src/composables";
import { unref, ref, defineComponent, computed, onMounted } from "@vue/composition-api";
import { authService } from "../services/auth";
import { useLoadTokenInfo } from "../composables/tokenInfo";
import { clientService } from "web-pkg/src/services";
import { createLocationSpaces } from "files/src/router";
import {urlJoin} from "web-pkg/src/utils";
import {buildShareSpaceResource} from "web-client/src/helpers";
import {configurationManager} from "web-pkg/src/configuration";
import {createFileRouteOptions} from "web-pkg/src/helpers/router";
import {dirname} from "path";
export default defineComponent({
name: 'ResolveAliasLink',
Expand All @@ -26,16 +28,10 @@ export default defineComponent({
const route = useRoute()
const token = useRouteParam('token')
const { $gettext } = useTranslations()
const isUserContext = useUserContext({ store })
const { loadTokenInfoTask } = useLoadTokenInfo(unref(token))
const tokenInfo = ref(undefined)
onMounted(async () => {
if (!unref(isUserContext)) {
await authService.loginUser()
return router.push({ name: '/login' })
}
tokenInfo.value = await loadTokenInfoTask.perform()
resolveAliasLink()
})
Expand All @@ -44,25 +40,38 @@ export default defineComponent({
const resolveAliasLink = async () => {
const { id, storage_id: storageId, space_id: spaceId } = unref(tokenInfo)
const path = await clientService.owncloudSdk.files.getPathForFileId(id)
const matchingSpace = getMatchingSpace(`${storageId}$${spaceId}`)
let path = await clientService.owncloudSdk.files.getPathForFileId(id)
let matchingSpace = getMatchingSpace(`${storageId}$${spaceId}`)
if (!matchingSpace){
const [shareName, ...pathSegments] = path.split('/').filter(Boolean)
matchingSpace = buildShareSpaceResource({
shareName,
serverUrl: configurationManager.serverUrl
})
path = urlJoin(pathSegments)
}
console.log('mathcing space', matchingSpace)
console.log('path', path)
const resource = await clientService.webdav.getFileInfo(matchingSpace, { path })
let driveAliasPath
let scrollTo
let fileId
if (resource.type !== 'file') {
driveAliasPath = path
fileId = resource.fileId
scrollTo = ''
} else {
driveAliasPath = ''
path = dirname(path)
fileId = resource.parentFolderId
scrollTo = path
}
const {params, query} = createFileRouteOptions(matchingSpace, {fileId, path})
const location = createLocationSpaces('files-spaces-generic', {
params: {
driveAliasAndItem: matchingSpace.getDriveAliasAndItem({ path: driveAliasPath })
},
query: { scrollTo: urlJoin(scrollTo, { leadingSlash: false }) }
params,
query: {...query, scrollTo: urlJoin(scrollTo, { leadingSlash: false }) }
})
return router.push(location)
}
Expand Down

0 comments on commit e55cd41

Please sign in to comment.