From 996dc8af5027154cdec314cd34667d6956a790f3 Mon Sep 17 00:00:00 2001 From: Benedikt Kulmann Date: Tue, 11 Oct 2022 23:49:42 +0200 Subject: [PATCH 1/3] feat: resolve private links into shares --- .../src/helpers/resource/resource.ts | 12 ++- .../web-app-files/src/helpers/resources.ts | 10 +- .../web-client/src/helpers/resource/types.ts | 1 + .../web-client/src/helpers/space/functions.ts | 10 +- .../web-client/src/helpers/space/types.ts | 21 ++++ .../web-runtime/src/pages/resolveFileLink.vue | 98 +++++++++++++++---- 6 files changed, 128 insertions(+), 24 deletions(-) diff --git a/packages/web-app-files/src/helpers/resource/resource.ts b/packages/web-app-files/src/helpers/resource/resource.ts index db1ddc3d5d4..cf99fa8f141 100644 --- a/packages/web-app-files/src/helpers/resource/resource.ts +++ b/packages/web-app-files/src/helpers/resource/resource.ts @@ -1,11 +1,19 @@ import { Resource } from 'web-client' import fileExtensions from '../extensions/fileExtensions' -export const extractStorageId = (id?: string): string => { +const extractIdSegment = (id: string, index: number): string => { if (!id || typeof id !== 'string') { return '' } - return id.indexOf('!') >= 0 ? id.split('!')[0] : '' + return id.indexOf('!') >= 0 ? id.split('!')[index] : '' +} + +export const extractStorageId = (id?: string): string => { + return extractIdSegment(id, 0) +} + +export const extractNodeId = (id?: string): string => { + return extractIdSegment(id, 1) } export const extractNameWithoutExtension = (resource?: Resource): string => { diff --git a/packages/web-app-files/src/helpers/resources.ts b/packages/web-app-files/src/helpers/resources.ts index 667167e7cf6..b8125487b34 100644 --- a/packages/web-app-files/src/helpers/resources.ts +++ b/packages/web-app-files/src/helpers/resources.ts @@ -14,7 +14,7 @@ import { spaceRoleManager, spaceRoleViewer } from 'web-client/src/helpers/share' -import { extractExtensionFromFile, extractStorageId } from './resource' +import { extractExtensionFromFile, extractNodeId, extractStorageId } from './resource' import { buildWebDavSpacesPath, extractDomSelector } from 'web-client/src/helpers/resource' import { Resource, SpaceResource, SHARE_JAIL_ID } from 'web-client/src/helpers' import { urlJoin } from 'web-pkg/src/utils' @@ -44,7 +44,7 @@ export function buildResource(resource): Resource { } const id = resource.fileInfo[DavProperty.FileId] - return { + const r = { id, fileId: id, storageId: extractStorageId(id), @@ -106,6 +106,12 @@ export function buildResource(resource): Resource { }, getDomSelector: () => extractDomSelector(id) } + Object.defineProperty(r, 'nodeId', { + get() { + return extractNodeId(this.id) + } + }) + return r } export function buildWebDavPublicPath(publicLinkToken, path = '') { diff --git a/packages/web-client/src/helpers/resource/types.ts b/packages/web-client/src/helpers/resource/types.ts index 3c6e6a93aba..cce534a51f5 100644 --- a/packages/web-client/src/helpers/resource/types.ts +++ b/packages/web-client/src/helpers/resource/types.ts @@ -6,6 +6,7 @@ export interface Resource { fileId?: string parentFolderId?: string storageId?: string + readonly nodeId?: string name?: string path: string webDavPath?: string diff --git a/packages/web-client/src/helpers/space/functions.ts b/packages/web-client/src/helpers/space/functions.ts index 56bef530e7f..7953f7ef3b2 100644 --- a/packages/web-client/src/helpers/space/functions.ts +++ b/packages/web-client/src/helpers/space/functions.ts @@ -5,6 +5,7 @@ import { PublicSpaceResource, ShareSpaceResource, SpaceResource, SHARE_JAIL_ID } import { DavProperty } from 'web-pkg/src/constants' import { buildWebDavPublicPath } from 'files/src/helpers/resources' import { urlJoin } from 'web-pkg/src/utils' +import { extractNodeId } from 'files/src/helpers/resource' export function buildPublicSpaceResource(data): PublicSpaceResource { const publicLinkPassword = data.publicLinkPassword @@ -94,7 +95,7 @@ export function buildSpace(data): SpaceResource { }) const webDavUrl = urlJoin(data.serverUrl, 'remote.php/dav', webDavPath) - return { + const s = { id: data.id, fileId: data.id, storageId: data.id, @@ -125,6 +126,7 @@ export function buildSpace(data): SpaceResource { ownerDisplayName: '', ownerId: data.owner?.user?.id, disabled, + root: data.root, spaceQuota: data.quota, spaceRoles, spaceImageData, @@ -197,4 +199,10 @@ export function buildSpace(data): SpaceResource { return urlJoin(this.webDavUrl, resource.path) } } + Object.defineProperty(s, 'nodeId', { + get() { + return extractNodeId(this.id) + } + }) + return s } diff --git a/packages/web-client/src/helpers/space/types.ts b/packages/web-client/src/helpers/space/types.ts index 5ab8306513e..90a7e9537a8 100644 --- a/packages/web-client/src/helpers/space/types.ts +++ b/packages/web-client/src/helpers/space/types.ts @@ -10,9 +10,21 @@ import { Resource } from '../resource' export const SHARE_JAIL_ID = 'a0ca6a90-a365-4782-871e-d44447bbc668' +export interface SpaceResourceRemoteItem { + id: string + name: string +} + +export interface SpaceResourceRoot { + id: string + remoteItem: SpaceResourceRemoteItem + webDavUrl: string +} + export interface SpaceResource extends Resource { disabled?: boolean webDavUrl: string + root: SpaceResourceRoot getWebDavUrl(resource: Resource): string getDriveAliasAndItem(resource: Resource): string } @@ -39,6 +51,15 @@ export const isShareSpaceResource = (resource: Resource): resource is ShareSpace return resource.driveType === 'share' } +export interface MountPointSpaceResource extends SpaceResource { + __mountPointSpaceResource?: any +} +export const isMountPointSpaceResource = ( + resource: Resource +): resource is MountPointSpaceResource => { + return resource.driveType === 'mountpoint' +} + export interface PublicSpaceResource extends SpaceResource { publicLinkPassword?: string publicLinkItemType?: string diff --git a/packages/web-runtime/src/pages/resolveFileLink.vue b/packages/web-runtime/src/pages/resolveFileLink.vue index 47a6ed0c7b1..718d65a1f72 100644 --- a/packages/web-runtime/src/pages/resolveFileLink.vue +++ b/packages/web-runtime/src/pages/resolveFileLink.vue @@ -31,21 +31,34 @@ -