Skip to content

Commit

Permalink
Merge branch 'main' into utm-templates
Browse files Browse the repository at this point in the history
  • Loading branch information
steven-tey authored Oct 16, 2024
2 parents 6ab663e + 58efa71 commit 39f31ba
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 32 deletions.
16 changes: 8 additions & 8 deletions apps/web/app/api/metatags/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import { getMetaTags } from "./utils";

export const runtime = "edge";

const CORS_HEADERS = {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, OPTIONS",
};

export async function GET(req: NextRequest) {
try {
const { url } = getUrlQuerySchema.parse({
Expand All @@ -21,22 +26,17 @@ export async function GET(req: NextRequest) {
poweredBy: "Dub.co - Link management for modern marketing teams",
},
{
headers: {
"Access-Control-Allow-Origin": "*",
},
headers: CORS_HEADERS,
},
);
} catch (error) {
return handleAndReturnErrorResponse(error);
return handleAndReturnErrorResponse(error, CORS_HEADERS);
}
}

export function OPTIONS() {
return new Response(null, {
status: 204,
headers: {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, OPTIONS",
},
headers: CORS_HEADERS,
});
}
15 changes: 14 additions & 1 deletion apps/web/app/api/qr/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ import { NextRequest } from "next/server";

export const runtime = "edge";

const CORS_HEADERS = {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, OPTIONS",
};

export async function GET(req: NextRequest) {
try {
const params = getSearchParams(req.url);
Expand Down Expand Up @@ -62,9 +67,17 @@ export async function GET(req: NextRequest) {
{
width: size,
height: size,
headers: CORS_HEADERS,
},
);
} catch (error) {
return handleAndReturnErrorResponse(error);
return handleAndReturnErrorResponse(error, CORS_HEADERS);
}
}

export function OPTIONS() {
return new Response(null, {
status: 204,
headers: CORS_HEADERS,
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { UpgradeRequiredToast } from "@/ui/shared/upgrade-required-toast";
import { Logo, Switch } from "@dub/ui";
import {
Amazon,
CalendarDays,
ChatGPT,
Figma,
GitHubEnhanced,
Expand All @@ -28,6 +29,8 @@ function DubDomainsIcon(domain: string) {
return GitHubEnhanced;
case "spti.fi":
return Spotify;
case "cal.link":
return CalendarDays;
case "amzn.id":
return Amazon;
case "ggl.link":
Expand Down
26 changes: 6 additions & 20 deletions apps/web/lib/api/links/process-link.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {
getFeatureFlags,
isBlacklistedDomain,
updateConfig,
} from "@/lib/edge-config";
import { isBlacklistedDomain, updateConfig } from "@/lib/edge-config";
import { getPangeaDomainIntel } from "@/lib/pangea";
import { checkIfUserExists, getRandomKey } from "@/lib/planetscale";
import { prisma } from "@/lib/prisma";
Expand Down Expand Up @@ -197,7 +193,11 @@ export async function processLink<T extends Record<string, any>>({
// coerce type with ! cause we already checked if it exists
const { allowedHostnames } = DUB_DOMAINS.find((d) => d.slug === domain)!;
const urlDomain = getApexDomain(url) || "";
if (allowedHostnames && !allowedHostnames.includes(urlDomain)) {
if (
key !== "_root" &&
allowedHostnames &&
!allowedHostnames.includes(urlDomain)
) {
return {
link: payload,
error: `Invalid destination URL. You can only create ${domain} short links for URLs with the domain${allowedHostnames.length > 1 ? "s" : ""} ${allowedHostnames
Expand All @@ -207,20 +207,6 @@ export async function processLink<T extends Record<string, any>>({
};
}

if (domain === "cal.link") {
const flags = await getFeatureFlags({
workspaceId: workspace?.id,
});
if (!flags?.callink) {
return {
link: payload,
error:
"You can only use the cal.link domain if you have beta access to it. Contact [email protected] to get access.",
code: "forbidden",
};
}
}

if (key?.includes("/")) {
// check if the user has access to the parent link
const parentKey = key.split("/")[0];
Expand Down
11 changes: 8 additions & 3 deletions apps/web/ui/domains/domain-card-title-column.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,16 @@ export function DomainCardTitleColumn({
<div
className={cn(
"rounded-full",
!defaultDomain &&
"border border-white bg-gradient-to-t from-gray-100 p-1 md:p-3",
(!defaultDomain || domain === "cal.link") &&
"border border-white bg-gradient-to-t from-gray-100 p-1 md:p-2",
)}
>
<Icon className={cn("size-5", defaultDomain && "size-8")} />
<Icon
className={cn(
"size-5",
defaultDomain && domain !== "cal.link" && "size-8",
)}
/>
</div>
</div>
<div className="overflow-hidden">
Expand Down
73 changes: 73 additions & 0 deletions packages/ui/src/icons/nucleo/calendar-days.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { SVGProps } from "react";

export function CalendarDays(props: SVGProps<SVGSVGElement>) {
return (
<svg viewBox="0 0 18 18" xmlns="http://www.w3.org/2000/svg" {...props}>
<g fill="currentColor">
<path
d="M2.25 4.75C2.25 3.64543 3.14543 2.75 4.25 2.75H13.75C14.8546 2.75 15.75 3.64543 15.75 4.75V6.25H2.25V4.75Z"
fill="currentColor"
fillOpacity="0.3"
stroke="none"
/>
<path
d="M5.75 2.75V0.75"
fill="none"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="1.5"
/>
<path
d="M12.25 2.75V0.75"
fill="none"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="1.5"
/>
<path
d="M13.75 2.75H4.25C3.14543 2.75 2.25 3.64543 2.25 4.75V13.25C2.25 14.3546 3.14543 15.25 4.25 15.25H13.75C14.8546 15.25 15.75 14.3546 15.75 13.25V4.75C15.75 3.64543 14.8546 2.75 13.75 2.75Z"
fill="none"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="1.5"
/>
<path
d="M2.25 6.25H15.75"
fill="none"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="1.5"
/>
<path
d="M9 8.25C8.449 8.25 8 8.699 8 9.25C8 9.801 8.449 10.25 9 10.25C9.551 10.25 10 9.801 10 9.25C10 8.699 9.551 8.25 9 8.25Z"
fill="currentColor"
stroke="none"
/>
<path
d="M12.5 10.25C13.051 10.25 13.5 9.801 13.5 9.25C13.5 8.699 13.051 8.25 12.5 8.25C11.949 8.25 11.5 8.699 11.5 9.25C11.5 9.801 11.949 10.25 12.5 10.25Z"
fill="currentColor"
stroke="none"
/>
<path
d="M9 11.25C8.449 11.25 8 11.699 8 12.25C8 12.801 8.449 13.25 9 13.25C9.551 13.25 10 12.801 10 12.25C10 11.699 9.551 11.25 9 11.25Z"
fill="currentColor"
stroke="none"
/>
<path
d="M5.5 11.25C4.949 11.25 4.5 11.699 4.5 12.25C4.5 12.801 4.949 13.25 5.5 13.25C6.051 13.25 6.5 12.801 6.5 12.25C6.5 11.699 6.051 11.25 5.5 11.25Z"
fill="currentColor"
stroke="none"
/>
<path
d="M12.5 11.25C11.949 11.25 11.5 11.699 11.5 12.25C11.5 12.801 11.949 13.25 12.5 13.25C13.051 13.25 13.5 12.801 13.5 12.25C13.5 11.699 13.051 11.25 12.5 11.25Z"
fill="currentColor"
stroke="none"
/>
</g>
</svg>
);
}
1 change: 1 addition & 0 deletions packages/ui/src/icons/nucleo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export * from "./book2";
export * from "./books2";
export * from "./box-archive";
export * from "./bullet-list";
export * from "./calendar-days";
export * from "./cards";
export * from "./caret-up-fill";
export * from "./chart-activity2";
Expand Down

0 comments on commit 39f31ba

Please sign in to comment.