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.

fix admin

Steven Tey88a89ce901a2
diff --git a/apps/web/lib/api/links/utils.ts b/apps/web/lib/api/links/utils.ts
index 26d5135cd4..6c6efdeb00 100644
--- a/apps/web/lib/api/links/utils.ts
+++ b/apps/web/lib/api/links/utils.ts
@@ -45,7 +45,6 @@ export async function keyChecks({
key: string;
workspace?: Pick<WorkspaceProps, "plan">;
}): Promise<{ error: string | null; code?: DubApiError["code"] }> {
- console.log({ domain, key });
if ((key.length === 0 || key === "_root") && workspace?.plan === "free") {
return {
error:
diff --git a/apps/web/lib/api/workspaces.ts b/apps/web/lib/api/workspaces.ts
index ffec448231..c69f38527d 100644
--- a/apps/web/lib/api/workspaces.ts
+++ b/apps/web/lib/api/workspaces.ts
@@ -11,7 +11,7 @@ import {
import { waitUntil } from "@vercel/functions";
import { recordLink } from "../tinybird";
import { WorkspaceProps } from "../types";
-import { redis } from "../upstash";
+import { formatRedisLink, redis } from "../upstash";
export async function deleteWorkspace(
workspace: Pick<WorkspaceProps, "id" | "slug" | "stripeId" | "logo">,
@@ -131,7 +131,7 @@ export async function deleteWorkspace(
export async function deleteWorkspaceAdmin(
workspace: Pick<WorkspaceProps, "id" | "slug" | "stripeId" | "logo">,
) {
- const [customDomains, _] = await Promise.all([
+ const [customDomains, defaultDomainLinks] = await Promise.all([
prisma.domain.findMany({
where: {
projectId: workspace.id,
@@ -140,20 +140,43 @@ export async function deleteWorkspaceAdmin(
slug: true,
},
}),
- prisma.link.updateMany({
+ prisma.link.findMany({
where: {
projectId: workspace.id,
domain: {
in: DUB_DOMAINS_ARRAY,
},
},
- data: {
- userId: LEGAL_USER_ID,
- projectId: LEGAL_WORKSPACE_ID,
- },
}),
]);
+ const updateLinkRedisResponse = await Promise.allSettled(
+ defaultDomainLinks.map(async (link) => {
+ return redis.hset(link.domain.toLowerCase(), {
+ [link.key.toLowerCase()]: {
+ ...(await formatRedisLink(link)),
+ projectId: LEGAL_WORKSPACE_ID,
+ },
+ });
+ }),
+ );
+
+ // update all default domain links to the legal workspace
+ const updateLinkPrismaResponse = await prisma.link.updateMany({
+ where: {
+ projectId: workspace.id,
+ domain: {
+ in: DUB_DOMAINS_ARRAY,
+ },
+ },
+ data: {
+ userId: LEGAL_USER_ID,
+ projectId: LEGAL_WORKSPACE_ID,
+ },
+ });
+
+ console.log({ updateLinkRedisResponse, updateLinkPrismaResponse });
+
// delete all domains, links, and uploaded images associated with the workspace
const deleteDomainsLinksResponse = await Promise.allSettled([
...customDomains.map(({ slug }) => deleteDomainAndLinks(slug)),
@@ -175,6 +198,8 @@ export async function deleteWorkspaceAdmin(
]);
return {
+ updateLinkRedisResponse,
+ updateLinkPrismaResponse,
deleteDomainsLinksResponse,
deleteWorkspaceResponse,
};
diff --git a/apps/web/lib/edge-config/is-blacklisted-domain.ts b/apps/web/lib/edge-config/is-blacklisted-domain.ts
index b5b53dcfea..835c01925c 100644
--- a/apps/web/lib/edge-config/is-blacklisted-domain.ts
+++ b/apps/web/lib/edge-config/is-blacklisted-domain.ts
@@ -28,7 +28,7 @@ export const isBlacklistedDomain = async ({
const blacklistedTermsRegex = new RegExp(
blacklistedTerms
- .map((term: string) => term.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"))
+ .map((term: string) => term.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")) // replace special characters with escape sequences
.join("|"),
);
diff --git a/apps/web/ui/links/links-container.tsx b/apps/web/ui/links/links-container.tsx
index 679a047ece..a86d47ca04 100644
--- a/apps/web/ui/links/links-container.tsx
+++ b/apps/web/ui/links/links-container.tsx
@@ -81,7 +81,7 @@ function LinksList({
"showArchived",
].some((param) => searchParams.has(param));
- return loading || links?.length ? (
+ return !links || links.length ? (
<LinksListContext.Provider value={{ openMenuLinkId, setOpenMenuLinkId }}>
{/* Cards */}
<CardList variant={compact ? "compact" : "loose"} loading={loading}>
@@ -89,7 +89,7 @@ function LinksList({
? // Link cards
links.map((link) => <LinkCard link={link} />)
: // Loading placeholder cards
- Array.from({ length: 6 }).map((_, idx) => (
+ Array.from({ length: 12 }).map((_, idx) => (
<CardList.Card
key={idx}
outerClassName="pointer-events-none"