Spaces:
Running
Running
Delete app
Browse files- app/(public)/layout.tsx +0 -15
- app/(public)/page.tsx +0 -44
- app/(public)/projects/page.tsx +0 -13
- app/actions/auth.ts +0 -18
- app/actions/projects.ts +0 -63
- app/api/ask-ai/route.ts +0 -419
- app/api/auth/route.ts +0 -86
- app/api/me/projects/[namespace]/[repoId]/route.ts +0 -237
- app/api/me/projects/route.ts +0 -126
- app/api/me/route.ts +0 -25
- app/api/re-design/route.ts +0 -39
- app/auth/callback/page.tsx +0 -72
- app/auth/page.tsx +0 -28
- app/favicon.ico +0 -0
- app/layout.tsx +0 -108
- app/projects/[namespace]/[repoId]/page.tsx +0 -40
- app/projects/new/page.tsx +0 -5
app/(public)/layout.tsx
DELETED
|
@@ -1,15 +0,0 @@
|
|
| 1 |
-
import Navigation from "@/components/public/navigation";
|
| 2 |
-
|
| 3 |
-
export default async function PublicLayout({
|
| 4 |
-
children,
|
| 5 |
-
}: Readonly<{
|
| 6 |
-
children: React.ReactNode;
|
| 7 |
-
}>) {
|
| 8 |
-
return (
|
| 9 |
-
<div className="min-h-screen bg-black z-1 relative">
|
| 10 |
-
<div className="background__noisy" />
|
| 11 |
-
<Navigation />
|
| 12 |
-
{children}
|
| 13 |
-
</div>
|
| 14 |
-
);
|
| 15 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/(public)/page.tsx
DELETED
|
@@ -1,44 +0,0 @@
|
|
| 1 |
-
import { AskAi } from "@/components/space/ask-ai";
|
| 2 |
-
import { redirect } from "next/navigation";
|
| 3 |
-
export default function Home() {
|
| 4 |
-
redirect("/projects/new");
|
| 5 |
-
return (
|
| 6 |
-
<>
|
| 7 |
-
<header className="container mx-auto pt-20 px-6 relative flex flex-col items-center justify-center text-center">
|
| 8 |
-
<div className="rounded-full border border-neutral-100/10 bg-neutral-100/5 text-xs text-neutral-300 px-3 py-1 max-w-max mx-auto mb-2">
|
| 9 |
-
✨ DeepSite Public Beta
|
| 10 |
-
</div>
|
| 11 |
-
<h1 className="text-8xl font-semibold text-white font-mono max-w-4xl">
|
| 12 |
-
Code your website with AI in seconds
|
| 13 |
-
</h1>
|
| 14 |
-
<p className="text-2xl text-neutral-300/80 mt-4 text-center max-w-2xl">
|
| 15 |
-
Vibe Coding has never been so easy.
|
| 16 |
-
</p>
|
| 17 |
-
<div className="mt-14 max-w-2xl w-full mx-auto">
|
| 18 |
-
<AskAi />
|
| 19 |
-
</div>
|
| 20 |
-
<div className="absolute inset-0 pointer-events-none -z-[1]">
|
| 21 |
-
<div className="w-full h-full bg-gradient-to-r from-purple-500 to-pink-500 opacity-10 blur-3xl rounded-full" />
|
| 22 |
-
<div className="w-2/3 h-3/4 bg-gradient-to-r from-blue-500 to-teal-500 opacity-24 blur-3xl absolute -top-20 right-10 transform rotate-12" />
|
| 23 |
-
<div className="w-1/2 h-1/2 bg-gradient-to-r from-amber-500 to-rose-500 opacity-20 blur-3xl absolute bottom-0 left-10 rounded-3xl" />
|
| 24 |
-
<div className="w-48 h-48 bg-gradient-to-r from-cyan-500 to-indigo-500 opacity-20 blur-3xl absolute top-1/3 right-1/3 rounded-lg transform -rotate-15" />
|
| 25 |
-
</div>
|
| 26 |
-
</header>
|
| 27 |
-
<div id="community" className="h-screen flex items-center justify-center">
|
| 28 |
-
<h1 className="text-7xl font-extrabold text-white font-mono">
|
| 29 |
-
Community Driven
|
| 30 |
-
</h1>
|
| 31 |
-
</div>
|
| 32 |
-
<div id="deploy" className="h-screen flex items-center justify-center">
|
| 33 |
-
<h1 className="text-7xl font-extrabold text-white font-mono">
|
| 34 |
-
Deploy your website in seconds
|
| 35 |
-
</h1>
|
| 36 |
-
</div>
|
| 37 |
-
<div id="features" className="h-screen flex items-center justify-center">
|
| 38 |
-
<h1 className="text-7xl font-extrabold text-white font-mono">
|
| 39 |
-
Features that make you smile
|
| 40 |
-
</h1>
|
| 41 |
-
</div>
|
| 42 |
-
</>
|
| 43 |
-
);
|
| 44 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/(public)/projects/page.tsx
DELETED
|
@@ -1,13 +0,0 @@
|
|
| 1 |
-
import { redirect } from "next/navigation";
|
| 2 |
-
|
| 3 |
-
import { MyProjects } from "@/components/my-projects";
|
| 4 |
-
import { getProjects } from "@/app/actions/projects";
|
| 5 |
-
|
| 6 |
-
export default async function ProjectsPage() {
|
| 7 |
-
const { ok, projects } = await getProjects();
|
| 8 |
-
if (!ok) {
|
| 9 |
-
redirect("/");
|
| 10 |
-
}
|
| 11 |
-
|
| 12 |
-
return <MyProjects projects={projects} />;
|
| 13 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/actions/auth.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
| 1 |
-
"use server";
|
| 2 |
-
|
| 3 |
-
import { headers } from "next/headers";
|
| 4 |
-
|
| 5 |
-
export async function getAuth() {
|
| 6 |
-
const authList = await headers();
|
| 7 |
-
const host = authList.get("host") ?? "localhost:3000";
|
| 8 |
-
const url = host.includes("/spaces/enzostvs")
|
| 9 |
-
? "enzostvs-deepsite.hf.space"
|
| 10 |
-
: host;
|
| 11 |
-
const redirect_uri =
|
| 12 |
-
`${host.includes("localhost") ? "http://" : "https://"}` +
|
| 13 |
-
url +
|
| 14 |
-
"/auth/callback";
|
| 15 |
-
|
| 16 |
-
const loginRedirectUrl = `https://huggingface.co/oauth/authorize?client_id=${process.env.OAUTH_CLIENT_ID}&redirect_uri=${redirect_uri}&response_type=code&scope=openid%20profile%20write-repos%20manage-repos%20inference-api&prompt=consent&state=1234567890`;
|
| 17 |
-
return loginRedirectUrl;
|
| 18 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/actions/projects.ts
DELETED
|
@@ -1,63 +0,0 @@
|
|
| 1 |
-
"use server";
|
| 2 |
-
|
| 3 |
-
import { isAuthenticated } from "@/lib/auth";
|
| 4 |
-
import { NextResponse } from "next/server";
|
| 5 |
-
import dbConnect from "@/lib/mongodb";
|
| 6 |
-
import Project from "@/models/Project";
|
| 7 |
-
import { Project as ProjectType } from "@/types";
|
| 8 |
-
|
| 9 |
-
export async function getProjects(): Promise<{
|
| 10 |
-
ok: boolean;
|
| 11 |
-
projects: ProjectType[];
|
| 12 |
-
}> {
|
| 13 |
-
const user = await isAuthenticated();
|
| 14 |
-
|
| 15 |
-
if (user instanceof NextResponse || !user) {
|
| 16 |
-
return {
|
| 17 |
-
ok: false,
|
| 18 |
-
projects: [],
|
| 19 |
-
};
|
| 20 |
-
}
|
| 21 |
-
|
| 22 |
-
await dbConnect();
|
| 23 |
-
const projects = await Project.find({
|
| 24 |
-
user_id: user?.id,
|
| 25 |
-
})
|
| 26 |
-
.sort({ _createdAt: -1 })
|
| 27 |
-
.limit(100)
|
| 28 |
-
.lean();
|
| 29 |
-
if (!projects) {
|
| 30 |
-
return {
|
| 31 |
-
ok: false,
|
| 32 |
-
projects: [],
|
| 33 |
-
};
|
| 34 |
-
}
|
| 35 |
-
return {
|
| 36 |
-
ok: true,
|
| 37 |
-
projects: JSON.parse(JSON.stringify(projects)) as ProjectType[],
|
| 38 |
-
};
|
| 39 |
-
}
|
| 40 |
-
|
| 41 |
-
export async function getProject(
|
| 42 |
-
namespace: string,
|
| 43 |
-
repoId: string
|
| 44 |
-
): Promise<ProjectType | null> {
|
| 45 |
-
const user = await isAuthenticated();
|
| 46 |
-
|
| 47 |
-
if (user instanceof NextResponse || !user) {
|
| 48 |
-
return null;
|
| 49 |
-
}
|
| 50 |
-
|
| 51 |
-
await dbConnect();
|
| 52 |
-
const project = await Project.findOne({
|
| 53 |
-
user_id: user.id,
|
| 54 |
-
namespace,
|
| 55 |
-
repoId,
|
| 56 |
-
}).lean();
|
| 57 |
-
|
| 58 |
-
if (!project) {
|
| 59 |
-
return null;
|
| 60 |
-
}
|
| 61 |
-
|
| 62 |
-
return JSON.parse(JSON.stringify(project)) as ProjectType;
|
| 63 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/api/ask-ai/route.ts
DELETED
|
@@ -1,419 +0,0 @@
|
|
| 1 |
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
| 2 |
-
import type { NextRequest } from "next/server";
|
| 3 |
-
import { NextResponse } from "next/server";
|
| 4 |
-
import { headers } from "next/headers";
|
| 5 |
-
import { InferenceClient } from "@huggingface/inference";
|
| 6 |
-
|
| 7 |
-
import { MODELS, PROVIDERS } from "@/lib/providers";
|
| 8 |
-
import {
|
| 9 |
-
DIVIDER,
|
| 10 |
-
FOLLOW_UP_SYSTEM_PROMPT,
|
| 11 |
-
INITIAL_SYSTEM_PROMPT,
|
| 12 |
-
MAX_REQUESTS_PER_IP,
|
| 13 |
-
REPLACE_END,
|
| 14 |
-
SEARCH_START,
|
| 15 |
-
} from "@/lib/prompts";
|
| 16 |
-
import MY_TOKEN_KEY from "@/lib/get-cookie-name";
|
| 17 |
-
|
| 18 |
-
const ipAddresses = new Map();
|
| 19 |
-
|
| 20 |
-
export async function POST(request: NextRequest) {
|
| 21 |
-
const authHeaders = await headers();
|
| 22 |
-
const userToken = request.cookies.get(MY_TOKEN_KEY())?.value;
|
| 23 |
-
|
| 24 |
-
const body = await request.json();
|
| 25 |
-
const { prompt, provider, model, redesignMarkdown, html } = body;
|
| 26 |
-
|
| 27 |
-
if (!model || (!prompt && !redesignMarkdown)) {
|
| 28 |
-
return NextResponse.json(
|
| 29 |
-
{ ok: false, error: "Missing required fields" },
|
| 30 |
-
{ status: 400 }
|
| 31 |
-
);
|
| 32 |
-
}
|
| 33 |
-
|
| 34 |
-
const selectedModel = MODELS.find(
|
| 35 |
-
(m) => m.value === model || m.label === model
|
| 36 |
-
);
|
| 37 |
-
if (!selectedModel) {
|
| 38 |
-
return NextResponse.json(
|
| 39 |
-
{ ok: false, error: "Invalid model selected" },
|
| 40 |
-
{ status: 400 }
|
| 41 |
-
);
|
| 42 |
-
}
|
| 43 |
-
|
| 44 |
-
if (!selectedModel.providers.includes(provider) && provider !== "auto") {
|
| 45 |
-
return NextResponse.json(
|
| 46 |
-
{
|
| 47 |
-
ok: false,
|
| 48 |
-
error: `The selected model does not support the ${provider} provider.`,
|
| 49 |
-
openSelectProvider: true,
|
| 50 |
-
},
|
| 51 |
-
{ status: 400 }
|
| 52 |
-
);
|
| 53 |
-
}
|
| 54 |
-
|
| 55 |
-
let token = userToken;
|
| 56 |
-
let billTo: string | null = null;
|
| 57 |
-
|
| 58 |
-
/**
|
| 59 |
-
* Handle local usage token, this bypass the need for a user token
|
| 60 |
-
* and allows local testing without authentication.
|
| 61 |
-
* This is useful for development and testing purposes.
|
| 62 |
-
*/
|
| 63 |
-
if (process.env.HF_TOKEN && process.env.HF_TOKEN.length > 0) {
|
| 64 |
-
token = process.env.HF_TOKEN;
|
| 65 |
-
}
|
| 66 |
-
|
| 67 |
-
const ip = authHeaders.get("x-forwarded-for")?.includes(",")
|
| 68 |
-
? authHeaders.get("x-forwarded-for")?.split(",")[1].trim()
|
| 69 |
-
: authHeaders.get("x-forwarded-for");
|
| 70 |
-
|
| 71 |
-
if (!token) {
|
| 72 |
-
ipAddresses.set(ip, (ipAddresses.get(ip) || 0) + 1);
|
| 73 |
-
if (ipAddresses.get(ip) > MAX_REQUESTS_PER_IP) {
|
| 74 |
-
return NextResponse.json(
|
| 75 |
-
{
|
| 76 |
-
ok: false,
|
| 77 |
-
openLogin: true,
|
| 78 |
-
message: "Log In to continue using the service",
|
| 79 |
-
},
|
| 80 |
-
{ status: 429 }
|
| 81 |
-
);
|
| 82 |
-
}
|
| 83 |
-
|
| 84 |
-
token = process.env.DEFAULT_HF_TOKEN as string;
|
| 85 |
-
billTo = "huggingface";
|
| 86 |
-
}
|
| 87 |
-
|
| 88 |
-
const DEFAULT_PROVIDER = PROVIDERS.novita;
|
| 89 |
-
const selectedProvider =
|
| 90 |
-
provider === "auto"
|
| 91 |
-
? PROVIDERS[selectedModel.autoProvider as keyof typeof PROVIDERS]
|
| 92 |
-
: PROVIDERS[provider as keyof typeof PROVIDERS] ?? DEFAULT_PROVIDER;
|
| 93 |
-
|
| 94 |
-
try {
|
| 95 |
-
// Create a stream response
|
| 96 |
-
const encoder = new TextEncoder();
|
| 97 |
-
const stream = new TransformStream();
|
| 98 |
-
const writer = stream.writable.getWriter();
|
| 99 |
-
|
| 100 |
-
// Start the response
|
| 101 |
-
const response = new NextResponse(stream.readable, {
|
| 102 |
-
headers: {
|
| 103 |
-
"Content-Type": "text/plain; charset=utf-8",
|
| 104 |
-
"Cache-Control": "no-cache",
|
| 105 |
-
Connection: "keep-alive",
|
| 106 |
-
},
|
| 107 |
-
});
|
| 108 |
-
|
| 109 |
-
(async () => {
|
| 110 |
-
let completeResponse = "";
|
| 111 |
-
try {
|
| 112 |
-
const client = new InferenceClient(token);
|
| 113 |
-
const chatCompletion = client.chatCompletionStream(
|
| 114 |
-
{
|
| 115 |
-
model: selectedModel.value,
|
| 116 |
-
provider: selectedProvider.id as any,
|
| 117 |
-
messages: [
|
| 118 |
-
{
|
| 119 |
-
role: "system",
|
| 120 |
-
content: INITIAL_SYSTEM_PROMPT,
|
| 121 |
-
},
|
| 122 |
-
{
|
| 123 |
-
role: "user",
|
| 124 |
-
content: redesignMarkdown
|
| 125 |
-
? `Here is my current design as a markdown:\n\n${redesignMarkdown}\n\nNow, please create a new design based on this markdown.`
|
| 126 |
-
: html
|
| 127 |
-
? `Here is my current HTML code:\n\n\`\`\`html\n${html}\n\`\`\`\n\nNow, please create a new design based on this HTML.`
|
| 128 |
-
: prompt,
|
| 129 |
-
},
|
| 130 |
-
],
|
| 131 |
-
max_tokens: selectedProvider.max_tokens,
|
| 132 |
-
},
|
| 133 |
-
billTo ? { billTo } : {}
|
| 134 |
-
);
|
| 135 |
-
|
| 136 |
-
while (true) {
|
| 137 |
-
const { done, value } = await chatCompletion.next();
|
| 138 |
-
if (done) {
|
| 139 |
-
break;
|
| 140 |
-
}
|
| 141 |
-
|
| 142 |
-
const chunk = value.choices[0]?.delta?.content;
|
| 143 |
-
if (chunk) {
|
| 144 |
-
let newChunk = chunk;
|
| 145 |
-
if (!selectedModel?.isThinker) {
|
| 146 |
-
if (provider !== "sambanova") {
|
| 147 |
-
await writer.write(encoder.encode(chunk));
|
| 148 |
-
completeResponse += chunk;
|
| 149 |
-
|
| 150 |
-
if (completeResponse.includes("</html>")) {
|
| 151 |
-
break;
|
| 152 |
-
}
|
| 153 |
-
} else {
|
| 154 |
-
if (chunk.includes("</html>")) {
|
| 155 |
-
newChunk = newChunk.replace(/<\/html>[\s\S]*/, "</html>");
|
| 156 |
-
}
|
| 157 |
-
completeResponse += newChunk;
|
| 158 |
-
await writer.write(encoder.encode(newChunk));
|
| 159 |
-
if (newChunk.includes("</html>")) {
|
| 160 |
-
break;
|
| 161 |
-
}
|
| 162 |
-
}
|
| 163 |
-
} else {
|
| 164 |
-
const lastThinkTagIndex =
|
| 165 |
-
completeResponse.lastIndexOf("</think>");
|
| 166 |
-
completeResponse += newChunk;
|
| 167 |
-
await writer.write(encoder.encode(newChunk));
|
| 168 |
-
if (lastThinkTagIndex !== -1) {
|
| 169 |
-
const afterLastThinkTag = completeResponse.slice(
|
| 170 |
-
lastThinkTagIndex + "</think>".length
|
| 171 |
-
);
|
| 172 |
-
if (afterLastThinkTag.includes("</html>")) {
|
| 173 |
-
break;
|
| 174 |
-
}
|
| 175 |
-
}
|
| 176 |
-
}
|
| 177 |
-
}
|
| 178 |
-
}
|
| 179 |
-
} catch (error: any) {
|
| 180 |
-
if (error.message?.includes("exceeded your monthly included credits")) {
|
| 181 |
-
await writer.write(
|
| 182 |
-
encoder.encode(
|
| 183 |
-
JSON.stringify({
|
| 184 |
-
ok: false,
|
| 185 |
-
openProModal: true,
|
| 186 |
-
message: error.message,
|
| 187 |
-
})
|
| 188 |
-
)
|
| 189 |
-
);
|
| 190 |
-
} else {
|
| 191 |
-
await writer.write(
|
| 192 |
-
encoder.encode(
|
| 193 |
-
JSON.stringify({
|
| 194 |
-
ok: false,
|
| 195 |
-
message:
|
| 196 |
-
error.message ||
|
| 197 |
-
"An error occurred while processing your request.",
|
| 198 |
-
})
|
| 199 |
-
)
|
| 200 |
-
);
|
| 201 |
-
}
|
| 202 |
-
} finally {
|
| 203 |
-
await writer?.close();
|
| 204 |
-
}
|
| 205 |
-
})();
|
| 206 |
-
|
| 207 |
-
return response;
|
| 208 |
-
} catch (error: any) {
|
| 209 |
-
return NextResponse.json(
|
| 210 |
-
{
|
| 211 |
-
ok: false,
|
| 212 |
-
openSelectProvider: true,
|
| 213 |
-
message:
|
| 214 |
-
error?.message || "An error occurred while processing your request.",
|
| 215 |
-
},
|
| 216 |
-
{ status: 500 }
|
| 217 |
-
);
|
| 218 |
-
}
|
| 219 |
-
}
|
| 220 |
-
|
| 221 |
-
export async function PUT(request: NextRequest) {
|
| 222 |
-
const authHeaders = await headers();
|
| 223 |
-
const userToken = request.cookies.get(MY_TOKEN_KEY())?.value;
|
| 224 |
-
|
| 225 |
-
const body = await request.json();
|
| 226 |
-
const { prompt, html, previousPrompt, provider, selectedElementHtml, model } =
|
| 227 |
-
body;
|
| 228 |
-
|
| 229 |
-
if (!prompt || !html) {
|
| 230 |
-
return NextResponse.json(
|
| 231 |
-
{ ok: false, error: "Missing required fields" },
|
| 232 |
-
{ status: 400 }
|
| 233 |
-
);
|
| 234 |
-
}
|
| 235 |
-
|
| 236 |
-
const selectedModel = MODELS.find(
|
| 237 |
-
(m) => m.value === model || m.label === model
|
| 238 |
-
);
|
| 239 |
-
if (!selectedModel) {
|
| 240 |
-
return NextResponse.json(
|
| 241 |
-
{ ok: false, error: "Invalid model selected" },
|
| 242 |
-
{ status: 400 }
|
| 243 |
-
);
|
| 244 |
-
}
|
| 245 |
-
|
| 246 |
-
let token = userToken;
|
| 247 |
-
let billTo: string | null = null;
|
| 248 |
-
|
| 249 |
-
/**
|
| 250 |
-
* Handle local usage token, this bypass the need for a user token
|
| 251 |
-
* and allows local testing without authentication.
|
| 252 |
-
* This is useful for development and testing purposes.
|
| 253 |
-
*/
|
| 254 |
-
if (process.env.HF_TOKEN && process.env.HF_TOKEN.length > 0) {
|
| 255 |
-
token = process.env.HF_TOKEN;
|
| 256 |
-
}
|
| 257 |
-
|
| 258 |
-
const ip = authHeaders.get("x-forwarded-for")?.includes(",")
|
| 259 |
-
? authHeaders.get("x-forwarded-for")?.split(",")[1].trim()
|
| 260 |
-
: authHeaders.get("x-forwarded-for");
|
| 261 |
-
|
| 262 |
-
if (!token) {
|
| 263 |
-
ipAddresses.set(ip, (ipAddresses.get(ip) || 0) + 1);
|
| 264 |
-
if (ipAddresses.get(ip) > MAX_REQUESTS_PER_IP) {
|
| 265 |
-
return NextResponse.json(
|
| 266 |
-
{
|
| 267 |
-
ok: false,
|
| 268 |
-
openLogin: true,
|
| 269 |
-
message: "Log In to continue using the service",
|
| 270 |
-
},
|
| 271 |
-
{ status: 429 }
|
| 272 |
-
);
|
| 273 |
-
}
|
| 274 |
-
|
| 275 |
-
token = process.env.DEFAULT_HF_TOKEN as string;
|
| 276 |
-
billTo = "huggingface";
|
| 277 |
-
}
|
| 278 |
-
|
| 279 |
-
const client = new InferenceClient(token);
|
| 280 |
-
|
| 281 |
-
const DEFAULT_PROVIDER = PROVIDERS.novita;
|
| 282 |
-
const selectedProvider =
|
| 283 |
-
provider === "auto"
|
| 284 |
-
? PROVIDERS[selectedModel.autoProvider as keyof typeof PROVIDERS]
|
| 285 |
-
: PROVIDERS[provider as keyof typeof PROVIDERS] ?? DEFAULT_PROVIDER;
|
| 286 |
-
|
| 287 |
-
try {
|
| 288 |
-
const response = await client.chatCompletion(
|
| 289 |
-
{
|
| 290 |
-
model: selectedModel.value,
|
| 291 |
-
provider: selectedProvider.id as any,
|
| 292 |
-
messages: [
|
| 293 |
-
{
|
| 294 |
-
role: "system",
|
| 295 |
-
content: FOLLOW_UP_SYSTEM_PROMPT,
|
| 296 |
-
},
|
| 297 |
-
{
|
| 298 |
-
role: "user",
|
| 299 |
-
content: previousPrompt
|
| 300 |
-
? previousPrompt
|
| 301 |
-
: "You are modifying the HTML file based on the user's request.",
|
| 302 |
-
},
|
| 303 |
-
{
|
| 304 |
-
role: "assistant",
|
| 305 |
-
|
| 306 |
-
content: `The current code is: \n\`\`\`html\n${html}\n\`\`\` ${
|
| 307 |
-
selectedElementHtml
|
| 308 |
-
? `\n\nYou have to update ONLY the following element, NOTHING ELSE: \n\n\`\`\`html\n${selectedElementHtml}\n\`\`\``
|
| 309 |
-
: ""
|
| 310 |
-
}`,
|
| 311 |
-
},
|
| 312 |
-
{
|
| 313 |
-
role: "user",
|
| 314 |
-
content: prompt,
|
| 315 |
-
},
|
| 316 |
-
],
|
| 317 |
-
...(selectedProvider.id !== "sambanova"
|
| 318 |
-
? {
|
| 319 |
-
max_tokens: selectedProvider.max_tokens,
|
| 320 |
-
}
|
| 321 |
-
: {}),
|
| 322 |
-
},
|
| 323 |
-
billTo ? { billTo } : {}
|
| 324 |
-
);
|
| 325 |
-
|
| 326 |
-
const chunk = response.choices[0]?.message?.content;
|
| 327 |
-
if (!chunk) {
|
| 328 |
-
return NextResponse.json(
|
| 329 |
-
{ ok: false, message: "No content returned from the model" },
|
| 330 |
-
{ status: 400 }
|
| 331 |
-
);
|
| 332 |
-
}
|
| 333 |
-
|
| 334 |
-
if (chunk) {
|
| 335 |
-
const updatedLines: number[][] = [];
|
| 336 |
-
let newHtml = html;
|
| 337 |
-
let position = 0;
|
| 338 |
-
let moreBlocks = true;
|
| 339 |
-
|
| 340 |
-
while (moreBlocks) {
|
| 341 |
-
const searchStartIndex = chunk.indexOf(SEARCH_START, position);
|
| 342 |
-
if (searchStartIndex === -1) {
|
| 343 |
-
moreBlocks = false;
|
| 344 |
-
continue;
|
| 345 |
-
}
|
| 346 |
-
|
| 347 |
-
const dividerIndex = chunk.indexOf(DIVIDER, searchStartIndex);
|
| 348 |
-
if (dividerIndex === -1) {
|
| 349 |
-
moreBlocks = false;
|
| 350 |
-
continue;
|
| 351 |
-
}
|
| 352 |
-
|
| 353 |
-
const replaceEndIndex = chunk.indexOf(REPLACE_END, dividerIndex);
|
| 354 |
-
if (replaceEndIndex === -1) {
|
| 355 |
-
moreBlocks = false;
|
| 356 |
-
continue;
|
| 357 |
-
}
|
| 358 |
-
|
| 359 |
-
const searchBlock = chunk.substring(
|
| 360 |
-
searchStartIndex + SEARCH_START.length,
|
| 361 |
-
dividerIndex
|
| 362 |
-
);
|
| 363 |
-
const replaceBlock = chunk.substring(
|
| 364 |
-
dividerIndex + DIVIDER.length,
|
| 365 |
-
replaceEndIndex
|
| 366 |
-
);
|
| 367 |
-
|
| 368 |
-
if (searchBlock.trim() === "") {
|
| 369 |
-
newHtml = `${replaceBlock}\n${newHtml}`;
|
| 370 |
-
updatedLines.push([1, replaceBlock.split("\n").length]);
|
| 371 |
-
} else {
|
| 372 |
-
const blockPosition = newHtml.indexOf(searchBlock);
|
| 373 |
-
if (blockPosition !== -1) {
|
| 374 |
-
const beforeText = newHtml.substring(0, blockPosition);
|
| 375 |
-
const startLineNumber = beforeText.split("\n").length;
|
| 376 |
-
const replaceLines = replaceBlock.split("\n").length;
|
| 377 |
-
const endLineNumber = startLineNumber + replaceLines - 1;
|
| 378 |
-
|
| 379 |
-
updatedLines.push([startLineNumber, endLineNumber]);
|
| 380 |
-
newHtml = newHtml.replace(searchBlock, replaceBlock);
|
| 381 |
-
}
|
| 382 |
-
}
|
| 383 |
-
|
| 384 |
-
position = replaceEndIndex + REPLACE_END.length;
|
| 385 |
-
}
|
| 386 |
-
|
| 387 |
-
return NextResponse.json({
|
| 388 |
-
ok: true,
|
| 389 |
-
html: newHtml,
|
| 390 |
-
updatedLines,
|
| 391 |
-
});
|
| 392 |
-
} else {
|
| 393 |
-
return NextResponse.json(
|
| 394 |
-
{ ok: false, message: "No content returned from the model" },
|
| 395 |
-
{ status: 400 }
|
| 396 |
-
);
|
| 397 |
-
}
|
| 398 |
-
} catch (error: any) {
|
| 399 |
-
if (error.message?.includes("exceeded your monthly included credits")) {
|
| 400 |
-
return NextResponse.json(
|
| 401 |
-
{
|
| 402 |
-
ok: false,
|
| 403 |
-
openProModal: true,
|
| 404 |
-
message: error.message,
|
| 405 |
-
},
|
| 406 |
-
{ status: 402 }
|
| 407 |
-
);
|
| 408 |
-
}
|
| 409 |
-
return NextResponse.json(
|
| 410 |
-
{
|
| 411 |
-
ok: false,
|
| 412 |
-
openSelectProvider: true,
|
| 413 |
-
message:
|
| 414 |
-
error.message || "An error occurred while processing your request.",
|
| 415 |
-
},
|
| 416 |
-
{ status: 500 }
|
| 417 |
-
);
|
| 418 |
-
}
|
| 419 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/api/auth/route.ts
DELETED
|
@@ -1,86 +0,0 @@
|
|
| 1 |
-
import { NextRequest, NextResponse } from "next/server";
|
| 2 |
-
|
| 3 |
-
export async function POST(req: NextRequest) {
|
| 4 |
-
const body = await req.json();
|
| 5 |
-
const { code } = body;
|
| 6 |
-
|
| 7 |
-
if (!code) {
|
| 8 |
-
return NextResponse.json(
|
| 9 |
-
{ error: "Code is required" },
|
| 10 |
-
{
|
| 11 |
-
status: 400,
|
| 12 |
-
headers: {
|
| 13 |
-
"Content-Type": "application/json",
|
| 14 |
-
},
|
| 15 |
-
}
|
| 16 |
-
);
|
| 17 |
-
}
|
| 18 |
-
|
| 19 |
-
const Authorization = `Basic ${Buffer.from(
|
| 20 |
-
`${process.env.OAUTH_CLIENT_ID}:${process.env.OAUTH_CLIENT_SECRET}`
|
| 21 |
-
).toString("base64")}`;
|
| 22 |
-
|
| 23 |
-
const host =
|
| 24 |
-
req.headers.get("host") ?? req.headers.get("origin") ?? "localhost:3000";
|
| 25 |
-
|
| 26 |
-
const url = host.includes("/spaces/enzostvs")
|
| 27 |
-
? "enzostvs-deepsite.hf.space"
|
| 28 |
-
: host;
|
| 29 |
-
const redirect_uri =
|
| 30 |
-
`${host.includes("localhost") ? "http://" : "https://"}` +
|
| 31 |
-
url +
|
| 32 |
-
"/auth/callback";
|
| 33 |
-
const request_auth = await fetch("https://huggingface.co/oauth/token", {
|
| 34 |
-
method: "POST",
|
| 35 |
-
headers: {
|
| 36 |
-
"Content-Type": "application/x-www-form-urlencoded",
|
| 37 |
-
Authorization,
|
| 38 |
-
},
|
| 39 |
-
body: new URLSearchParams({
|
| 40 |
-
grant_type: "authorization_code",
|
| 41 |
-
code,
|
| 42 |
-
redirect_uri,
|
| 43 |
-
}),
|
| 44 |
-
});
|
| 45 |
-
|
| 46 |
-
const response = await request_auth.json();
|
| 47 |
-
if (!response.access_token) {
|
| 48 |
-
return NextResponse.json(
|
| 49 |
-
{ error: "Failed to retrieve access token" },
|
| 50 |
-
{
|
| 51 |
-
status: 400,
|
| 52 |
-
headers: {
|
| 53 |
-
"Content-Type": "application/json",
|
| 54 |
-
},
|
| 55 |
-
}
|
| 56 |
-
);
|
| 57 |
-
}
|
| 58 |
-
|
| 59 |
-
const userResponse = await fetch("https://huggingface.co/api/whoami-v2", {
|
| 60 |
-
headers: {
|
| 61 |
-
Authorization: `Bearer ${response.access_token}`,
|
| 62 |
-
},
|
| 63 |
-
});
|
| 64 |
-
|
| 65 |
-
if (!userResponse.ok) {
|
| 66 |
-
return NextResponse.json(
|
| 67 |
-
{ user: null, errCode: userResponse.status },
|
| 68 |
-
{ status: userResponse.status }
|
| 69 |
-
);
|
| 70 |
-
}
|
| 71 |
-
const user = await userResponse.json();
|
| 72 |
-
|
| 73 |
-
return NextResponse.json(
|
| 74 |
-
{
|
| 75 |
-
access_token: response.access_token,
|
| 76 |
-
expires_in: response.expires_in,
|
| 77 |
-
user,
|
| 78 |
-
},
|
| 79 |
-
{
|
| 80 |
-
status: 200,
|
| 81 |
-
headers: {
|
| 82 |
-
"Content-Type": "application/json",
|
| 83 |
-
},
|
| 84 |
-
}
|
| 85 |
-
);
|
| 86 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/api/me/projects/[namespace]/[repoId]/route.ts
DELETED
|
@@ -1,237 +0,0 @@
|
|
| 1 |
-
import { NextRequest, NextResponse } from "next/server";
|
| 2 |
-
import { RepoDesignation, spaceInfo, uploadFile } from "@huggingface/hub";
|
| 3 |
-
|
| 4 |
-
import { isAuthenticated } from "@/lib/auth";
|
| 5 |
-
import Project from "@/models/Project";
|
| 6 |
-
import dbConnect from "@/lib/mongodb";
|
| 7 |
-
import { getPTag } from "@/lib/utils";
|
| 8 |
-
|
| 9 |
-
export async function GET(
|
| 10 |
-
req: NextRequest,
|
| 11 |
-
{ params }: { params: Promise<{ namespace: string; repoId: string }> }
|
| 12 |
-
) {
|
| 13 |
-
const user = await isAuthenticated();
|
| 14 |
-
|
| 15 |
-
if (user instanceof NextResponse || !user) {
|
| 16 |
-
return NextResponse.json({ message: "Unauthorized" }, { status: 401 });
|
| 17 |
-
}
|
| 18 |
-
|
| 19 |
-
await dbConnect();
|
| 20 |
-
const param = await params;
|
| 21 |
-
const { namespace, repoId } = param;
|
| 22 |
-
|
| 23 |
-
const project = await Project.findOne({
|
| 24 |
-
user_id: user.id,
|
| 25 |
-
space_id: `${namespace}/${repoId}`,
|
| 26 |
-
}).lean();
|
| 27 |
-
if (!project) {
|
| 28 |
-
return NextResponse.json(
|
| 29 |
-
{
|
| 30 |
-
ok: false,
|
| 31 |
-
error: "Project not found",
|
| 32 |
-
},
|
| 33 |
-
{ status: 404 }
|
| 34 |
-
);
|
| 35 |
-
}
|
| 36 |
-
const space_url = `https://huggingface.co/spaces/${namespace}/${repoId}/raw/main/index.html`;
|
| 37 |
-
try {
|
| 38 |
-
const space = await spaceInfo({
|
| 39 |
-
name: namespace + "/" + repoId,
|
| 40 |
-
accessToken: user.token as string,
|
| 41 |
-
additionalFields: ["author"],
|
| 42 |
-
});
|
| 43 |
-
|
| 44 |
-
if (!space || space.sdk !== "static") {
|
| 45 |
-
return NextResponse.json(
|
| 46 |
-
{
|
| 47 |
-
ok: false,
|
| 48 |
-
error: "Space is not a static space",
|
| 49 |
-
},
|
| 50 |
-
{ status: 404 }
|
| 51 |
-
);
|
| 52 |
-
}
|
| 53 |
-
if (space.author !== user.name) {
|
| 54 |
-
return NextResponse.json(
|
| 55 |
-
{
|
| 56 |
-
ok: false,
|
| 57 |
-
error: "Space does not belong to the authenticated user",
|
| 58 |
-
},
|
| 59 |
-
{ status: 403 }
|
| 60 |
-
);
|
| 61 |
-
}
|
| 62 |
-
|
| 63 |
-
const response = await fetch(space_url);
|
| 64 |
-
if (!response.ok) {
|
| 65 |
-
return NextResponse.json(
|
| 66 |
-
{
|
| 67 |
-
ok: false,
|
| 68 |
-
error: "Failed to fetch space HTML",
|
| 69 |
-
},
|
| 70 |
-
{ status: 404 }
|
| 71 |
-
);
|
| 72 |
-
}
|
| 73 |
-
let html = await response.text();
|
| 74 |
-
// remove the last p tag including this url https://enzostvs-deepsite.hf.space
|
| 75 |
-
html = html.replace(getPTag(namespace + "/" + repoId), "");
|
| 76 |
-
|
| 77 |
-
return NextResponse.json(
|
| 78 |
-
{
|
| 79 |
-
project: {
|
| 80 |
-
...project,
|
| 81 |
-
html,
|
| 82 |
-
},
|
| 83 |
-
ok: true,
|
| 84 |
-
},
|
| 85 |
-
{ status: 200 }
|
| 86 |
-
);
|
| 87 |
-
|
| 88 |
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
| 89 |
-
} catch (error: any) {
|
| 90 |
-
if (error.statusCode === 404) {
|
| 91 |
-
await Project.deleteOne({
|
| 92 |
-
user_id: user.id,
|
| 93 |
-
space_id: `${namespace}/${repoId}`,
|
| 94 |
-
});
|
| 95 |
-
return NextResponse.json(
|
| 96 |
-
{ error: "Space not found", ok: false },
|
| 97 |
-
{ status: 404 }
|
| 98 |
-
);
|
| 99 |
-
}
|
| 100 |
-
return NextResponse.json(
|
| 101 |
-
{ error: error.message, ok: false },
|
| 102 |
-
{ status: 500 }
|
| 103 |
-
);
|
| 104 |
-
}
|
| 105 |
-
}
|
| 106 |
-
|
| 107 |
-
export async function PUT(
|
| 108 |
-
req: NextRequest,
|
| 109 |
-
{ params }: { params: Promise<{ namespace: string; repoId: string }> }
|
| 110 |
-
) {
|
| 111 |
-
const user = await isAuthenticated();
|
| 112 |
-
|
| 113 |
-
if (user instanceof NextResponse || !user) {
|
| 114 |
-
return NextResponse.json({ message: "Unauthorized" }, { status: 401 });
|
| 115 |
-
}
|
| 116 |
-
|
| 117 |
-
await dbConnect();
|
| 118 |
-
const param = await params;
|
| 119 |
-
const { namespace, repoId } = param;
|
| 120 |
-
const { html, prompts } = await req.json();
|
| 121 |
-
|
| 122 |
-
const project = await Project.findOne({
|
| 123 |
-
user_id: user.id,
|
| 124 |
-
space_id: `${namespace}/${repoId}`,
|
| 125 |
-
}).lean();
|
| 126 |
-
if (!project) {
|
| 127 |
-
return NextResponse.json(
|
| 128 |
-
{
|
| 129 |
-
ok: false,
|
| 130 |
-
error: "Project not found",
|
| 131 |
-
},
|
| 132 |
-
{ status: 404 }
|
| 133 |
-
);
|
| 134 |
-
}
|
| 135 |
-
|
| 136 |
-
const repo: RepoDesignation = {
|
| 137 |
-
type: "space",
|
| 138 |
-
name: `${namespace}/${repoId}`,
|
| 139 |
-
};
|
| 140 |
-
|
| 141 |
-
const newHtml = html.replace(/<\/body>/, `${getPTag(repo.name)}</body>`);
|
| 142 |
-
const file = new File([newHtml], "index.html", { type: "text/html" });
|
| 143 |
-
await uploadFile({
|
| 144 |
-
repo,
|
| 145 |
-
file,
|
| 146 |
-
accessToken: user.token as string,
|
| 147 |
-
commitTitle: `${prompts[prompts.length - 1]} - Follow Up Deployment`,
|
| 148 |
-
});
|
| 149 |
-
|
| 150 |
-
await Project.updateOne(
|
| 151 |
-
{ user_id: user.id, space_id: `${namespace}/${repoId}` },
|
| 152 |
-
{
|
| 153 |
-
$set: {
|
| 154 |
-
prompts: [
|
| 155 |
-
...(project && "prompts" in project ? project.prompts : []),
|
| 156 |
-
...prompts,
|
| 157 |
-
],
|
| 158 |
-
},
|
| 159 |
-
}
|
| 160 |
-
);
|
| 161 |
-
return NextResponse.json({ ok: true }, { status: 200 });
|
| 162 |
-
}
|
| 163 |
-
|
| 164 |
-
export async function POST(
|
| 165 |
-
req: NextRequest,
|
| 166 |
-
{ params }: { params: Promise<{ namespace: string; repoId: string }> }
|
| 167 |
-
) {
|
| 168 |
-
const user = await isAuthenticated();
|
| 169 |
-
|
| 170 |
-
if (user instanceof NextResponse || !user) {
|
| 171 |
-
return NextResponse.json({ message: "Unauthorized" }, { status: 401 });
|
| 172 |
-
}
|
| 173 |
-
|
| 174 |
-
await dbConnect();
|
| 175 |
-
const param = await params;
|
| 176 |
-
const { namespace, repoId } = param;
|
| 177 |
-
|
| 178 |
-
const space = await spaceInfo({
|
| 179 |
-
name: namespace + "/" + repoId,
|
| 180 |
-
accessToken: user.token as string,
|
| 181 |
-
additionalFields: ["author"],
|
| 182 |
-
});
|
| 183 |
-
|
| 184 |
-
if (!space || space.sdk !== "static") {
|
| 185 |
-
return NextResponse.json(
|
| 186 |
-
{
|
| 187 |
-
ok: false,
|
| 188 |
-
error: "Space is not a static space",
|
| 189 |
-
},
|
| 190 |
-
{ status: 404 }
|
| 191 |
-
);
|
| 192 |
-
}
|
| 193 |
-
if (space.author !== user.name) {
|
| 194 |
-
return NextResponse.json(
|
| 195 |
-
{
|
| 196 |
-
ok: false,
|
| 197 |
-
error: "Space does not belong to the authenticated user",
|
| 198 |
-
},
|
| 199 |
-
{ status: 403 }
|
| 200 |
-
);
|
| 201 |
-
}
|
| 202 |
-
|
| 203 |
-
const project = await Project.findOne({
|
| 204 |
-
user_id: user.id,
|
| 205 |
-
space_id: `${namespace}/${repoId}`,
|
| 206 |
-
}).lean();
|
| 207 |
-
if (project) {
|
| 208 |
-
// redirect to the project page if it already exists
|
| 209 |
-
return NextResponse.json(
|
| 210 |
-
{
|
| 211 |
-
ok: false,
|
| 212 |
-
error: "Project already exists",
|
| 213 |
-
redirect: `/projects/${namespace}/${repoId}`,
|
| 214 |
-
},
|
| 215 |
-
{ status: 400 }
|
| 216 |
-
);
|
| 217 |
-
}
|
| 218 |
-
|
| 219 |
-
const newProject = new Project({
|
| 220 |
-
user_id: user.id,
|
| 221 |
-
space_id: `${namespace}/${repoId}`,
|
| 222 |
-
prompts: [],
|
| 223 |
-
});
|
| 224 |
-
|
| 225 |
-
await newProject.save();
|
| 226 |
-
return NextResponse.json(
|
| 227 |
-
{
|
| 228 |
-
ok: true,
|
| 229 |
-
project: {
|
| 230 |
-
id: newProject._id,
|
| 231 |
-
space_id: newProject.space_id,
|
| 232 |
-
prompts: newProject.prompts,
|
| 233 |
-
},
|
| 234 |
-
},
|
| 235 |
-
{ status: 201 }
|
| 236 |
-
);
|
| 237 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/api/me/projects/route.ts
DELETED
|
@@ -1,126 +0,0 @@
|
|
| 1 |
-
import { NextRequest, NextResponse } from "next/server";
|
| 2 |
-
import { createRepo, RepoDesignation, uploadFiles } from "@huggingface/hub";
|
| 3 |
-
|
| 4 |
-
import { isAuthenticated } from "@/lib/auth";
|
| 5 |
-
import Project from "@/models/Project";
|
| 6 |
-
import dbConnect from "@/lib/mongodb";
|
| 7 |
-
import { COLORS, getPTag } from "@/lib/utils";
|
| 8 |
-
// import type user
|
| 9 |
-
export async function GET() {
|
| 10 |
-
const user = await isAuthenticated();
|
| 11 |
-
|
| 12 |
-
if (user instanceof NextResponse || !user) {
|
| 13 |
-
return NextResponse.json({ message: "Unauthorized" }, { status: 401 });
|
| 14 |
-
}
|
| 15 |
-
|
| 16 |
-
await dbConnect();
|
| 17 |
-
|
| 18 |
-
const projects = await Project.find({
|
| 19 |
-
user_id: user?.id,
|
| 20 |
-
})
|
| 21 |
-
.sort({ _createdAt: -1 })
|
| 22 |
-
.limit(100)
|
| 23 |
-
.lean();
|
| 24 |
-
if (!projects) {
|
| 25 |
-
return NextResponse.json(
|
| 26 |
-
{
|
| 27 |
-
ok: false,
|
| 28 |
-
projects: [],
|
| 29 |
-
},
|
| 30 |
-
{ status: 404 }
|
| 31 |
-
);
|
| 32 |
-
}
|
| 33 |
-
return NextResponse.json(
|
| 34 |
-
{
|
| 35 |
-
ok: true,
|
| 36 |
-
projects,
|
| 37 |
-
},
|
| 38 |
-
{ status: 200 }
|
| 39 |
-
);
|
| 40 |
-
}
|
| 41 |
-
|
| 42 |
-
/**
|
| 43 |
-
* This API route creates a new project in Hugging Face Spaces.
|
| 44 |
-
* It requires an Authorization header with a valid token and a JSON body with the project details.
|
| 45 |
-
*/
|
| 46 |
-
export async function POST(request: NextRequest) {
|
| 47 |
-
const user = await isAuthenticated();
|
| 48 |
-
|
| 49 |
-
if (user instanceof NextResponse || !user) {
|
| 50 |
-
return NextResponse.json({ message: "Unauthorized" }, { status: 401 });
|
| 51 |
-
}
|
| 52 |
-
|
| 53 |
-
const { title, html, prompts } = await request.json();
|
| 54 |
-
|
| 55 |
-
if (!title || !html) {
|
| 56 |
-
return NextResponse.json(
|
| 57 |
-
{ message: "Title and HTML content are required.", ok: false },
|
| 58 |
-
{ status: 400 }
|
| 59 |
-
);
|
| 60 |
-
}
|
| 61 |
-
|
| 62 |
-
await dbConnect();
|
| 63 |
-
|
| 64 |
-
try {
|
| 65 |
-
let readme = "";
|
| 66 |
-
let newHtml = html;
|
| 67 |
-
|
| 68 |
-
const newTitle = title
|
| 69 |
-
.toLowerCase()
|
| 70 |
-
.replace(/[^a-z0-9]+/g, "-")
|
| 71 |
-
.split("-")
|
| 72 |
-
.filter(Boolean)
|
| 73 |
-
.join("-")
|
| 74 |
-
.slice(0, 96);
|
| 75 |
-
|
| 76 |
-
const repo: RepoDesignation = {
|
| 77 |
-
type: "space",
|
| 78 |
-
name: `${user.name}/${newTitle}`,
|
| 79 |
-
};
|
| 80 |
-
|
| 81 |
-
const { repoUrl } = await createRepo({
|
| 82 |
-
repo,
|
| 83 |
-
accessToken: user.token as string,
|
| 84 |
-
});
|
| 85 |
-
const colorFrom = COLORS[Math.floor(Math.random() * COLORS.length)];
|
| 86 |
-
const colorTo = COLORS[Math.floor(Math.random() * COLORS.length)];
|
| 87 |
-
readme = `---
|
| 88 |
-
title: ${newTitle}
|
| 89 |
-
emoji: 🐳
|
| 90 |
-
colorFrom: ${colorFrom}
|
| 91 |
-
colorTo: ${colorTo}
|
| 92 |
-
sdk: static
|
| 93 |
-
pinned: false
|
| 94 |
-
tags:
|
| 95 |
-
- deepsite
|
| 96 |
-
---
|
| 97 |
-
|
| 98 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference`;
|
| 99 |
-
|
| 100 |
-
newHtml = html.replace(/<\/body>/, `${getPTag(repo.name)}</body>`);
|
| 101 |
-
const file = new File([newHtml], "index.html", { type: "text/html" });
|
| 102 |
-
const readmeFile = new File([readme], "README.md", {
|
| 103 |
-
type: "text/markdown",
|
| 104 |
-
});
|
| 105 |
-
const files = [file, readmeFile];
|
| 106 |
-
await uploadFiles({
|
| 107 |
-
repo,
|
| 108 |
-
files,
|
| 109 |
-
accessToken: user.token as string,
|
| 110 |
-
commitTitle: `${prompts[prompts.length - 1]} - Initial Deployment`,
|
| 111 |
-
});
|
| 112 |
-
const path = repoUrl.split("/").slice(-2).join("/");
|
| 113 |
-
const project = await Project.create({
|
| 114 |
-
user_id: user.id,
|
| 115 |
-
space_id: path,
|
| 116 |
-
prompts,
|
| 117 |
-
});
|
| 118 |
-
return NextResponse.json({ project, path, ok: true }, { status: 201 });
|
| 119 |
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
| 120 |
-
} catch (err: any) {
|
| 121 |
-
return NextResponse.json(
|
| 122 |
-
{ error: err.message, ok: false },
|
| 123 |
-
{ status: 500 }
|
| 124 |
-
);
|
| 125 |
-
}
|
| 126 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/api/me/route.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
| 1 |
-
import { headers } from "next/headers";
|
| 2 |
-
import { NextResponse } from "next/server";
|
| 3 |
-
|
| 4 |
-
export async function GET() {
|
| 5 |
-
const authHeaders = await headers();
|
| 6 |
-
const token = authHeaders.get("Authorization");
|
| 7 |
-
if (!token) {
|
| 8 |
-
return NextResponse.json({ user: null, errCode: 401 }, { status: 401 });
|
| 9 |
-
}
|
| 10 |
-
|
| 11 |
-
const userResponse = await fetch("https://huggingface.co/api/whoami-v2", {
|
| 12 |
-
headers: {
|
| 13 |
-
Authorization: `${token}`,
|
| 14 |
-
},
|
| 15 |
-
});
|
| 16 |
-
|
| 17 |
-
if (!userResponse.ok) {
|
| 18 |
-
return NextResponse.json(
|
| 19 |
-
{ user: null, errCode: userResponse.status },
|
| 20 |
-
{ status: userResponse.status }
|
| 21 |
-
);
|
| 22 |
-
}
|
| 23 |
-
const user = await userResponse.json();
|
| 24 |
-
return NextResponse.json({ user, errCode: null }, { status: 200 });
|
| 25 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/api/re-design/route.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
| 1 |
-
import { NextRequest, NextResponse } from "next/server";
|
| 2 |
-
|
| 3 |
-
export async function PUT(request: NextRequest) {
|
| 4 |
-
const body = await request.json();
|
| 5 |
-
const { url } = body;
|
| 6 |
-
|
| 7 |
-
if (!url) {
|
| 8 |
-
return NextResponse.json({ error: "URL is required" }, { status: 400 });
|
| 9 |
-
}
|
| 10 |
-
|
| 11 |
-
try {
|
| 12 |
-
const response = await fetch(
|
| 13 |
-
`https://r.jina.ai/${encodeURIComponent(url)}`,
|
| 14 |
-
{
|
| 15 |
-
method: "POST",
|
| 16 |
-
}
|
| 17 |
-
);
|
| 18 |
-
if (!response.ok) {
|
| 19 |
-
return NextResponse.json(
|
| 20 |
-
{ error: "Failed to fetch redesign" },
|
| 21 |
-
{ status: 500 }
|
| 22 |
-
);
|
| 23 |
-
}
|
| 24 |
-
const markdown = await response.text();
|
| 25 |
-
return NextResponse.json(
|
| 26 |
-
{
|
| 27 |
-
ok: true,
|
| 28 |
-
markdown,
|
| 29 |
-
},
|
| 30 |
-
{ status: 200 }
|
| 31 |
-
);
|
| 32 |
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
| 33 |
-
} catch (error: any) {
|
| 34 |
-
return NextResponse.json(
|
| 35 |
-
{ error: error.message || "An error occurred" },
|
| 36 |
-
{ status: 500 }
|
| 37 |
-
);
|
| 38 |
-
}
|
| 39 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/auth/callback/page.tsx
DELETED
|
@@ -1,72 +0,0 @@
|
|
| 1 |
-
"use client";
|
| 2 |
-
import Link from "next/link";
|
| 3 |
-
import { useUser } from "@/hooks/useUser";
|
| 4 |
-
import { use, useState } from "react";
|
| 5 |
-
import { useMount, useTimeoutFn } from "react-use";
|
| 6 |
-
|
| 7 |
-
import { Button } from "@/components/ui/button";
|
| 8 |
-
export default function AuthCallback({
|
| 9 |
-
searchParams,
|
| 10 |
-
}: {
|
| 11 |
-
searchParams: Promise<{ code: string }>;
|
| 12 |
-
}) {
|
| 13 |
-
const [showButton, setShowButton] = useState(false);
|
| 14 |
-
const { code } = use(searchParams);
|
| 15 |
-
const { loginFromCode } = useUser();
|
| 16 |
-
|
| 17 |
-
useMount(async () => {
|
| 18 |
-
if (code) {
|
| 19 |
-
await loginFromCode(code);
|
| 20 |
-
}
|
| 21 |
-
});
|
| 22 |
-
|
| 23 |
-
useTimeoutFn(
|
| 24 |
-
() => setShowButton(true),
|
| 25 |
-
7000 // Show button after 5 seconds
|
| 26 |
-
);
|
| 27 |
-
|
| 28 |
-
return (
|
| 29 |
-
<div className="h-screen flex flex-col justify-center items-center">
|
| 30 |
-
<div className="!rounded-2xl !p-0 !bg-white !border-neutral-100 min-w-xs text-center overflow-hidden ring-[8px] ring-white/20">
|
| 31 |
-
<header className="bg-neutral-50 p-6 border-b border-neutral-200/60">
|
| 32 |
-
<div className="flex items-center justify-center -space-x-4 mb-3">
|
| 33 |
-
<div className="size-9 rounded-full bg-pink-200 shadow-2xs flex items-center justify-center text-xl opacity-50">
|
| 34 |
-
🚀
|
| 35 |
-
</div>
|
| 36 |
-
<div className="size-11 rounded-full bg-amber-200 shadow-2xl flex items-center justify-center text-2xl z-2">
|
| 37 |
-
👋
|
| 38 |
-
</div>
|
| 39 |
-
<div className="size-9 rounded-full bg-sky-200 shadow-2xs flex items-center justify-center text-xl opacity-50">
|
| 40 |
-
🙌
|
| 41 |
-
</div>
|
| 42 |
-
</div>
|
| 43 |
-
<p className="text-xl font-semibold text-neutral-950">
|
| 44 |
-
Login In Progress...
|
| 45 |
-
</p>
|
| 46 |
-
<p className="text-sm text-neutral-500 mt-1.5">
|
| 47 |
-
Wait a moment while we log you in with your code.
|
| 48 |
-
</p>
|
| 49 |
-
</header>
|
| 50 |
-
<main className="space-y-4 p-6">
|
| 51 |
-
<div>
|
| 52 |
-
<p className="text-sm text-neutral-700 mb-4 max-w-xs">
|
| 53 |
-
If you are not redirected automatically in the next 5 seconds,
|
| 54 |
-
please click the button below
|
| 55 |
-
</p>
|
| 56 |
-
{showButton ? (
|
| 57 |
-
<Link href="/">
|
| 58 |
-
<Button variant="black" className="relative">
|
| 59 |
-
Go to Home
|
| 60 |
-
</Button>
|
| 61 |
-
</Link>
|
| 62 |
-
) : (
|
| 63 |
-
<p className="text-xs text-neutral-500">
|
| 64 |
-
Please wait, we are logging you in...
|
| 65 |
-
</p>
|
| 66 |
-
)}
|
| 67 |
-
</div>
|
| 68 |
-
</main>
|
| 69 |
-
</div>
|
| 70 |
-
</div>
|
| 71 |
-
);
|
| 72 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/auth/page.tsx
DELETED
|
@@ -1,28 +0,0 @@
|
|
| 1 |
-
import { redirect } from "next/navigation";
|
| 2 |
-
import { Metadata } from "next";
|
| 3 |
-
|
| 4 |
-
import { getAuth } from "@/app/actions/auth";
|
| 5 |
-
|
| 6 |
-
export const revalidate = 1;
|
| 7 |
-
|
| 8 |
-
export const metadata: Metadata = {
|
| 9 |
-
robots: "noindex, nofollow",
|
| 10 |
-
};
|
| 11 |
-
|
| 12 |
-
export default async function Auth() {
|
| 13 |
-
const loginRedirectUrl = await getAuth();
|
| 14 |
-
if (loginRedirectUrl) {
|
| 15 |
-
redirect(loginRedirectUrl);
|
| 16 |
-
}
|
| 17 |
-
|
| 18 |
-
return (
|
| 19 |
-
<div className="p-4">
|
| 20 |
-
<div className="border bg-red-500/10 border-red-500/20 text-red-500 px-5 py-3 rounded-lg">
|
| 21 |
-
<h1 className="text-xl font-bold">Error</h1>
|
| 22 |
-
<p className="text-sm">
|
| 23 |
-
An error occurred while trying to log in. Please try again later.
|
| 24 |
-
</p>
|
| 25 |
-
</div>
|
| 26 |
-
</div>
|
| 27 |
-
);
|
| 28 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/favicon.ico
DELETED
|
Binary file (25.9 kB)
|
|
|
app/layout.tsx
DELETED
|
@@ -1,108 +0,0 @@
|
|
| 1 |
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
| 2 |
-
import type { Metadata, Viewport } from "next";
|
| 3 |
-
import { Inter, PT_Sans } from "next/font/google";
|
| 4 |
-
import { cookies } from "next/headers";
|
| 5 |
-
|
| 6 |
-
import TanstackProvider from "@/components/providers/tanstack-query-provider";
|
| 7 |
-
import "@/assets/globals.css";
|
| 8 |
-
import { Toaster } from "@/components/ui/sonner";
|
| 9 |
-
import MY_TOKEN_KEY from "@/lib/get-cookie-name";
|
| 10 |
-
import { apiServer } from "@/lib/api";
|
| 11 |
-
import AppContext from "@/components/contexts/app-context";
|
| 12 |
-
import Script from "next/script";
|
| 13 |
-
|
| 14 |
-
const inter = Inter({
|
| 15 |
-
variable: "--font-inter-sans",
|
| 16 |
-
subsets: ["latin"],
|
| 17 |
-
});
|
| 18 |
-
|
| 19 |
-
const ptSans = PT_Sans({
|
| 20 |
-
variable: "--font-ptSans-mono",
|
| 21 |
-
subsets: ["latin"],
|
| 22 |
-
weight: ["400", "700"],
|
| 23 |
-
});
|
| 24 |
-
|
| 25 |
-
export const metadata: Metadata = {
|
| 26 |
-
title: "DeepSite | Build with AI ✨",
|
| 27 |
-
description:
|
| 28 |
-
"DeepSite is a web development tool that helps you build websites with AI, no code required. Let's deploy your website with DeepSite and enjoy the magic of AI.",
|
| 29 |
-
openGraph: {
|
| 30 |
-
title: "DeepSite | Build with AI ✨",
|
| 31 |
-
description:
|
| 32 |
-
"DeepSite is a web development tool that helps you build websites with AI, no code required. Let's deploy your website with DeepSite and enjoy the magic of AI.",
|
| 33 |
-
url: "https://deepsite.hf.co",
|
| 34 |
-
siteName: "DeepSite",
|
| 35 |
-
images: [
|
| 36 |
-
{
|
| 37 |
-
url: "https://deepsite.hf.co/banner.png",
|
| 38 |
-
width: 1200,
|
| 39 |
-
height: 630,
|
| 40 |
-
alt: "DeepSite Open Graph Image",
|
| 41 |
-
},
|
| 42 |
-
],
|
| 43 |
-
},
|
| 44 |
-
twitter: {
|
| 45 |
-
card: "summary_large_image",
|
| 46 |
-
title: "DeepSite | Build with AI ✨",
|
| 47 |
-
description:
|
| 48 |
-
"DeepSite is a web development tool that helps you build websites with AI, no code required. Let's deploy your website with DeepSite and enjoy the magic of AI.",
|
| 49 |
-
images: ["https://deepsite.hf.co/banner.png"],
|
| 50 |
-
},
|
| 51 |
-
appleWebApp: {
|
| 52 |
-
capable: true,
|
| 53 |
-
title: "DeepSite",
|
| 54 |
-
statusBarStyle: "black-translucent",
|
| 55 |
-
},
|
| 56 |
-
icons: {
|
| 57 |
-
icon: "/logo.svg",
|
| 58 |
-
shortcut: "/logo.svg",
|
| 59 |
-
apple: "/logo.svg",
|
| 60 |
-
},
|
| 61 |
-
};
|
| 62 |
-
|
| 63 |
-
export const viewport: Viewport = {
|
| 64 |
-
initialScale: 1,
|
| 65 |
-
maximumScale: 1,
|
| 66 |
-
themeColor: "#000000",
|
| 67 |
-
};
|
| 68 |
-
|
| 69 |
-
async function getMe() {
|
| 70 |
-
const cookieStore = await cookies();
|
| 71 |
-
const token = cookieStore.get(MY_TOKEN_KEY())?.value;
|
| 72 |
-
if (!token) return { user: null, errCode: null };
|
| 73 |
-
try {
|
| 74 |
-
const res = await apiServer.get("/me", {
|
| 75 |
-
headers: {
|
| 76 |
-
Authorization: `Bearer ${token}`,
|
| 77 |
-
},
|
| 78 |
-
});
|
| 79 |
-
return { user: res.data.user, errCode: null };
|
| 80 |
-
} catch (err: any) {
|
| 81 |
-
return { user: null, errCode: err.status };
|
| 82 |
-
}
|
| 83 |
-
}
|
| 84 |
-
|
| 85 |
-
export default async function RootLayout({
|
| 86 |
-
children,
|
| 87 |
-
}: Readonly<{
|
| 88 |
-
children: React.ReactNode;
|
| 89 |
-
}>) {
|
| 90 |
-
const data = await getMe();
|
| 91 |
-
return (
|
| 92 |
-
<html lang="en">
|
| 93 |
-
<Script
|
| 94 |
-
defer
|
| 95 |
-
data-domain="deepsite.hf.co"
|
| 96 |
-
src="https://plausible.io/js/script.js"
|
| 97 |
-
></Script>
|
| 98 |
-
<body
|
| 99 |
-
className={`${inter.variable} ${ptSans.variable} antialiased bg-black dark h-[100dvh] overflow-hidden`}
|
| 100 |
-
>
|
| 101 |
-
<Toaster richColors position="bottom-center" />
|
| 102 |
-
<TanstackProvider>
|
| 103 |
-
<AppContext me={data}>{children}</AppContext>
|
| 104 |
-
</TanstackProvider>
|
| 105 |
-
</body>
|
| 106 |
-
</html>
|
| 107 |
-
);
|
| 108 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/projects/[namespace]/[repoId]/page.tsx
DELETED
|
@@ -1,40 +0,0 @@
|
|
| 1 |
-
import { cookies } from "next/headers";
|
| 2 |
-
import { redirect } from "next/navigation";
|
| 3 |
-
|
| 4 |
-
import { apiServer } from "@/lib/api";
|
| 5 |
-
import MY_TOKEN_KEY from "@/lib/get-cookie-name";
|
| 6 |
-
import { AppEditor } from "@/components/editor";
|
| 7 |
-
|
| 8 |
-
async function getProject(namespace: string, repoId: string) {
|
| 9 |
-
// TODO replace with a server action
|
| 10 |
-
const cookieStore = await cookies();
|
| 11 |
-
const token = cookieStore.get(MY_TOKEN_KEY())?.value;
|
| 12 |
-
if (!token) return {};
|
| 13 |
-
try {
|
| 14 |
-
const { data } = await apiServer.get(
|
| 15 |
-
`/me/projects/${namespace}/${repoId}`,
|
| 16 |
-
{
|
| 17 |
-
headers: {
|
| 18 |
-
Authorization: `Bearer ${token}`,
|
| 19 |
-
},
|
| 20 |
-
}
|
| 21 |
-
);
|
| 22 |
-
|
| 23 |
-
return data.project;
|
| 24 |
-
} catch {
|
| 25 |
-
return {};
|
| 26 |
-
}
|
| 27 |
-
}
|
| 28 |
-
|
| 29 |
-
export default async function ProjectNamespacePage({
|
| 30 |
-
params,
|
| 31 |
-
}: {
|
| 32 |
-
params: Promise<{ namespace: string; repoId: string }>;
|
| 33 |
-
}) {
|
| 34 |
-
const { namespace, repoId } = await params;
|
| 35 |
-
const project = await getProject(namespace, repoId);
|
| 36 |
-
if (!project?.html) {
|
| 37 |
-
redirect("/projects");
|
| 38 |
-
}
|
| 39 |
-
return <AppEditor project={project} />;
|
| 40 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/projects/new/page.tsx
DELETED
|
@@ -1,5 +0,0 @@
|
|
| 1 |
-
import { AppEditor } from "@/components/editor";
|
| 2 |
-
|
| 3 |
-
export default function ProjectsNewPage() {
|
| 4 |
-
return <AppEditor />;
|
| 5 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|