"use server"; import { isAuthenticated } from "@/lib/auth"; import { NextResponse } from "next/server"; import { Project as ProjectType } from "@/types"; // Import local storage functions instead of MongoDB import { listProjects, findProject } from "@/lib/local-storage"; export async function getProjects(): Promise<{ ok: boolean; projects: ProjectType[]; }> { const user = await isAuthenticated(); if (user instanceof NextResponse || !user) { return { ok: false, projects: [], }; } // Use local storage instead of MongoDB const result = await listProjects(user.id); if (!result.success || !result.data) { return { ok: false, projects: [], }; } // Sort projects by creation date (newest first) and limit to 100 const projects = result.data .sort((a: any, b: any) => new Date(b._createdAt).getTime() - new Date(a._createdAt).getTime()) .slice(0, 100); return { ok: true, projects: JSON.parse(JSON.stringify(projects)) as ProjectType[], }; } export async function getProject( namespace: string, repoId: string ): Promise { const user = await isAuthenticated(); if (user instanceof NextResponse || !user) { return null; } // Use local storage instead of MongoDB const result = await findProject(user.id, namespace, repoId); if (!result.success || !result.data) { return null; } return JSON.parse(JSON.stringify(result.data)) as ProjectType; }