25 lines
524 B
TypeScript
25 lines
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,
|
||
|
|
}));
|
||
|
|
}
|