From e1bfa908075a13f78da436b01b6d9e3aa987599c Mon Sep 17 00:00:00 2001 From: oiov Date: Tue, 30 Jul 2024 14:35:39 +0800 Subject: [PATCH] upd --- app/(auth)/login/page.tsx | 12 ++- app/(marketing)/s/page.tsx | 3 - app/api/record/update/route.ts | 1 - app/api/s/route.ts | 31 ++++++ auth.config.ts | 2 +- components/forms/record-form.tsx | 29 +++-- components/layout/dashboard-sidebar.tsx | 69 ++++++------ components/layout/navbar.tsx | 5 +- components/layout/site-footer.tsx | 10 +- components/sections/hero-landing.tsx | 6 +- components/shared/icons.tsx | 2 + components/ui/form.tsx | 101 +++++++++--------- config/dashboard.ts | 10 +- config/marketing.ts | 2 +- lib/dto/short-urls.ts | 40 ++++++- lib/validations/record.ts | 2 +- middleware.ts | 38 ++++++- next.config.js | 5 + .../20240705091917_init/migration.sql | 15 ++- prisma/schema.prisma | 18 ++-- public/_static/wr.png | Bin 0 -> 4373 bytes public/site.webmanifest | 4 +- 22 files changed, 267 insertions(+), 138 deletions(-) delete mode 100644 app/(marketing)/s/page.tsx create mode 100644 app/api/s/route.ts create mode 100644 public/_static/wr.png diff --git a/app/(auth)/login/page.tsx b/app/(auth)/login/page.tsx index ba8adb2..f1a28e5 100644 --- a/app/(auth)/login/page.tsx +++ b/app/(auth)/login/page.tsx @@ -2,6 +2,7 @@ import { Suspense } from "react"; import { Metadata } from "next"; import Link from "next/link"; +import { siteConfig } from "@/config/site"; import { cn } from "@/lib/utils"; import { buttonVariants } from "@/components/ui/button"; import { UserAuthForm } from "@/components/forms/user-auth-form"; @@ -29,10 +30,13 @@ export default function LoginPage() {
- -

- Welcome back -

+ +
+ Welcome to{" "} + + {siteConfig.name} + +

Enter your email to sign in to your account

diff --git a/app/(marketing)/s/page.tsx b/app/(marketing)/s/page.tsx deleted file mode 100644 index b2432e2..0000000 --- a/app/(marketing)/s/page.tsx +++ /dev/null @@ -1,3 +0,0 @@ -export default function IndexPage() { - return <>; -} diff --git a/app/api/record/update/route.ts b/app/api/record/update/route.ts index 06b30b6..3d46381 100644 --- a/app/api/record/update/route.ts +++ b/app/api/record/update/route.ts @@ -18,7 +18,6 @@ export async function POST(req: Request) { } const { record, recordId } = await req.json(); - console.log(record, recordId); const data = await updateDNSRecord( CLOUDFLARE_ZONE_ID, diff --git a/app/api/s/route.ts b/app/api/s/route.ts new file mode 100644 index 0000000..53e24c7 --- /dev/null +++ b/app/api/s/route.ts @@ -0,0 +1,31 @@ +import { NextRequest, NextResponse } from "next/server"; + +import { createUserShortUrlMeta, getUrlBySuffix } from "@/lib/dto/short-urls"; + +export async function GET(req: NextRequest) { + try { + console.log("[api/s]", req.ip, req.geo); + + const url = new URL(req.url); + const slug = url.searchParams.get("slug"); + if (!slug) return Response.json(null); + + const res = await getUrlBySuffix(slug); + if (res?.target && res?.active === 1) { + await createUserShortUrlMeta({ + urlId: res.id, + click: 1, + ip: req.ip ?? "127.0.0.0", + city: req.geo?.city ?? "", + region: req.geo?.region ?? "", + country: req.geo?.country ?? "", + latitude: req.geo?.latitude ?? "", + longitude: req.geo?.longitude ?? "", + }); + return Response.json(res.target); + } + return Response.json(null); + } catch (error) { + return Response.json(null); + } +} diff --git a/auth.config.ts b/auth.config.ts index 95322ab..36041b6 100644 --- a/auth.config.ts +++ b/auth.config.ts @@ -22,7 +22,7 @@ export default { }), Resend({ apiKey: env.RESEND_API_KEY, - from: "wrdo ", + from: "wrdo ", }), ], } satisfies NextAuthConfig; diff --git a/components/forms/record-form.tsx b/components/forms/record-form.tsx index e56894e..a65aab4 100644 --- a/components/forms/record-form.tsx +++ b/components/forms/record-form.tsx @@ -68,7 +68,10 @@ export function RecordForm({ ttl: initData?.ttl || 1, proxied: initData?.proxied || false, comment: initData?.comment || "", - name: initData?.name || "", + name: + (initData?.name.endsWith(".wr.do") + ? initData?.name.slice(0, -6) + : initData?.name) || "", content: initData?.content || "", }, }); @@ -164,8 +167,7 @@ export function RecordForm({ setCurrentRecordType(value); }} name={"type"} - // disabled - defaultValue="CNAME" + defaultValue={initData?.type || "CNAME"} > @@ -187,12 +189,17 @@ export function RecordForm({ - +
+ + + .wr.do + +
{errors?.name ? ( @@ -201,7 +208,7 @@ export function RecordForm({

) : (

- Required. Use @ for root + Required. Use @ for root.

)}
@@ -251,7 +258,7 @@ export function RecordForm({ setValue("ttl", Number(value)); }} name="ttl" - defaultValue="1" + defaultValue={`${initData?.ttl}` || "1"} > diff --git a/components/layout/dashboard-sidebar.tsx b/components/layout/dashboard-sidebar.tsx index 43d9068..65776c2 100644 --- a/components/layout/dashboard-sidebar.tsx +++ b/components/layout/dashboard-sidebar.tsx @@ -79,7 +79,7 @@ export function DashboardSidebar({ links }: DashboardSidebarProps) { {siteConfig.name} @@ -178,39 +178,38 @@ export function DashboardSidebar({ links }: DashboardSidebarProps) { ))} - {/*
- {isSidebarExpanded ? : null} -
*/} -

- © 2024{" "} - - oiov - - .
Built with{" "} - - Nextjs - {" "} - &{" "} - - Cloudflare - - . -

+ {isSidebarExpanded && ( +

+ © 2024{" "} + + oiov + + .
Built with{" "} + + Nextjs + {" "} + &{" "} + + Cloudflare + + . +

+ )}
@@ -249,7 +248,7 @@ export function MobileSheetSidebar({ links }: DashboardSidebarProps) { logo {siteConfig.name} diff --git a/components/layout/navbar.tsx b/components/layout/navbar.tsx index 8239275..a72bba0 100644 --- a/components/layout/navbar.tsx +++ b/components/layout/navbar.tsx @@ -50,7 +50,10 @@ export function NavBar({ scroll = false }: NavBarProps) {
-

+

{siteConfig.name}

diff --git a/components/layout/site-footer.tsx b/components/layout/site-footer.tsx index ed51daa..2fd7aec 100644 --- a/components/layout/site-footer.tsx +++ b/components/layout/site-footer.tsx @@ -12,18 +12,22 @@ export function SiteFooter({ className }: React.HTMLAttributes) { return (