ultisuite-client/lib/drive/drive-search.ts
R3D347HR4Y 6ec95262af Add OnlyOffice integration and update project configurations
- 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.
2026-06-07 15:49:21 +02:00

103 lines
3.4 KiB
TypeScript

import type { DriveView } from "@/lib/drive/drive-url"
import { displayFileName } from "@/lib/drive/display-file-name"
import { normalizeDriveFolderPath } from "@/lib/drive/drive-sidebar-tree"
export const DRIVE_SEARCH_SCOPES = ["all", "shared", "folder"] as const
export type DriveSearchScope = (typeof DRIVE_SEARCH_SCOPES)[number]
export interface DriveSearchState {
query: string
scope: DriveSearchScope
/** Folder path when scope is `folder`. */
folderPath: string
}
export function defaultDriveSearchScope(
view: DriveView,
folderPath: string
): DriveSearchScope {
if (view === "shared" && folderPath === "/") return "shared"
if (folderPath !== "/") return "folder"
return "all"
}
export function driveSearchScopeLabel(
scope: DriveSearchScope,
folderPath: string
): string {
if (scope === "all") return "Mon Drive"
if (scope === "shared") return "Partagés avec moi"
const normalized = normalizeDriveFolderPath(folderPath)
if (normalized === "/") return "Dossier courant"
const segments = normalized.slice(1).split("/")
return segments.map(displayFileName).join(" / ")
}
export function driveSearchScopeShortLabel(scope: DriveSearchScope): string {
if (scope === "all") return "Mon Drive"
if (scope === "shared") return "Partagés"
return "Ce dossier"
}
export function buildDriveSearchUrl(state: DriveSearchState): string {
const params = new URLSearchParams()
params.set("q", state.query.trim())
params.set("scope", state.scope)
if (state.scope === "folder" && state.folderPath !== "/") {
params.set("path", normalizeDriveFolderPath(state.folderPath))
}
return `/drive/search?${params.toString()}`
}
export function parseDriveSearchParams(
searchParams: URLSearchParams,
fallback: Pick<DriveSearchState, "scope" | "folderPath">
): DriveSearchState {
const query = searchParams.get("q")?.trim() ?? ""
const scopeRaw = searchParams.get("scope")
const scope = DRIVE_SEARCH_SCOPES.includes(scopeRaw as DriveSearchScope)
? (scopeRaw as DriveSearchScope)
: fallback.scope
const pathRaw = searchParams.get("path")
const folderPath = pathRaw
? normalizeDriveFolderPath(pathRaw)
: fallback.folderPath
return { query, scope, folderPath }
}
export function parentFolderPath(filePath: string): string {
const normalized = normalizeDriveFolderPath(filePath)
if (normalized === "/") return "/"
const lastSlash = normalized.lastIndexOf("/")
if (lastSlash <= 0) return "/"
return normalized.slice(0, lastSlash) || "/"
}
/** Parent folder path for a file or folder item. */
export function itemParentFolderPath(itemPath: string, itemType: "file" | "directory"): string {
const normalized = normalizeDriveFolderPath(itemPath)
if (itemType === "directory") {
return parentFolderPath(normalized)
}
return parentFolderPath(normalized)
}
export function itemLocationLabel(itemPath: string, itemType: "file" | "directory"): string {
const parent = itemParentFolderPath(itemPath, itemType)
if (parent === "/") return "Mon Drive"
return parent
.slice(1)
.split("/")
.map(displayFileName)
.join(" / ")
}
export function searchResultsTitle(state: DriveSearchState): string {
const scopeLabel = driveSearchScopeLabel(state.scope, state.folderPath)
return `Résultats pour « ${state.query} » dans ${scopeLabel}`
}
export function fileBrowserViewForSearchScope(scope: DriveSearchScope): "files" | "shared" {
return scope === "shared" ? "shared" : "files"
}