ultisuite-client/lib/api/drive-roots.ts
R3D347HR4Y ad1370ea7e
Some checks are pending
E2E / Playwright e2e (push) Waiting to run
feat: enhance configuration and add new demo layouts
- Introduced turbopack alias for canvas in next.config.mjs.
- Updated package.json scripts for development and branding tasks.
- Added new dependencies for Tiptap extensions.
- Implemented new demo layouts for agenda, contacts, drive, and mail applications.
- Enhanced globals.css for improved theming and splash screen animations.
- Added OAuth callback handling for drive mounts.
- Updated layout components to integrate new demo shells and improve structure.
2026-06-12 19:10:24 +02:00

99 lines
3.0 KiB
TypeScript

import { decodePathSegment } from "@/lib/drive/drive-url"
function encodeFolderPath(folderPath: string): string {
if (folderPath === "/" || folderPath.trim() === "") return ""
return folderPath
.replace(/^\/+/, "")
.split("/")
.filter(Boolean)
.map((seg) => encodeURIComponent(decodePathSegment(seg)))
.join("/")
}
export function driveOrgFilesApiPath(folderId: string, folderPath: string): string {
const encoded = encodeFolderPath(folderPath)
const base = `/drive/org-folders/${encodeURIComponent(folderId)}/files`
return encoded ? `${base}/${encoded}` : `${base}/`
}
export function driveMountFilesApiPath(mountId: string, folderPath: string): string {
const encoded = encodeFolderPath(folderPath)
const base = `/drive/mounts/${encodeURIComponent(mountId)}/files`
return encoded ? `${base}/${encoded}` : `${base}/`
}
export function driveOrgDownloadApiPath(folderId: string, filePath: string): string {
const encoded = encodeFolderPath(filePath)
return `/drive/org-folders/${encodeURIComponent(folderId)}/download/${encoded}`
}
export function driveMountDownloadApiPath(mountId: string, filePath: string): string {
const encoded = encodeFolderPath(filePath)
return `/drive/mounts/${encodeURIComponent(mountId)}/download/${encoded}`
}
export function driveOrgPreviewApiPath(
folderId: string,
filePath: string,
width = 400,
height = 300
): string {
const encoded = encodeFolderPath(filePath)
return `/drive/org-folders/${encodeURIComponent(folderId)}/preview/${encoded}?w=${width}&h=${height}`
}
export function driveMountPreviewApiPath(
mountId: string,
filePath: string,
width = 400,
height = 300
): string {
const encoded = encodeFolderPath(filePath)
return `/drive/mounts/${encodeURIComponent(mountId)}/preview/${encoded}?w=${width}&h=${height}`
}
export interface DrivePathRef {
root?: "personal" | "org" | "mount"
root_id?: string
path: string
}
export function pathRefFromRoute(
view: string,
rootId: string | null,
path: string
): DrivePathRef {
if (view === "org" && rootId) return { root: "org", root_id: rootId, path }
if (view === "mount" && rootId) return { root: "mount", root_id: rootId, path }
return { path }
}
export function withPathRefBody<T extends Record<string, unknown>>(
body: T,
ref: DrivePathRef
): T & Partial<DrivePathRef> {
if (ref.root && ref.root !== "personal") {
return { ...body, root: ref.root, root_id: ref.root_id, path: ref.path }
}
return body
}
export function withMoveCopyRefs(
source: DrivePathRef,
destination: DrivePathRef
): Record<string, string> {
const payload: Record<string, string> = {
source: source.path,
destination: destination.path,
}
if (source.root && source.root !== "personal") {
payload.source_root = source.root
if (source.root_id) payload.source_root_id = source.root_id
}
if (destination.root && destination.root !== "personal") {
payload.destination_root = destination.root
if (destination.root_id) payload.destination_root_id = destination.root_id
}
return payload
}