124_webcalibre2/src/app/dashboard/actions.ts

25 lines
No EOL
524 B
TypeScript

'use server';
import { prisma } from "@/lib/prisma";
import { auth } from "@/auth";
export async function getFileNodes() {
const session = await auth();
if (!session?.user?.id) {
return []; // Return empty if not logged in
}
const nodes = await prisma.fileNode.findMany({
where: {
ownerId: session.user.id, // Only get THIS user's files
},
orderBy: {
orderIndex: 'asc',
},
});
return nodes.map(node => ({
...node,
size: node.size ? Number(node.size) : null,
}));
}