Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Added dynamic OG image, modularize getStats and stats endpoint

Steven Teybaebc411829e
diff --git a/components/stats/bar-chart.tsx b/components/stats/bar-chart.tsx
index 72459a5d93..6afa147cd1 100644
--- a/components/stats/bar-chart.tsx
+++ b/components/stats/bar-chart.tsx
@@ -14,6 +14,7 @@ import useSWR from "swr";
import { fetcher } from "@/lib/utils";
import useProject from "@/lib/swr/use-project";
import { LoadingCircle } from "@/components/shared/icons";
+import useEndpoint from "@/lib/hooks/use-endpoint";
const LEFT_AXIS_WIDTH = 30;
const CHART_MAX_HEIGHT = 400;
@@ -37,25 +38,15 @@ const rangeFormatter = (maxN: number): number => {
const BarChart = ({ screenWidth }: { screenWidth?: number }) => {
const router = useRouter();
- const {
- slug,
- key,
- interval = "24h",
- } = router.query as {
- slug?: string;
- key: string;
+ const { interval = "24h" } = router.query as {
interval?: string;
};
- const { project: { domain } = {} } = useProject();
+ const { endpoint } = useEndpoint();
const { data } = useSWR<{ start: Date; clicks: number }[]>(
router.isReady &&
- `${
- slug && domain
- ? `/api/projects/${slug}/domains/${domain}/links/${key}/stats/timeseries`
- : `/api/edge/links/${key}/stats/timeseries`
- }${interval ? `?interval=${interval}` : ""}`,
+ `${endpoint}/timeseries${interval ? `?interval=${interval}` : ""}`,
fetcher,
);
diff --git a/components/stats/clicks.tsx b/components/stats/clicks.tsx
index efa67573a2..8ca3c0b6ce 100644
--- a/components/stats/clicks.tsx
+++ b/components/stats/clicks.tsx
@@ -4,28 +4,18 @@ import { nFormatter } from "@/lib/utils";
import { useRouter } from "next/router";
import useSWR from "swr";
import { fetcher } from "@/lib/utils";
-import useProject from "@/lib/swr/use-project";
+import useEndpoint from "@/lib/hooks/use-endpoint";
export default function Clicks() {
const router = useRouter();
- const {
- slug,
- key,
- interval = "24h",
- } = router.query as {
- slug?: string;
- key: string;
+ const { interval = "24h" } = router.query as {
interval?: string;
};
+ const { endpoint } = useEndpoint();
- const { project: { domain } = {} } = useProject();
const { data: totalClicks } = useSWR<number>(
router.isReady &&
- `${
- slug && domain
- ? `/api/projects/${slug}/domains/${domain}/links/${key}/clicks`
- : `/api/edge/links/${key}/clicks`
- }${interval ? `?interval=${interval}` : ""}`,
+ `${endpoint}/clicks${interval ? `?interval=${interval}` : ""}`,
fetcher,
);
diff --git a/components/stats/devices.tsx b/components/stats/devices.tsx
index be1d3f9d16..63d4be2464 100644
--- a/components/stats/devices.tsx
+++ b/components/stats/devices.tsx
@@ -8,41 +8,29 @@ import { nFormatter } from "@/lib/utils";
import DeviceIcon from "./device-icon";
import useSWR from "swr";
import { fetcher } from "@/lib/utils";
-import useProject from "@/lib/swr/use-project";
+import useEndpoint from "@/lib/hooks/use-endpoint";
export default function Devices() {
const [tab, setTab] = useState<DeviceTabs>("device");
const router = useRouter();
- const { slug, key, interval } = router.query as {
- slug?: string;
- key: string;
+ const { interval } = router.query as {
interval?: string;
};
- const { project: { domain } = {} } = useProject();
+ const { endpoint } = useEndpoint();
const { data } = useSWR<
({
[key in DeviceTabs]: string;
} & { clicks: number })[]
>(
- router.isReady &&
- `${
- slug && domain
- ? `/api/projects/${slug}/domains/${domain}/links/${key}/stats/${tab}`
- : `/api/edge/links/${key}/stats/${tab}`
- }?interval=${interval || "24h"}`,
+ router.isReady && `${endpoint}/${tab}?interval=${interval || "24h"}`,
fetcher,
);
const { data: totalClicks } = useSWR<number>(
- router.isReady &&
- `${
- slug && domain
- ? `/api/projects/${slug}/domains/${domain}/links/${key}/clicks`
- : `/api/edge/links/${key}/clicks`
- }?interval=${interval || "24h"}`,
+ router.isReady && `${endpoint}/clicks?interval=${interval || "24h"}`,
fetcher,
);
diff --git a/components/stats/locations.tsx b/components/stats/locations.tsx
index 633941ac8e..7fcefcf12a 100644
--- a/components/stats/locations.tsx
+++ b/components/stats/locations.tsx
@@ -8,37 +8,25 @@ import { LoadingCircle } from "../shared/icons";
import { useRouter } from "next/router";
import useSWR from "swr";
import { fetcher } from "@/lib/utils";
-import useProject from "@/lib/swr/use-project";
+import useEndpoint from "@/lib/hooks/use-endpoint";
export default function Locations() {
const [tab, setTab] = useState<LocationTabs>("country");
const router = useRouter();
- const { slug, key, interval } = router.query as {
- slug?: string;
- key: string;
+ const { interval } = router.query as {
interval?: string;
};
- const { project: { domain } = {} } = useProject();
+ const { endpoint } = useEndpoint();
const { data } = useSWR<{ country: string; city: string; clicks: number }[]>(
- router.isReady &&
- `${
- slug && domain
- ? `/api/projects/${slug}/domains/${domain}/links/${key}/stats/${tab}`
- : `/api/edge/links/${key}/stats/${tab}`
- }?interval=${interval || "24h"}`,
+ router.isReady && `${endpoint}/${tab}?interval=${interval || "24h"}`,
fetcher,
);
const { data: totalClicks } = useSWR<number>(
- router.isReady &&
- `${
- slug && domain
- ? `/api/projects/${slug}/domains/${domain}/links/${key}/clicks`
- : `/api/edge/links/${key}/clicks`
- }?interval=${interval || "24h"}`,
+ router.isReady && `${endpoint}/clicks?interval=${interval || "24h"}`,
fetcher,
);
diff --git a/components/stats/referer.tsx b/components/stats/referer.tsx
index 0093dfea66..7b2c4678b2 100644
--- a/components/stats/referer.tsx
+++ b/components/stats/referer.tsx
@@ -5,36 +5,24 @@ import { Link, LoadingCircle } from "@/components/shared/icons";
import { nFormatter } from "@/lib/utils";
import useSWR from "swr";
import { fetcher } from "@/lib/utils";
-import useProject from "@/lib/swr/use-project";
+import useEndpoint from "@/lib/hooks/use-endpoint";
export default function Referer() {
const router = useRouter();
- const { slug, key, interval } = router.query as {
- slug?: string;
- key: string;
+ const { interval } = router.query as {
interval?: string;
};
- const { project: { domain } = {} } = useProject();
+ const { endpoint } = useEndpoint();
const { data } = useSWR<{ referer: string; clicks: number }[]>(
- router.isReady &&
- `${
- slug && domain
- ? `/api/projects/${slug}/domains/${domain}/links/${key}/stats/referer`
- : `/api/edge/links/${key}/stats/referer`
- }?interval=${interval || "24h"}`,
+ router.isReady && `${endpoint}/referer?interval=${interval || "24h"}`,
fetcher,
);
const { data: totalClicks } = useSWR<number>(
- router.isReady &&
- `${
- slug && domain
- ? `/api/projects/${slug}/domains/${domain}/links/${key}/clicks`
- : `/api/edge/links/${key}/clicks`
- }?interval=${interval || "24h"}`,
+ router.isReady && `${endpoint}/clicks?interval=${interval || "24h"}`,
fetcher,
);
diff --git a/components/stats/toggle.tsx b/components/stats/toggle.tsx
index f94261aadc..9104046362 100644
--- a/components/stats/toggle.tsx
+++ b/components/stats/toggle.tsx
@@ -17,9 +17,9 @@ import useSWR, { mutate } from "swr";
import { fetcher } from "@/lib/utils";
import { useSession } from "next-auth/react";
import { toast } from "react-hot-toast";
-import useProject from "@/lib/swr/use-project";
import Switch from "../shared/switch";
import Link from "next/link";
+import useEndpoint from "@/lib/hooks/use-endpoint";
export default function Toggle({
atModalTop,
@@ -29,31 +29,12 @@ export default function Toggle({
domain?: string;
}) {
const router = useRouter();
- const {
- slug,
- key,
- interval = "24h",
- } = router.query as {
- slug?: string;
+ const { key, interval = "24h" } = router.query as {
key: string;
interval?: string;
};
- const { project: { domain: projectDomain } = {} } = useProject();
-
- const { pageType, domain } = useMemo(() => {
- // Project link page, e.g. app.dub.sh/dub/github
- if (slug && key) {
- return { pageType: slug, domain: projectDomain };
-
- // Generic Dub.sh link page, e.g. app.dub.sh/links/steven
- } else if (key && router.asPath.startsWith("/links")) {
- return { pageType: "links", domain: "dub.sh" };
- }
-
- // Public stats page, e.g. dub.sh/stats/github
- return { pageType: "stats", domain: staticDomain };
- }, [slug, key, router.asPath]);
+ const { pageType, domain } = useEndpoint(staticDomain);
const atTop = useScroll(80) || atModalTop;
const [openDatePopover, setOpenDatePopover] = useState(false);
@@ -145,28 +126,33 @@ const SharePopover = ({ domain }: { domain: string }) => {
const [openSharePopover, setopenSharePopoverPopover] = useState(false);
+ const endpoint = useMemo(() => {
+ if (slug) {
+ return `/api/projects/${slug}/domains/${domain}/links/${key}/stats`;
+ } else {
+ return `/api/links/${key}/stats`;
+ }
+ }, [slug]);
+
const { data: { publicStats } = {} } = useSWR<{ publicStats: boolean }>(
- slug && `/api/projects/${slug}/domains/${domain}/links/${key}/stats`,
+ endpoint,
fetcher,
);
const handleChange = async () => {
toast.promise(
new Promise<void>(async (resolve) => {
- const res = await fetch(
- `/api/projects/${slug}/domains/${domain}/links/${key}/stats`,
- {
- method: "PUT",
- headers: {
- "Content-Type": "application/json",
- },
- body: JSON.stringify({
- publicStats: !publicStats,
- }),
+ const res = await fetch(endpoint, {
+ method: "PUT",
+ headers: {
+ "Content-Type": "application/json",
},
- );
+ body: JSON.stringify({
+ publicStats: !publicStats,
+ }),
+ });
if (res.status === 200) {
- mutate(`/api/projects/${slug}/domains/${domain}/links/${key}/stats`);
+ mutate(endpoint);
}
resolve();
}),
diff --git a/lib/auth.ts b/lib/auth.ts
index c31337d6b8..ec13b22c4f 100644
--- a/lib/auth.ts
+++ b/lib/auth.ts
@@ -4,6 +4,7 @@ import { FREE_PLAN_PROJECT_LIMIT } from "@/lib/constants";
import prisma from "@/lib/prisma";
import { ProjectProps, UserProps } from "@/lib/types";
import { authOptions } from "@/pages/api/auth/[...nextauth]";
+
export interface Session {
user: {
email?: string | null;
diff --git a/lib/hooks/use-endpoint.ts b/lib/hooks/use-endpoint.ts
new file mode 100644
index 0000000000..ad612f0c5d
--- /dev/null
+++ b/lib/hooks/use-endpoint.ts
@@ -0,0 +1,45 @@
+import { useRouter } from "next/router";
+import { useMemo } from "react";
+import useProject from "@/lib/swr/use-project";
+
+export default function useEndpoint(staticDomain?: string) {
+ const router = useRouter();
+ const { slug, key } = router.query as {
+ slug?: string;
+ key: string;
+ };
+
+ const { project: { domain: projectDomain } = {} } = useProject();
+
+ const { pageType, domain, endpoint } = useMemo(() => {
+ // Project link page, e.g. app.dub.sh/dub/github
+ if (slug && key) {
+ return {
+ pageType: slug,
+ domain: projectDomain,
+ endpoint: `/api/projects/${slug}/domains/${projectDomain}/links/${key}/stats`,
+ };
+
+ // Generic Dub.sh link page, e.g. app.dub.sh/links/steven
+ } else if (key && router.asPath.startsWith("/links")) {
+ return {
+ pageType: "links",
+ domain: "dub.sh",
+ endpoint: `/api/links/${key}/stats`,
+ };
+ }
+
+ // Public stats page, e.g. dub.sh/stats/github
+ return {
+ pageType: "stats",
+ domain: staticDomain,
+ endpoint: `/api/edge/links/${key}/stats`,
+ };
+ }, [slug, key, router.asPath]);
+
+ return {
+ pageType,
+ domain,
+ endpoint,
+ };
+}
diff --git a/lib/stats.ts b/lib/stats.ts
index 462c59cf7f..6715b3ff9e 100644
--- a/lib/stats.ts
+++ b/lib/stats.ts
@@ -1,3 +1,5 @@
+import { conn } from "./planetscale";
+
export type IntervalProps = "1h" | "24h" | "7d" | "30d" | "90d";
export const intervalData = {
@@ -120,6 +122,21 @@ export const getStats = async ({
return null;
}
+ // get all-time clicks count
+ if (endpoint === "clicks" && !interval) {
+ const response = await conn.execute(
+ "SELECT clicks FROM Link WHERE domain = ? AND `key` = ?",
+ [domain, key],
+ );
+ let clicks = 0;
+ try {
+ clicks = response.rows[0]["clicks"];
+ return new Response(JSON.stringify(clicks), { status: 200 });
+ } catch (e) {
+ console.log(e);
+ }
+ }
+
let url = new URL(
`https://api.us-east.tinybird.co/v0/pipes/${endpoint}.json`,
);
@@ -147,6 +164,14 @@ export const getStats = async ({
})
.then((res) => res.json())
.then(({ data }) => {
+ if (endpoint === "clicks") {
+ try {
+ const clicks = data[0]["count()"];
+ return clicks || "0";
+ } catch (e) {
+ console.log(e);
+ }
+ }
return data;
});
};
diff --git a/lib/utils.ts b/lib/utils.ts
index bac611364c..edcc454abf 100644
--- a/lib/utils.ts
+++ b/lib/utils.ts
@@ -194,11 +194,7 @@ export const isValidUrl = (url: string) => {
};
export const isHomeHostname = (domain: string) => {
- return (
- HOME_HOSTNAMES.has(domain) ||
- domain.endsWith(".vercel.app") ||
- domain.endsWith(".localhost:3000")
- );
+ return HOME_HOSTNAMES.has(domain) || domain.endsWith(".vercel.app");
};
export const getUrlFromString = (str: string) => {
diff --git a/pages/api/edge/links/[key]/clicks.ts b/pages/api/edge/links/[key]/clicks.ts
deleted file mode 100644
index c8c57de6e4..0000000000
--- a/pages/api/edge/links/[key]/clicks.ts
+++ /dev/null
@@ -1,51 +0,0 @@
-import type { NextRequest } from "next/server";
-import { getStats } from "@/lib/stats";
-import { isHomeHostname } from "@/lib/utils";
-import { conn } from "@/lib/planetscale";
-
-export const config = {
- runtime: "edge",
-};
-
-export default async function handler(req: NextRequest) {
- if (req.method === "GET") {
- const key = req.nextUrl.searchParams.get("key");
- const interval = req.nextUrl.searchParams.get("interval");
-
- let domain = req.headers.get("host");
- if (isHomeHostname(domain)) domain = "dub.sh";
-
- if (!interval) {
- const response = await conn.execute(
- "SELECT clicks FROM Link WHERE domain = ? AND `key` = ?",
- [domain, key],
- );
- let clicks = 0;
- try {
- clicks = response.rows[0]["clicks"];
- return new Response(JSON.stringify(clicks), { status: 200 });
- } catch (e) {
- console.log(e);
- }
- }
-
- // if Planetscale fails or interval is provided, get the total clicks from Tinybird
- const response = await getStats({
- domain,
- key,
- endpoint: "clicks",
- interval,
- });
-
- let clicks = 0;
- try {
- clicks = response[0]["count()"];
- } catch (e) {
- console.log(e);
- }
-
- return new Response(JSON.stringify(clicks), { status: 200 });
- } else {
- return new Response(`Method ${req.method} Not Allowed`, { status: 405 });
- }
-}
diff --git a/pages/api/edge/links/[key]/stats/[endpoint].ts b/pages/api/edge/links/[key]/stats/[endpoint].ts
index 0db06a1af9..73b420592c 100644
--- a/pages/api/edge/links/[key]/stats/[endpoint].ts
+++ b/pages/api/edge/links/[key]/stats/[endpoint].ts
@@ -15,13 +15,11 @@ export default async function handler(req: NextRequest) {
let domain = req.headers.get("host");
if (isHomeHostname(domain)) domain = "dub.sh";
- if (domain !== "dub.sh") {
- const data = await getLinkViaEdge(key, domain);
- if (!data.publicStats) {
- return new Response(`Method ${req.method} Not Allowed`, {
- status: 405,
- });
- }
+ const data = await getLinkViaEdge(domain, key);
+ if (!data?.publicStats) {
+ return new Response(`Stats for this link are not public`, {
+ status: 403,
+ });
}
const response = await getStats({
diff --git a/pages/api/links/[key]/stats/[endpoint].ts b/pages/api/links/[key]/stats/[endpoint].ts
new file mode 100644
index 0000000000..09f0d7e8c4
--- /dev/null
+++ b/pages/api/links/[key]/stats/[endpoint].ts
@@ -0,0 +1,35 @@
+import { NextApiRequest, NextApiResponse } from "next";
+import { withUserAuth } from "@/lib/auth";
+import { getStats, IntervalProps } from "@/lib/stats";
+
+export default withUserAuth(
+ async (req: NextApiRequest, res: NextApiResponse) => {
+ // GET /api/links/[key]/stats/[endpoint] - get link stats from Tinybird
+ if (req.method === "GET") {
+ const { key, endpoint, interval } = req.query as {
+ key: string;
+ endpoint: string;
+ interval: IntervalProps;
+ };
+ const response = await getStats({
+ domain: "dub.sh",
+ key,
+ endpoint,
+ interval,
+ });
+
+ if (!response) {
+ return res
+ .status(405)
+ .json({ error: `Method ${req.method} Not Allowed` });
+ }
+
+ return res.status(200).json(response);
+ } else {
+ res.setHeader("Allow", ["GET"]);
+ return res
+ .status(405)
+ .json({ error: `Method ${req.method} Not Allowed` });
+ }
+ },
+);
diff --git a/pages/api/links/[key]/stats/index.ts b/pages/api/links/[key]/stats/index.ts
new file mode 100644
index 0000000000..b76c1e571c
--- /dev/null
+++ b/pages/api/links/[key]/stats/index.ts
@@ -0,0 +1,50 @@
+import { NextApiRequest, NextApiResponse } from "next";
+import { withUserAuth } from "@/lib/auth";
+import prisma from "@/lib/prisma";
+
+export default withUserAuth(
+ async (req: NextApiRequest, res: NextApiResponse, project) => {
+ const { key } = req.query as {
+ key: string;
+ };
+
+ // GET /api/links/[key]/stats - get a link's stats page privacy
+ if (req.method === "GET") {
+ const link = await prisma.link.findUnique({
+ where: {
+ domain_key: {
+ domain: "dub.sh",
+ key,
+ },
+ },
+ select: {
+ publicStats: true,
+ },
+ });
+
+ return res.status(200).json(link);
+
+ // PUT /api/links/[key]/stats - edit a link's stats page privacy
+ } else if (req.method === "PUT") {
+ const { publicStats } = req.body as { publicStats: boolean };
+ const response = await prisma.link.update({
+ where: {
+ domain_key: {
+ key,
+ domain: "dub.sh",
+ },
+ },
+ data: {
+ publicStats,
+ },
+ });
+
+ return res.status(200).json(response);
+ } else {
+ res.setHeader("Allow", ["PUT"]);
+ return res
+ .status(405)
+ .json({ error: `Method ${req.method} Not Allowed` });
+ }
+ },
+);
diff --git a/pages/api/og/stats.tsx b/pages/api/og/stats.tsx
index 92a4f0e1e7..82aa77df65 100644
--- a/pages/api/og/stats.tsx
+++ b/pages/api/og/stats.tsx
@@ -1,3 +1,5 @@
+import { getLinkViaEdge } from "@/lib/planetscale";
+import { getStats } from "@/lib/stats";
import { nFormatter, truncate } from "@/lib/utils";
import { ImageResponse } from "@vercel/og";
import { NextRequest } from "next/server";
@@ -6,21 +8,40 @@ export const config = {
runtime: "edge",
};
-const satoshi = fetch(
+const satoshiBLack = fetch(
new URL("../../../styles/Satoshi-Black.ttf", import.meta.url),
).then((res) => res.arrayBuffer());
-const inter = fetch(
- new URL("../../../styles/Inter-Bold.ttf", import.meta.url),
+const satoshiBold = fetch(
+ new URL("../../../styles/Satoshi-Bold.ttf", import.meta.url),
).then((res) => res.arrayBuffer());
export default async function handler(req: NextRequest) {
- const [satoshiData, interData] = await Promise.all([satoshi, inter]);
+ const [satoshiBlackData, satoshiBoldData] = await Promise.all([
+ satoshiBLack,
+ satoshiBold,
+ ]);
const { searchParams } = req.nextUrl;
const domain = searchParams.get("domain") || "dub.sh";
const key = searchParams.get("key") || "github";
- const clicks = searchParams.get("clicks") || "12702";
+
+ const data = await getLinkViaEdge(domain, key);
+ if (!data?.publicStats) {
+ return new Response(`Stats for this link are not public`, {
+ status: 403,
+ });
+ }
+
+ const timeseries = await getStats({
+ domain,
+ key,
+ endpoint: "timeseries",
+ interval: "30d",
+ });
+
+ const maxClicks = Math.max(...timeseries.map((t) => t.clicks));
+ const totalClicks = timeseries.reduce((acc, t) => acc + t.clicks, 0);
return new ImageResponse(
(
@@ -41,13 +62,12 @@ export default async function handler(req: NextRequest) {
<h1
style={{
fontSize: "80px",
- fontWeight: "bold",
- fontFamily: "Satoshi",
+ fontFamily: "Satoshi Black",
background:
"linear-gradient(95.78deg, #C7BF00 21.66%, #E43838 86.47%)",
backgroundClip: "text",
color: "transparent",
- marginTop: "100px",
+ marginTop: "50px",
lineHeight: "7rem",
}}
>
@@ -55,16 +75,77 @@ export default async function handler(req: NextRequest) {
</h1>
<p
style={{
- fontSize: "45px",
- fontWeight: "bold",
- fontFamily: "Inter",
+ fontSize: "40px",
+ fontFamily: "Satoshi Bold",
color: "black",
opacity: 0.8,
- marginTop: "12px",
+ marginTop: "-10px",
}}
>
- {nFormatter(parseInt(clicks))} TOTAL CLICKS
+ {nFormatter(totalClicks)} clicks in the last 30 days
</p>
+ <div
+ style={{
+ position: "absolute",
+ bottom: "80px",
+ display: "flex",
+ flexDirection: "row",
+ alignItems: "flex-end",
+ justifyContent: "center",
+ marginTop: "50px",
+ }}
+ >
+ {timeseries.map(({ start, clicks }) => (
+ <div
+ key={start}
+ style={{
+ display: "flex",
+ flexDirection: "column",
+ alignItems: "center",
+ justifyContent: "center",
+ width: "20px",
+ height: `${(clicks / maxClicks) * 300}px`, // normalize clicks count to scale of 300px
+ marginRight: "10px",
+ backgroundColor: "#2563eb",
+ }}
+ />
+ ))}
+ </div>
+ <div
+ style={{
+ position: "absolute",
+ bottom: "0px",
+ height: "80px",
+ width: "100%",
+ display: "flex",
+ flexDirection: "row",
+ alignItems: "center",
+ justifyContent: "center",
+ backgroundColor: "rgba(255, 255, 255, 0.4)",
+ backdropFilter: "blur(30px)",
+ }}
+ >
+ <img
+ src={new URL(
+ "../../../public/_static/logo.png",
+ import.meta.url,
+ ).toString()}
+ style={{
+ width: "40px",
+ height: "40px",
+ }}
+ />
+ <h2
+ style={{
+ fontSize: "25px",
+ fontFamily: "Satoshi Bold",
+ color: "#000",
+ marginLeft: "20px",
+ }}
+ >
+ Dub.sh - Link Management For Modern Marketing Teams
+ </h2>
+ </div>
</div>
),
{
@@ -72,12 +153,12 @@ export default async function handler(req: NextRequest) {
height: 630,
fonts: [
{
- name: "Satoshi",
- data: satoshiData,
+ name: "Satoshi Black",
+ data: satoshiBlackData,
},
{
- name: "Inter",
- data: interData,
+ name: "Satoshi Bold",
+ data: satoshiBoldData,
},
],
},
diff --git a/pages/api/projects/[slug]/domains/[domain]/links/[key]/clicks.ts b/pages/api/projects/[slug]/domains/[domain]/links/[key]/clicks.ts
deleted file mode 100644
index d6bf4e388c..0000000000
--- a/pages/api/projects/[slug]/domains/[domain]/links/[key]/clicks.ts
+++ /dev/null
@@ -1,53 +0,0 @@
-import { NextApiRequest, NextApiResponse } from "next";
-import { withProjectAuth } from "@/lib/auth";
-import prisma from "@/lib/prisma";
-import { getStats } from "@/lib/stats";
-
-export default withProjectAuth(
- async (req: NextApiRequest, res: NextApiResponse) => {
- // GET /api/projects/[slug]/domains/[domain]/links/[key]/clicks - get link clicks
- if (req.method === "GET") {
- const { domain, key, interval } = req.query as {
- domain: string;
- key: string;
- interval?: string;
- };
-
- if (!interval) {
- // if no interval is provided, get the total clicks from MySQL
- const response = await prisma.link.findUnique({
- where: {
- domain_key: {
- domain,
- key,
- },
- },
- select: {
- clicks: true,
- },
- });
- return res.status(200).json(response?.clicks || 0);
- }
-
- const response = await getStats({
- domain,
- key,
- endpoint: "clicks",
- interval,
- });
-
- let clicks = 0;
- try {
- clicks = response[0]["count()"];
- } catch (e) {
- console.log(e);
- }
- return res.status(200).json(clicks);
- } else {
- res.setHeader("Allow", ["GET"]);
- return res
- .status(405)
- .json({ error: `Method ${req.method} Not Allowed` });
- }
- },
-);
diff --git a/pages/sitemap.xml.tsx b/pages/sitemap.xml.tsx
index 15abeb3264..e3ca200fe9 100644
--- a/pages/sitemap.xml.tsx
+++ b/pages/sitemap.xml.tsx
@@ -46,6 +46,7 @@ export async function getServerSideProps({
const links = await prisma.link.findMany({
where: {
domain: "dub.sh",
+ publicStats: true,
},
select: {
key: true,
diff --git a/pages/stats/[key].tsx b/pages/stats/[key].tsx
index 64b940f45e..a3444f87af 100644
--- a/pages/stats/[key].tsx
+++ b/pages/stats/[key].tsx
@@ -10,25 +10,19 @@ export const config = {
export default function StatsPage({
url,
- clicks,
_key,
domain,
}: {
url: string;
- clicks: number;
_key: string;
domain?: string;
}) {
return (
<HomeLayout
meta={{
- title: `Stats for ${domain}/${_key} (${nFormatter(
- clicks,
- )} clicks) - Dub`,
- description: `Stats page for ${domain}/${_key}, which redirects to ${url} and has received ${nFormatter(
- clicks,
- )} total clicks.`,
- image: `https://dub.sh/api/og/stats?domain=${domain}&key=${_key}&clicks=${clicks}`,
+ title: `Stats for ${domain}/${_key} - Dub`,
+ description: `Stats page for ${domain}/${_key}, which redirects to ${url}.`,
+ image: `https://dub.sh/api/og/stats?domain=${domain}&key=${_key}`,
}}
>
<div className="bg-gray-50">
@@ -48,7 +42,7 @@ export const getServerSideProps: GetServerSideProps = async ({
const data = await getLinkViaEdge(domain, key);
- if (data && (domain === "dub.sh" || data.publicStats)) {
+ if (data && data.publicStats) {
return {
props: {
...data,
diff --git a/public/_static/background.png b/public/_static/background.png
index 6944266822..8a58dc2686 100644
Binary files a/public/_static/background.png and b/public/_static/background.png differ
diff --git a/styles/Inter-Bold.ttf b/styles/Inter-Bold.ttf
deleted file mode 100644
index 8e82c70d10..0000000000
Binary files a/styles/Inter-Bold.ttf and /dev/null differ
diff --git a/styles/Satoshi-Bold.ttf b/styles/Satoshi-Bold.ttf
new file mode 100644
index 0000000000..00bc985b2c
Binary files /dev/null and b/styles/Satoshi-Bold.ttf differ