解决编译错误

This commit is contained in:
ymk
2025-08-19 18:57:10 +08:00
parent 505167ea92
commit 6ff08a0340
7 changed files with 38 additions and 28 deletions

View File

@@ -36,7 +36,7 @@ export default function Page() {
<h2 className="text-3xl font-bold text-center mb-12">
{t("toolTitle")}
</h2>
<Editor textProp={text} backgroundProp={undefined}></Editor>
<Editor textProp={text} backgroundProp={undefined} effectProp={undefined}></Editor>
</section>
{/* Features Section */}

View File

@@ -1,5 +1,5 @@
import { OnlyPage } from "@/components/editor/OnlyPage";
import { decodeText } from "@/lib/utils";
import { decode } from "@/lib/utils";
import { Metadata } from "next";
import { getTranslations } from "next-intl/server";
@@ -7,20 +7,21 @@ export default async function Page({ params }: { params: Promise<{ data: string
const { data } = await params
let backgroundProp, textProp
let backgroundProp, textProp, effectProp
if (data) {
try {
const { bg, text } = JSON.parse(decodeText(data));
const { bg, text, effect } = decode(data);
backgroundProp = bg;
textProp = text;
effectProp = effect;
} catch (error) {
console.error("parse data from url error", error)
}
}
return (<OnlyPage textProp={textProp} backgroundProp={backgroundProp}></OnlyPage>)
return (<OnlyPage textProp={textProp} backgroundProp={backgroundProp} effectProp={effectProp}></OnlyPage>)
}
@@ -39,8 +40,7 @@ export async function generateMetadata({
if (data) {
try {
const { bg, text } = JSON.parse(decodeText(data));
const { bg, text } = decode(data);
backgroundProp = bg;
textProp = text;
} catch (error) {

View File

@@ -7,7 +7,7 @@ import { Metadata } from "next";
import { getTranslations } from "next-intl/server";
const host = process.env.NEXT_PUBLIC_HOST;
export default function Page() {
return (<OnlyPage textProp={undefined} backgroundProp={undefined}></OnlyPage>)
return (<OnlyPage textProp={undefined} backgroundProp={undefined} effectProp={undefined}></OnlyPage>)
}
const locales = Locales;

View File

@@ -4,7 +4,7 @@ import { routing } from "@/i18n/routing";
import { getTranslations, setRequestLocale } from "next-intl/server";
import { jsonLdScriptProps } from "react-schemaorg";
import { WebSite } from "schema-dts";
import { Geist, Geist_Mono } from "next/font/google";
// import { Geist, Geist_Mono } from "next/font/google";
import { Analytics } from "@vercel/analytics/react";
import { SpeedInsights } from "@vercel/speed-insights/next";
import "../globals.css";
@@ -12,15 +12,15 @@ import { ThemeProvider } from "next-themes";
import { Theme } from "@radix-ui/themes";
const host = process.env.NEXT_PUBLIC_HOST;
const geistSans = Geist({
variable: "--font-geist-sans",
subsets: ["latin"],
});
// const geistSans = Geist({
// variable: "--font-geist-sans",
// subsets: ["latin"],
// });
const geistMono = Geist_Mono({
variable: "--font-geist-mono",
subsets: ["latin"],
});
// const geistMono = Geist_Mono({
// variable: "--font-geist-mono",
// subsets: ["latin"],
// });
export default async function RootLayout({
children,
@@ -66,7 +66,7 @@ export default async function RootLayout({
/>
</head>
<body
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
// className={`${geistSans.variable} ${geistMono.variable} antialiased`}
suppressHydrationWarning
>

View File

@@ -41,7 +41,7 @@ export default function HomePage() {
<Heading as="h2" size={"8"}>
{t("toolTitle")}
</Heading>
<Editor textProp={undefined} backgroundProp={undefined}></Editor>
<Editor textProp={undefined} backgroundProp={undefined} effectProp={undefined}></Editor>
</Flex>
</Section>

View File

@@ -6,7 +6,7 @@ import { BackgroundProp } from "./BackgroundSelector";
import { Text, Flex, Button, Select, AlertDialog, Code, AspectRatio } from "@radix-ui/themes";
import { getPicture, resize, init as threeInit, updateBackground, updateEffectProp, updateTextProp } from "./ThreeTools";
import { TextProp } from "./TextSetting";
import { encodeText, getShareLink } from "@/lib/utils";
import { getShareLink } from "@/lib/utils";
import { EffectProp } from "./Effects";
const Sizes = [
@@ -198,11 +198,8 @@ export default function PreviewToolbar({
}
const bg = { ...background, image: null };
let txt = JSON.stringify({ bg, text });
txt = encodeText(txt);
const link = getShareLink(txt, locale);
const link = getShareLink({ bg, text }, locale);
setShareLink(link);

View File

@@ -2,18 +2,21 @@ import { clsx, type ClassValue } from "clsx";
import { twMerge } from "tailwind-merge";
import CryptoJS from "crypto-js";
import LZString from "lz-string";
import { BackgroundProp } from "@/components/common/BackgroundSelector";
import { EffectProp } from "@/components/common/Effects";
import { TextProp } from "@/components/common/TextSetting";
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}
const SECRET_KEY = "fast3dtext-ymk";
export function encodeText(text: string) {
function encodeText(text: string) {
const compressed = LZString.compressToEncodedURIComponent(text);
const encrypted = CryptoJS.AES.encrypt(compressed, SECRET_KEY).toString();
return encodeURIComponent(encrypted);
}
export function decodeText(encodedText: string) {
function decodeText(encodedText: string) {
const decoded = decodeURIComponent(encodedText);
const decrypted = CryptoJS.AES.decrypt(decoded, SECRET_KEY).toString(
CryptoJS.enc.Utf8
@@ -22,6 +25,16 @@ export function decodeText(encodedText: string) {
return decompressed;
}
export function getShareLink(data: string, locale: string) {
return `${window.location.origin}/${locale}/editor/${data}`;
export interface ShareObj {
bg: BackgroundProp;
text: TextProp;
effect?: EffectProp;
}
export function getShareLink(data: ShareObj, locale: string) {
const dataStr = JSON.stringify(data);
return `${window.location.origin}/${locale}/editor/${encodeText(dataStr)}`;
}
export function decode(data: string) {
const decoded = decodeText(data);
return JSON.parse(decoded) as ShareObj;
}