Spaces:
Build error
Build error
| import { clsx, type ClassValue } from "clsx" | |
| import { twMerge } from "tailwind-merge" | |
| import type { Folder, File, FileSystemNode } from '@/app/api/files/route'; | |
| export function cn(...inputs: ClassValue[]) { | |
| return twMerge(clsx(inputs)) | |
| } | |
| export function findNodeByPath(node: Folder, path: string): Folder | null { | |
| if (node.path === path) { | |
| return node; | |
| } | |
| for (const child of node.children) { | |
| if (child.type === 'folder') { | |
| const found = findNodeByPath(child, path); | |
| if (found) { | |
| return found; | |
| } | |
| } | |
| } | |
| return null; | |
| } | |
| export function getAllFiles(node: Folder): File[] { | |
| let files: File[] = []; | |
| for (const child of node.children) { | |
| if (child.type === 'file') { | |
| files.push(child); | |
| } else if (child.type === 'folder') { | |
| files = files.concat(getAllFiles(child)); | |
| } | |
| } | |
| return files; | |
| } | |
| export function getNodesByIds(node: Folder, ids: string[]): FileSystemNode[] { | |
| let results: FileSystemNode[] = []; | |
| if (ids.includes(node.id)) { | |
| results.push(node); | |
| } | |
| for (const child of node.children) { | |
| if (child.type === 'folder') { | |
| results = results.concat(getNodesByIds(child, ids)); | |
| } else if (ids.includes(child.id)) { | |
| results.push(child); | |
| } | |
| } | |
| return results; | |
| } | |