From a2b9540cf22bbd431cdefcd47db3e9478c449810 Mon Sep 17 00:00:00 2001 From: oiov Date: Wed, 26 Mar 2025 22:00:52 +0800 Subject: [PATCH] feat: support multi domain config --- app/(marketing)/page.tsx | 2 +- app/(protected)/dashboard/page.tsx | 1 - app/(protected)/dashboard/urls/url-list.tsx | 8 ++-- app/api/url/add/route.ts | 3 +- app/api/url/admin/delete/route.ts | 1 - app/api/url/admin/update/route.ts | 3 +- app/api/url/update/active/route.ts | 1 - app/api/url/update/route.ts | 3 +- components/forms/url-form.tsx | 47 +++++++++++++++---- config/site.ts | 2 + env.mjs | 2 + lib/dto/short-urls.ts | 4 ++ lib/validations/url.ts | 1 + .../20240705091917_init/migration.sql | 1 + prisma/schema.prisma | 1 + public/sw.js.map | 2 +- types/index.d.ts | 1 + 17 files changed, 63 insertions(+), 20 deletions(-) diff --git a/app/(marketing)/page.tsx b/app/(marketing)/page.tsx index cdc6e01..7120805 100644 --- a/app/(marketing)/page.tsx +++ b/app/(marketing)/page.tsx @@ -1,3 +1,4 @@ +import { siteConfig } from "@/config/site"; import HeroLanding, { LandingImages } from "@/components/sections/hero-landing"; import { PricingSection } from "@/components/sections/pricing"; @@ -7,7 +8,6 @@ export default function IndexPage() { return ( <> - {/* */} diff --git a/app/(protected)/dashboard/page.tsx b/app/(protected)/dashboard/page.tsx index 946fb4e..333ec99 100644 --- a/app/(protected)/dashboard/page.tsx +++ b/app/(protected)/dashboard/page.tsx @@ -1,4 +1,3 @@ -import Link from "next/link"; import { redirect } from "next/navigation"; import { siteConfig } from "@/config/site"; diff --git a/app/(protected)/dashboard/urls/url-list.tsx b/app/(protected)/dashboard/urls/url-list.tsx index 7e0cbb7..56718f7 100644 --- a/app/(protected)/dashboard/urls/url-list.tsx +++ b/app/(protected)/dashboard/urls/url-list.tsx @@ -353,7 +353,7 @@ export default function UserUrlsList({ user, action }: UrlListProps) { { setSelectedUrlId(short.id!); setShowQrcode(!isShowQrcode); - handleQrcode(`https://wr.do/s/${short.url}`); + handleQrcode( + `https://${short.prefix}/s/${short.url}`, + ); }} > diff --git a/app/api/url/add/route.ts b/app/api/url/add/route.ts index e000f0f..f558d0f 100644 --- a/app/api/url/add/route.ts +++ b/app/api/url/add/route.ts @@ -25,13 +25,14 @@ export async function POST(req: Request) { const { data } = await req.json(); - const { target, url, visible, active, expiration } = + const { target, url, prefix, visible, active, expiration } = createUrlSchema.parse(data); const res = await createUserShortUrl({ userId: user.id, userName: user.name || "Anonymous", target, url, + prefix, visible, active, expiration, diff --git a/app/api/url/admin/delete/route.ts b/app/api/url/admin/delete/route.ts index bf7f44a..9a9ae6d 100644 --- a/app/api/url/admin/delete/route.ts +++ b/app/api/url/admin/delete/route.ts @@ -1,5 +1,4 @@ import { env } from "@/env.mjs"; -import { getUserRecords } from "@/lib/dto/cloudflare-dns-record"; import { deleteUserShortUrl } from "@/lib/dto/short-urls"; import { checkUserStatus } from "@/lib/dto/user"; import { getCurrentUser } from "@/lib/session"; diff --git a/app/api/url/admin/update/route.ts b/app/api/url/admin/update/route.ts index ec44819..2593df8 100644 --- a/app/api/url/admin/update/route.ts +++ b/app/api/url/admin/update/route.ts @@ -24,7 +24,7 @@ export async function POST(req: Request) { }); } - const { target, url, visible, active, id, expiration } = + const { target, url, prefix, visible, active, id, expiration } = createUrlSchema.parse(data); const res = await updateUserShortUrl({ id, @@ -32,6 +32,7 @@ export async function POST(req: Request) { userName: "", target, url, + prefix, visible, active, expiration, diff --git a/app/api/url/update/active/route.ts b/app/api/url/update/active/route.ts index da15070..8aa2ef7 100644 --- a/app/api/url/update/active/route.ts +++ b/app/api/url/update/active/route.ts @@ -6,7 +6,6 @@ import { } from "@/lib/dto/short-urls"; import { checkUserStatus } from "@/lib/dto/user"; import { getCurrentUser } from "@/lib/session"; -import { createUrlSchema } from "@/lib/validations/url"; export async function POST(req: Request) { try { diff --git a/app/api/url/update/route.ts b/app/api/url/update/route.ts index 533dbfd..f7c4574 100644 --- a/app/api/url/update/route.ts +++ b/app/api/url/update/route.ts @@ -18,13 +18,14 @@ export async function POST(req: Request) { }); } - const { target, url, visible, active, id, expiration } = + const { target, url, prefix, visible, active, id, expiration } = createUrlSchema.parse(data); const res = await updateUserShortUrl({ id, userId: user.id, userName: user.name || "Anonymous", target, + prefix, url, visible, active, diff --git a/components/forms/url-form.tsx b/components/forms/url-form.tsx index cad7bf4..4214c3f 100644 --- a/components/forms/url-form.tsx +++ b/components/forms/url-form.tsx @@ -7,6 +7,7 @@ import { Sparkles } from "lucide-react"; import { useForm } from "react-hook-form"; import { toast } from "sonner"; +import { siteConfig } from "@/config/site"; import { ShortUrlFormData } from "@/lib/dto/short-urls"; import { EXPIRATION_ENUMS } from "@/lib/enums"; import { generateUrlSuffix } from "@/lib/utils"; @@ -63,6 +64,7 @@ export function UrlForm({ target: initData?.target || "", url: initData?.url || "", active: initData?.active || 1, + prefix: initData?.prefix || siteConfig.shortDomains[0], visible: initData?.visible || 0, expiration: initData?.expiration || "-1", }, @@ -148,7 +150,7 @@ export function UrlForm({ onSubmit={onSubmit} >
- +
- +
- - https://wr.do/s/ - + + {/* + /s/ + */} ) : (

- A random url suffix. + A random url suffix. Final url like「wr.do/s/suffix」

)}
@@ -241,7 +262,15 @@ export function UrlForm({ Expiration time, default for never.

- + {/*
+

+ Your Final URL: +

+

+ {getValues("prefix")}/s/{getValues("url")} +

+
*/} + {/*