Spaces:
Running
Running
File size: 1,064 Bytes
c10f8f8 |
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 |
"use server";
import { isAuthenticated } from "@/lib/auth";
import { NextResponse } from "next/server";
import { listSpaces } from "@huggingface/hub";
import { ProjectType } from "@/types";
export async function getProjects(): Promise<{
ok: boolean;
projects: ProjectType[];
isEmpty?: boolean;
}> {
const user = await isAuthenticated();
if (user instanceof NextResponse || !user) {
return {
ok: false,
projects: [],
};
}
const projects = [];
for await (const space of listSpaces({
accessToken: user.token as string,
additionalFields: ["author", "cardData"],
search: {
owner: user.name,
}
})) {
if (
!space.private &&
space.sdk === "static" &&
Array.isArray((space.cardData as { tags?: string[] })?.tags) &&
(
((space.cardData as { tags?: string[] })?.tags?.includes("deepsite-v3")) ||
((space.cardData as { tags?: string[] })?.tags?.includes("deepsite"))
)
) {
projects.push(space);
}
}
return {
ok: true,
projects,
};
}
|