Skip to content

Let's use AI to Earn!

youtobe 相关

daoyianb04fcc87b314
diff --git a/.env.development b/.env.development
index 3fbbf513..183041cc 100644
--- a/.env.development
+++ b/.env.development
@@ -1,3 +1,5 @@
NEXT_PUBLIC_EVN=dev
-NEXT_PUBLIC_API_URL=http://localhost:3000/api/
\ No newline at end of file
+NEXT_PUBLIC_API_URL=http://localhost:3000/api/
+
+# NEXT_PUBLIC_API_URL=http://localhost:3000/api/
\ No newline at end of file
diff --git a/src/api/youtube.ts b/src/api/youtube.ts
new file mode 100644
index 00000000..a18dc82f
--- /dev/null
+++ b/src/api/youtube.ts
@@ -0,0 +1,6 @@
+import sxRequest from "@/utils/request";
+
+// 获取 YouTube 授权 URL
+export const getYouTubeAuthUrlApi = (mail: string) => {
+ return sxRequest.get<{ url: string }>(`plat/youtube/auth/url?mail=${mail}`);
+};
\ No newline at end of file
diff --git a/src/app/[lng]/youtube/page.tsx b/src/app/[lng]/youtube/page.tsx
new file mode 100644
index 00000000..ec17b065
--- /dev/null
+++ b/src/app/[lng]/youtube/page.tsx
@@ -0,0 +1,86 @@
+'use client';
+
+import React, { useState } from 'react';
+import { useTransClient } from '@/app/i18n/client';
+import { Button, Input, message } from 'antd';
+import { MailOutlined } from '@ant-design/icons';
+import { getYouTubeAuthUrlApi } from '@/api/youtube';
+
+const YouTubeAuth: React.FC = () => {
+ const { t } = useTransClient('youtube');
+ const [email, setEmail] = useState('');
+ const [loading, setLoading] = useState(false);
+
+ const handleAuth = async () => {
+ if (!email) {
+ message.error(t('pleaseEnterEmail'));
+ return;
+ }
+
+ if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) {
+ message.error(t('invalidEmail'));
+ return;
+ }
+
+ setLoading(true);
+ try {
+ const response = await getYouTubeAuthUrlApi(email);
+ if (response?.data?.url) {
+ window.location.href = response.data.url;
+ }
+ } catch (error) {
+ console.error('获取授权 URL 失败:', error);
+ message.error(t('authFailed'));
+ } finally {
+ setLoading(false);
+ }
+ };
+
+ return (
+ <div className="min-h-screen flex items-center justify-center bg-gray-50">
+ <div className="max-w-md w-full space-y-8 p-8 bg-white rounded-lg shadow-lg">
+ <div>
+ <h2 className="mt-6 text-center text-3xl font-extrabold text-gray-900">
+ {t('youtubeAuth')}
+ </h2>
+ <p className="mt-2 text-center text-sm text-gray-600">
+ {t('authDescription')}
+ </p>
+ </div>
+ <div className="mt-8 space-y-6">
+ <div className="rounded-md shadow-sm -space-y-px">
+ <div>
+ <label htmlFor="email" className="sr-only">
+ {t('email')}
+ </label>
+ <Input
+ id="email"
+ name="email"
+ type="email"
+ required
+ className="appearance-none rounded-md relative block w-full px-3 py-2 border border-gray-300 placeholder-gray-500 text-gray-900 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 focus:z-10 sm:text-sm"
+ placeholder={t('enterEmail')}
+ value={email}
+ onChange={(e) => setEmail(e.target.value)}
+ prefix={<MailOutlined />}
+ />
+ </div>
+ </div>
+
+ <div>
+ <Button
+ type="primary"
+ onClick={handleAuth}
+ loading={loading}
+ className="group relative w-full flex justify-center py-2 px-4 border border-transparent text-sm font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500"
+ >
+ {t('authorize')}
+ </Button>
+ </div>
+ </div>
+ </div>
+ </div>
+ );
+};
+
+export default YouTubeAuth;
\ No newline at end of file
diff --git a/src/app/i18n/locales/en/youtube.json b/src/app/i18n/locales/en/youtube.json
new file mode 100644
index 00000000..e243af2c
--- /dev/null
+++ b/src/app/i18n/locales/en/youtube.json
@@ -0,0 +1,10 @@
+{
+ "youtubeAuth": "YouTube Authorization",
+ "authDescription": "Please enter your email address to get YouTube authorization",
+ "email": "Email",
+ "enterEmail": "Enter your email address",
+ "authorize": "Authorize",
+ "pleaseEnterEmail": "Please enter your email address",
+ "invalidEmail": "Please enter a valid email address",
+ "authFailed": "Authorization failed, please try again later"
+}
\ No newline at end of file
diff --git a/src/app/i18n/locales/zh-CN/youtube.json b/src/app/i18n/locales/zh-CN/youtube.json
new file mode 100644
index 00000000..9c79673e
--- /dev/null
+++ b/src/app/i18n/locales/zh-CN/youtube.json
@@ -0,0 +1,10 @@
+{
+ "youtubeAuth": "YouTube 授权",
+ "authDescription": "请输入您的邮箱地址以获取 YouTube 授权",
+ "email": "邮箱",
+ "enterEmail": "请输入邮箱地址",
+ "authorize": "授权",
+ "pleaseEnterEmail": "请输入邮箱地址",
+ "invalidEmail": "请输入有效的邮箱地址",
+ "authFailed": "授权失败,请稍后重试"
+}
\ No newline at end of file
diff --git a/src/app/layout/LyaoutHeader.tsx b/src/app/layout/LyaoutHeader.tsx
index 12cdbf5b..0badcf2d 100644
--- a/src/app/layout/LyaoutHeader.tsx
+++ b/src/app/layout/LyaoutHeader.tsx
@@ -82,7 +82,7 @@ const LyaoutHeader = memo(
const toggleLanguage = () => {
const newLng = userStore.lang === "zh-CN" ? "en" : "zh-CN";
userStore.setLang(newLng);
- location.href = `/${newLng}` + location.pathname.replace(`/${userStore.lang}`, "");
+ router.push(`/${newLng}${location.pathname.replace(`/${userStore.lang}`, "")}`);
};
useEffect(() => {
diff --git a/src/app/layout/routerData.ts b/src/app/layout/routerData.ts
index fdee0312..a8edf779 100644
--- a/src/app/layout/routerData.ts
+++ b/src/app/layout/routerData.ts
@@ -37,6 +37,11 @@ export const routerData: IRouterDataItem[] = [
translationKey: "hotContent",
path: "/hot-content",
},
+ {
+ name: "Youtobe",
+ translationKey: "youtube",
+ path: "/youtube",
+ },
];
const recursion = (