Spaces:
Running
Running
File size: 1,486 Bytes
1cf8f01 fedfb56 1cf8f01 fedfb56 1cf8f01 fedfb56 1cf8f01 fedfb56 1cf8f01 fedfb56 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
"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<ProjectType | null> {
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;
} |