read only editor
Browse files- app/api/me/projects/[namespace]/[repoId]/route.ts +23 -29
- app/api/me/route.ts +0 -1
- components/editor/index.tsx +1 -0
- components/my-projects/index.tsx +2 -0
- hooks/useAi.ts +3 -0
app/api/me/projects/[namespace]/[repoId]/route.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
import { NextRequest, NextResponse } from "next/server";
|
| 2 |
-
import { RepoDesignation, spaceInfo, listFiles, deleteRepo, listCommits } from "@huggingface/hub";
|
| 3 |
|
| 4 |
import { isAuthenticated } from "@/lib/auth";
|
| 5 |
import { Commit, Page } from "@/types";
|
|
@@ -37,13 +37,6 @@ export async function DELETE(
|
|
| 37 |
{ status: 403 }
|
| 38 |
);
|
| 39 |
}
|
| 40 |
-
|
| 41 |
-
if (space.private) {
|
| 42 |
-
return NextResponse.json(
|
| 43 |
-
{ ok: false, error: "Your space must be public to access it." },
|
| 44 |
-
{ status: 403 }
|
| 45 |
-
);
|
| 46 |
-
}
|
| 47 |
|
| 48 |
const repo: RepoDesignation = {
|
| 49 |
type: "space",
|
|
@@ -103,15 +96,15 @@ export async function GET(
|
|
| 103 |
{ status: 403 }
|
| 104 |
);
|
| 105 |
}
|
| 106 |
-
if (space.private) {
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
}
|
| 115 |
|
| 116 |
const repo: RepoDesignation = {
|
| 117 |
type: "space",
|
|
@@ -125,20 +118,21 @@ export async function GET(
|
|
| 125 |
|
| 126 |
for await (const fileInfo of listFiles({repo, accessToken: user.token as string})) {
|
| 127 |
if (fileInfo.path.endsWith(".html")) {
|
| 128 |
-
const
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
|
|
|
|
|
|
| 137 |
htmlFiles.push({
|
| 138 |
path: fileInfo.path,
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
}
|
| 142 |
}
|
| 143 |
}
|
| 144 |
if (fileInfo.type === "directory" && fileInfo.path === "images") {
|
|
|
|
| 1 |
import { NextRequest, NextResponse } from "next/server";
|
| 2 |
+
import { RepoDesignation, spaceInfo, listFiles, deleteRepo, listCommits, downloadFile } from "@huggingface/hub";
|
| 3 |
|
| 4 |
import { isAuthenticated } from "@/lib/auth";
|
| 5 |
import { Commit, Page } from "@/types";
|
|
|
|
| 37 |
{ status: 403 }
|
| 38 |
);
|
| 39 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
const repo: RepoDesignation = {
|
| 42 |
type: "space",
|
|
|
|
| 96 |
{ status: 403 }
|
| 97 |
);
|
| 98 |
}
|
| 99 |
+
// if (space.private) {
|
| 100 |
+
// return NextResponse.json(
|
| 101 |
+
// {
|
| 102 |
+
// ok: false,
|
| 103 |
+
// error: "Space must be public to access it",
|
| 104 |
+
// },
|
| 105 |
+
// { status: 403 }
|
| 106 |
+
// );
|
| 107 |
+
// }
|
| 108 |
|
| 109 |
const repo: RepoDesignation = {
|
| 110 |
type: "space",
|
|
|
|
| 118 |
|
| 119 |
for await (const fileInfo of listFiles({repo, accessToken: user.token as string})) {
|
| 120 |
if (fileInfo.path.endsWith(".html")) {
|
| 121 |
+
const blob = await downloadFile({ repo, accessToken: user.token as string, path: fileInfo.path, raw: true });
|
| 122 |
+
const html = await blob?.text();
|
| 123 |
+
if (!html) {
|
| 124 |
+
continue;
|
| 125 |
+
}
|
| 126 |
+
if (fileInfo.path === "index.html") {
|
| 127 |
+
htmlFiles.unshift({
|
| 128 |
+
path: fileInfo.path,
|
| 129 |
+
html,
|
| 130 |
+
});
|
| 131 |
+
} else {
|
| 132 |
htmlFiles.push({
|
| 133 |
path: fileInfo.path,
|
| 134 |
+
html,
|
| 135 |
+
});
|
|
|
|
| 136 |
}
|
| 137 |
}
|
| 138 |
if (fileInfo.type === "directory" && fileInfo.path === "images") {
|
app/api/me/route.ts
CHANGED
|
@@ -31,7 +31,6 @@ export async function GET() {
|
|
| 31 |
}
|
| 32 |
})) {
|
| 33 |
if (
|
| 34 |
-
!space.private &&
|
| 35 |
space.sdk === "static" &&
|
| 36 |
Array.isArray((space.cardData as { tags?: string[] })?.tags) &&
|
| 37 |
(
|
|
|
|
| 31 |
}
|
| 32 |
})) {
|
| 33 |
if (
|
|
|
|
| 34 |
space.sdk === "static" &&
|
| 35 |
Array.isArray((space.cardData as { tags?: string[] })?.tags) &&
|
| 36 |
(
|
components/editor/index.tsx
CHANGED
|
@@ -71,6 +71,7 @@ export const AppEditor = ({
|
|
| 71 |
horizontal: "hidden",
|
| 72 |
},
|
| 73 |
wordWrap: "on",
|
|
|
|
| 74 |
}}
|
| 75 |
value={currentPageData.html}
|
| 76 |
onChange={(value) => {
|
|
|
|
| 71 |
horizontal: "hidden",
|
| 72 |
},
|
| 73 |
wordWrap: "on",
|
| 74 |
+
readOnly: true,
|
| 75 |
}}
|
| 76 |
value={currentPageData.html}
|
| 77 |
onChange={(value) => {
|
components/my-projects/index.tsx
CHANGED
|
@@ -13,6 +13,7 @@ import { Button } from "@/components/ui/button";
|
|
| 13 |
import { useProModal } from "@/components/contexts/pro-context";
|
| 14 |
import { api } from "@/lib/api";
|
| 15 |
import { NotLogged } from "../not-logged/not-logged";
|
|
|
|
| 16 |
|
| 17 |
export function MyProjects() {
|
| 18 |
const { user, projects, setProjects } = useUser();
|
|
@@ -69,6 +70,7 @@ export function MyProjects() {
|
|
| 69 |
Upgrade to PRO
|
| 70 |
</Button>
|
| 71 |
) : (
|
|
|
|
| 72 |
<div></div>
|
| 73 |
)}
|
| 74 |
</header>
|
|
|
|
| 13 |
import { useProModal } from "@/components/contexts/pro-context";
|
| 14 |
import { api } from "@/lib/api";
|
| 15 |
import { NotLogged } from "../not-logged/not-logged";
|
| 16 |
+
import { LoadProject } from "./load-project";
|
| 17 |
|
| 18 |
export function MyProjects() {
|
| 19 |
const { user, projects, setProjects } = useUser();
|
|
|
|
| 70 |
Upgrade to PRO
|
| 71 |
</Button>
|
| 72 |
) : (
|
| 73 |
+
// <LoadProject onSuccess={() => {}} />
|
| 74 |
<div></div>
|
| 75 |
)}
|
| 76 |
</header>
|
hooks/useAi.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { useEditor } from "./useEditor";
|
|
| 8 |
import { Page, EnhancedSettings } from "@/types";
|
| 9 |
import { api } from "@/lib/api";
|
| 10 |
import { useRouter } from "next/navigation";
|
|
|
|
| 11 |
|
| 12 |
export const useAi = (onScrollToBottom?: () => void) => {
|
| 13 |
const client = useQueryClient();
|
|
@@ -17,6 +18,7 @@ export const useAi = (onScrollToBottom?: () => void) => {
|
|
| 17 |
const [storageProvider, setStorageProvider] = useLocalStorage("provider", "auto");
|
| 18 |
const [storageModel, setStorageModel] = useLocalStorage("model", MODELS[0].value);
|
| 19 |
const router = useRouter();
|
|
|
|
| 20 |
|
| 21 |
const { data: isAiWorking = false } = useQuery({
|
| 22 |
queryKey: ["ai.isAiWorking"],
|
|
@@ -111,6 +113,7 @@ export const useAi = (onScrollToBottom?: () => void) => {
|
|
| 111 |
setIsAiWorking(false);
|
| 112 |
router.replace(`/projects/${response.data.space.project.space_id}`);
|
| 113 |
setProject(response.data.space);
|
|
|
|
| 114 |
toast.success("AI responded successfully");
|
| 115 |
if (audio.current) audio.current.play();
|
| 116 |
}
|
|
|
|
| 8 |
import { Page, EnhancedSettings } from "@/types";
|
| 9 |
import { api } from "@/lib/api";
|
| 10 |
import { useRouter } from "next/navigation";
|
| 11 |
+
import { useUser } from "./useUser";
|
| 12 |
|
| 13 |
export const useAi = (onScrollToBottom?: () => void) => {
|
| 14 |
const client = useQueryClient();
|
|
|
|
| 18 |
const [storageProvider, setStorageProvider] = useLocalStorage("provider", "auto");
|
| 19 |
const [storageModel, setStorageModel] = useLocalStorage("model", MODELS[0].value);
|
| 20 |
const router = useRouter();
|
| 21 |
+
const { projects, setProjects } = useUser();
|
| 22 |
|
| 23 |
const { data: isAiWorking = false } = useQuery({
|
| 24 |
queryKey: ["ai.isAiWorking"],
|
|
|
|
| 113 |
setIsAiWorking(false);
|
| 114 |
router.replace(`/projects/${response.data.space.project.space_id}`);
|
| 115 |
setProject(response.data.space);
|
| 116 |
+
setProjects([...projects, response.data.space]);
|
| 117 |
toast.success("AI responded successfully");
|
| 118 |
if (audio.current) audio.current.play();
|
| 119 |
}
|