- Updated .env.example to include configuration for OnlyOffice Document Server. - Modified the workspace configuration to remove the drive-suite path. - Adjusted TypeScript environment imports for consistency. - Enhanced Next.js configuration to disable canvas in Webpack. - Updated package.json to include new dependencies for OnlyOffice and PDF.js. - Added global styles for OnlyOffice theme integration in the CSS. - Created new layout and page components for the Drive feature, including public sharing and editing functionalities. - Updated metadata handling across various layouts to reflect the new app structure.
56 lines
1.9 KiB
TypeScript
56 lines
1.9 KiB
TypeScript
import type { DriveFileInfo } from "@/lib/api/types"
|
|
import { normalizeDriveFolderPath } from "@/lib/drive/drive-sidebar-tree"
|
|
|
|
export type DriveMoveSource = Pick<DriveFileInfo, "path" | "name" | "type">
|
|
|
|
export function parentFolderPath(itemPath: string): string {
|
|
const normalized = itemPath.replace(/\/+$/, "")
|
|
const idx = normalized.lastIndexOf("/")
|
|
if (idx <= 0) return "/"
|
|
return normalized.slice(0, idx) || "/"
|
|
}
|
|
|
|
export function buildMoveDestination(destFolderPath: string, itemName: string): string {
|
|
const dest = normalizeDriveFolderPath(destFolderPath)
|
|
return dest === "/" ? `/${itemName}` : `${dest}/${itemName}`.replace(/\/+/g, "/")
|
|
}
|
|
|
|
export function isMoveDestinationBlocked(
|
|
sources: Pick<DriveMoveSource, "path" | "type">[],
|
|
destFolderPath: string
|
|
): boolean {
|
|
const dest = normalizeDriveFolderPath(destFolderPath)
|
|
return sources.some((source) => {
|
|
if (source.type !== "directory") return false
|
|
const src = normalizeDriveFolderPath(source.path)
|
|
return dest === src || dest.startsWith(`${src}/`)
|
|
})
|
|
}
|
|
|
|
export function isMoveToSameFolder(sources: DriveMoveSource[], destFolderPath: string): boolean {
|
|
const dest = normalizeDriveFolderPath(destFolderPath)
|
|
return sources.every((source) => parentFolderPath(source.path) === dest)
|
|
}
|
|
|
|
export async function copyDriveItemsToFolder(
|
|
sources: DriveMoveSource[],
|
|
destFolderPath: string,
|
|
copy: (body: { source: string; destination: string }) => Promise<void>
|
|
): Promise<void> {
|
|
for (const item of sources) {
|
|
const destination = buildMoveDestination(destFolderPath, item.name)
|
|
await copy({ source: item.path, destination })
|
|
}
|
|
}
|
|
|
|
export async function moveDriveItemsToFolder(
|
|
sources: DriveMoveSource[],
|
|
destFolderPath: string,
|
|
move: (body: { source: string; destination: string }) => Promise<void>
|
|
): Promise<void> {
|
|
for (const item of sources) {
|
|
const destination = buildMoveDestination(destFolderPath, item.name)
|
|
await move({ source: item.path, destination })
|
|
}
|
|
}
|