Skip to content

Commit 0fa96eb

Browse files
committed
subscribe with email
1 parent ba05a84 commit 0fa96eb

File tree

5 files changed

+76
-19
lines changed

5 files changed

+76
-19
lines changed

app/(default)/_components/hero/index.tsx

+5-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@ export default function () {
1212
Discover awesome AI Videos made with Sora.
1313
</h2>
1414

15+
<Input />
16+
1517
<div className="mx-auto max-w-6xl text-slate-400 text-sm mt-4 text-center">
16-
Sora text-to-video API is not available, all the videos are generated
17-
by OpenAI's red team.
18+
Sora text-to-video API is not available, we'll get you notified when
19+
it's live.
1820
</div>
21+
1922
<svg
2023
viewBox="0 0 1024 1024"
2124
className="absolute left-1/2 top-1/2 -z-10 h-[64rem] w-[64rem] -translate-x-1/2"

app/(default)/_components/input/index.tsx

+18-14
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,37 @@ import { useRouter } from "next/navigation";
77

88
export default function () {
99
const router = useRouter();
10-
const [description, setDescription] = useState("");
10+
const [email, setEmail] = useState("");
1111

1212
const handleSubmit = async () => {
13-
if (!description) {
14-
toast.error("please descibe your story");
13+
if (!email) {
14+
toast.error("please enter your email");
1515
return;
1616
}
1717

1818
try {
1919
const params = {
20-
description: description,
20+
email: email,
2121
};
22-
const resp = await fetch("/api/gen-video", {
22+
const resp = await fetch("/api/save-user", {
2323
method: "POST",
2424
headers: {
2525
"Content-Type": "application/json",
2626
},
2727
body: JSON.stringify(params),
2828
});
2929
const { code, message, data } = await resp.json();
30+
if (code !== 0) {
31+
toast.error(message);
32+
return;
33+
}
3034
if (data) {
31-
toast.success("We generated an random video for your story.");
32-
router.push(`/video/${data.uuid}`);
35+
toast.success("subscribe ok");
36+
setEmail("");
3337
}
3438
} catch (e) {
35-
toast.error("gen video failed");
36-
console.log("gen video failed", e);
39+
toast.error("subscribe failed");
40+
console.log("subscribe failed", e);
3741
}
3842
};
3943

@@ -49,20 +53,20 @@ export default function () {
4953
return (
5054
<div className="mx-auto mt-6 flex max-w-md gap-x-4">
5155
<input
52-
type="text"
56+
type="email"
5357
required
5458
className="min-w-0 flex-auto rounded-md border-0 bg-white/5 px-3.5 py-2 text-white shadow-sm ring-1 ring-inset ring-white/10 focus:ring-2 focus:ring-inset focus:ring-white sm:text-sm sm:leading-6"
55-
placeholder="Describe your story"
56-
value={description}
57-
onChange={(e) => setDescription(e.target.value)}
59+
placeholder="Enter your email"
60+
value={email}
61+
onChange={(e) => setEmail(e.target.value)}
5862
onKeyDown={handleInputKeydown}
5963
/>
6064
<button
6165
type="button"
6266
className="flex-none rounded-md bg-white px-3.5 py-2.5 text-sm font-semibold text-gray-900 shadow-sm hover:bg-gray-100 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-white"
6367
onClick={handleSubmit}
6468
>
65-
Surprise me
69+
Subscribe
6670
</button>
6771
</div>
6872
);

app/(default)/video/[uuid]/page.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ export default async function ({ params }: { params: { uuid: string } }) {
3535
<h1 className="mx-auto max-w-4xl text-center text-3xl font-bold tracking-tight text-primary sm:text-6xl">
3636
Sora AI Video Showcase
3737
</h1>
38-
<h2 className="mx-auto mt-2 max-w-xl text-center text-xl leading-8 text-gray-300">
39-
AI Video made with Sora.
40-
</h2>
38+
<p className="mx-auto mt-2 px-4 max-w-xl text-center text-xl leading-8 text-gray-300">
39+
This video is made with Sora, by OpenAI's red team.
40+
</p>
4141

4242
{video && (
4343
<div className="relative z-10 mt-8 bg-gray-900 pb-20 sm:mt-16 sm:pb-24 xl:pb-0">

app/api/save-user/route.ts

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { respData, respErr } from "@/lib/resp";
2+
3+
import { User } from "@/types/user";
4+
import { genUuid } from "@/lib";
5+
import { saveUser } from "@/services/user";
6+
7+
export async function POST(req: Request) {
8+
try {
9+
const { email } = await req.json();
10+
if (!email) {
11+
return respErr("invalid params");
12+
}
13+
if (!email.includes("@")) {
14+
return respErr("invalid email");
15+
}
16+
17+
const created_at = new Date().toISOString();
18+
const user_uuid = genUuid();
19+
20+
const user: User = {
21+
email: email,
22+
nickname: "",
23+
avatar_url: "",
24+
created_at: created_at,
25+
uuid: user_uuid,
26+
};
27+
console.log("save user info", user);
28+
29+
await saveUser(user);
30+
31+
return respData(user);
32+
} catch (e) {
33+
console.log("save user failed", e);
34+
return respErr("save user failed");
35+
}
36+
}

services/user.ts

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { findUserByEmail, insertUser } from "@/models/user";
2+
3+
import { User } from "@/types/user";
4+
5+
export async function saveUser(user: User) {
6+
try {
7+
const existUser = await findUserByEmail(user.email);
8+
if (!existUser) {
9+
await insertUser(user);
10+
}
11+
} catch (e) {
12+
console.log("save user failed: ", e);
13+
}
14+
}

0 commit comments

Comments
 (0)