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.

record link delete in Tinybird when delete domain

Steven Tey62180641b524
diff --git a/apps/web/app/api/cron/usage/utils.ts b/apps/web/app/api/cron/usage/utils.ts
index 9b5e2fd1a7..08f74941f6 100644
--- a/apps/web/app/api/cron/usage/utils.ts
+++ b/apps/web/app/api/cron/usage/utils.ts
@@ -124,6 +124,7 @@ export const updateUsage = async (skip?: number) => {
projectId: project.id,
endpoint: "top_links",
interval: "30d",
+ excludeRoot: "true",
}).then((data) =>
data
.slice(0, 5)
diff --git a/apps/web/lib/api/domains.ts b/apps/web/lib/api/domains.ts
index 00902cc461..b88d900f37 100644
--- a/apps/web/lib/api/domains.ts
+++ b/apps/web/lib/api/domains.ts
@@ -239,9 +239,33 @@ export async function deleteDomainAndLinks(
skipPrismaDelete = false,
} = {},
) {
+ const domainData = await prisma.domain.findUnique({
+ where: {
+ slug: domain,
+ },
+ select: {
+ id: true,
+ target: true,
+ projectId: true,
+ },
+ });
+ if (!domainData) {
+ return null;
+ }
return await Promise.allSettled([
// delete all links from redis
redis.del(domain),
+ // record delete in tinybird
+ recordLink({
+ link: {
+ domain,
+ key: "_root",
+ projectId: domainData.projectId,
+ id: domainData.id,
+ url: domainData.target || "",
+ },
+ deleted: true,
+ }),
// remove all images from cloudinary
cloudinary.v2.api.delete_resources_by_prefix(domain),
// remove the domain from Vercel
diff --git a/apps/web/lib/auth/index.ts b/apps/web/lib/auth/index.ts
index b44bae3440..b791f8e803 100644
--- a/apps/web/lib/auth/index.ts
+++ b/apps/web/lib/auth/index.ts
@@ -242,16 +242,22 @@ export const withAuth =
id: linkId,
},
})
- : domain && key && key !== "_root"
- ? prisma.link.findUnique({
- where: {
- domain_key: {
- domain,
- key,
- },
- },
- })
- : undefined,
+ : domain &&
+ key &&
+ (key === "_root"
+ ? prisma.domain.findUnique({
+ where: {
+ slug: domain,
+ },
+ })
+ : prisma.link.findUnique({
+ where: {
+ domain_key: {
+ domain,
+ key,
+ },
+ },
+ })),
])) as [ProjectProps, LinkProps | undefined];
if (!project || !project.users) {