Przeglądaj źródła

Rename SharePasswordForm to SharePasswordFrame, move /share-verify to /share/verify

jerryliao 2 dni temu
rodzic
commit
d69e653185

+ 2 - 2
islands/SharePasswordForm.tsx → islands/SharePasswordFrame.tsx

@@ -8,7 +8,7 @@ interface SharePasswordFormProps {
   title: string;
 }
 
-export default function SharePasswordForm(props: SharePasswordFormProps) {
+export default function SharePasswordFrame(props: SharePasswordFormProps) {
   const [password, setPassword] = useState("");
   const [error, setError] = useState(false);
 
@@ -17,7 +17,7 @@ export default function SharePasswordForm(props: SharePasswordFormProps) {
       setError(true);
       return;
     }
-    const resp = await fetch("/api/share-verify", {
+    const resp = await fetch("/api/share/verify", {
       method: "POST",
       headers: { "Content-Type": "application/json" },
       body: JSON.stringify({ id: props.id, password }),

+ 2 - 2
routes/[id].tsx

@@ -7,7 +7,7 @@ import { find } from "utils/db.ts";
 import { getCookies } from "@std/http";
 import TopBar from "../islands/TopBar.tsx";
 import Editor, { EditorMode } from "../islands/Editor.tsx";
-import SharePasswordForm from "../islands/SharePasswordForm.tsx";
+import SharePasswordFrame from "../islands/SharePasswordFrame.tsx";
 import PageContainer from "../components/layout/PageContainer.tsx";
 
 interface PostProps {
@@ -77,7 +77,7 @@ export default function Post(props: PageProps<PostProps>) {
           <title>{props.data.title}</title>
         </Head>
         <PageContainer>
-          <SharePasswordForm id={props.data.id} title={props.data.title} />
+          <SharePasswordFrame id={props.data.id} title={props.data.title} />
         </PageContainer>
       </>
     );

+ 0 - 0
routes/api/share.tsx → routes/api/share/index.tsx


+ 0 - 0
routes/api/share-verify.tsx → routes/api/share/verify.tsx


+ 8 - 8
tests/api/share_test.ts

@@ -63,7 +63,7 @@ Deno.test("API share - share a post", async () => {
       shared: 0,
     });
 
-    const { handler } = await import("../../routes/api/share.tsx");
+    const { handler } = await import("../../routes/api/share/index.tsx");
     const ctx = makeCtx("POST", {
       id: "share-post-1",
       shared: true,
@@ -96,7 +96,7 @@ Deno.test("API share - unshare a post", async () => {
       shared: 1,
     });
 
-    const { handler } = await import("../../routes/api/share.tsx");
+    const { handler } = await import("../../routes/api/share/index.tsx");
     const ctx = makeCtx("POST", {
       id: "unshare-post-1",
       shared: false,
@@ -117,7 +117,7 @@ Deno.test("API share - without token returns error", async () => {
   const dbPath = getTestDbPath();
   Deno.env.set("POSTDOWN_DB_PATH", dbPath);
   try {
-    const { handler } = await import("../../routes/api/share.tsx");
+    const { handler } = await import("../../routes/api/share/index.tsx");
     const ctx = makeCtx("POST", {
       id: "some-post",
       shared: true,
@@ -152,7 +152,7 @@ Deno.test("API share - share another user's post returns error", async () => {
       "password2",
     );
 
-    const { handler } = await import("../../routes/api/share.tsx");
+    const { handler } = await import("../../routes/api/share/index.tsx");
     const ctx = makeCtx("POST", {
       id: "other-post-1",
       shared: true,
@@ -182,7 +182,7 @@ Deno.test("API share - share with password stores hashed password", async () =>
       shared: 0,
     });
 
-    const { handler } = await import("../../routes/api/share.tsx");
+    const { handler } = await import("../../routes/api/share/index.tsx");
     const ctx = makeCtx("POST", {
       id: "pw-post-1",
       shared: true,
@@ -223,7 +223,7 @@ Deno.test("API share - unshare clears password", async () => {
       share_password: hashedPw,
     });
 
-    const { handler } = await import("../../routes/api/share.tsx");
+    const { handler } = await import("../../routes/api/share/index.tsx");
     const ctx = makeCtx("POST", {
       id: "pw-post-2",
       shared: false,
@@ -262,7 +262,7 @@ Deno.test("API share-verify - correct password returns success and sets cookie",
       share_password: hashedPw,
     });
 
-    const { handler } = await import("../../routes/api/share-verify.tsx");
+    const { handler } = await import("../../routes/api/share/verify.tsx");
     const ctx = makeCtx("POST", {
       id: "verify-post-1",
       password: "secret123",
@@ -304,7 +304,7 @@ Deno.test("API share-verify - wrong password returns error", async () => {
       share_password: hashedPw,
     });
 
-    const { handler } = await import("../../routes/api/share-verify.tsx");
+    const { handler } = await import("../../routes/api/share/verify.tsx");
     const ctx = makeCtx("POST", {
       id: "verify-post-2",
       password: "wrongpassword",