From 88087f5807d09fbf9ecddc990ec2a0c34c64a3ca Mon Sep 17 00:00:00 2001 From: JimmyLv Date: Fri, 3 Mar 2023 21:24:37 +0800 Subject: [PATCH] feat: add logic to setLicenseKey --- pages/[...slug].tsx | 43 +++++++++++++++++++++++++++---------------- pages/shop.tsx | 2 +- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/pages/[...slug].tsx b/pages/[...slug].tsx index 330c80bf..63736caf 100644 --- a/pages/[...slug].tsx +++ b/pages/[...slug].tsx @@ -1,5 +1,6 @@ import type { NextPage } from "next"; import Image from "next/image"; +import { useSearchParams } from "next/navigation"; import { useRouter } from "next/router"; import { useEffect, useState } from "react"; import { toast, Toaster } from "react-hot-toast"; @@ -19,11 +20,17 @@ if (typeof window !== "undefined") { export const Home: NextPage = () => { const router = useRouter(); const urlState = router.query.slug; + const searchParams = useSearchParams(); + const licenseKey = searchParams.get("license_key"); const [curVideo, setCurVideo] = useState(""); const [currentBvId, setCurrentBvId] = useState(""); - const [apiKey, setAPIKey] = useLocalStorage("user-openai-apikey"); + const [userKey, setUserKey] = useLocalStorage("user-openai-apikey"); const { loading, summary, resetSummary, summarize } = useSummarize(); + useEffect(() => { + licenseKey && setUserKey(licenseKey); + }, [licenseKey]); + useEffect(() => { const isValidatedUrl = urlState && @@ -70,7 +77,7 @@ export const Home: NextPage = () => { return toast.error("暂不支持此视频链接"); } - await summarize(bvId, apiKey); + await summarize(bvId, userKey); setTimeout(() => { window.scrollTo({ top: document.body.scrollHeight, behavior: "smooth" }); }, 10); @@ -188,22 +195,26 @@ export const Home: NextPage = () => {
setAPIKey(e.target.value)} + value={userKey} + onChange={(e) => setUserKey(e.target.value)} className="mx-auto my-4 w-full appearance-none rounded-lg rounded-md border bg-transparent py-2 pl-2 text-sm leading-6 text-slate-900 shadow-sm ring-1 ring-slate-200 placeholder:text-slate-400 focus:outline-none focus:ring-2 focus:ring-blue-500" - placeholder={"填你的 OpenAI API Key: sk-xxxxxx 或者购买的 License Key: xxx-CCDE-xxx"} + placeholder={ + "填你的 OpenAI API Key: sk-xxxxxx 或者购买的 License Key: xxx-CCDE-xxx" + } /> -

- 如何获取你自己的 OpenAI API{" "} - - https://platform.openai.com/account/api-keys - -

+
+
+ 如何获取你自己的 License Key + + https://shop.jimmylv.cn + +
+
diff --git a/pages/shop.tsx b/pages/shop.tsx index 6ed84f70..f54cf99b 100644 --- a/pages/shop.tsx +++ b/pages/shop.tsx @@ -5,7 +5,7 @@ export default () => { return (

- 伤不起了啊!每天都能用 {RATE_LIMIT_COUNT} 次,请点击 + 次数用完啦!每天都能用 {RATE_LIMIT_COUNT} 次,请点击