forked from dubinc/dub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
offload link checks to qstash, fix /exists 404
- Loading branch information
1 parent
c66087d
commit 7776e6b
Showing
6 changed files
with
92 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { receiver } from "@/lib/cron"; | ||
import prisma from "@/lib/prisma"; | ||
import { GOOGLE_FAVICON_URL, getApexDomain, log } from "@dub/utils"; | ||
|
||
export async function POST(req: Request) { | ||
const body = await req.json(); | ||
if (process.env.VERCEL === "1") { | ||
const isValid = await receiver.verify({ | ||
signature: req.headers.get("Upstash-Signature") || "", | ||
body: JSON.stringify(body), | ||
}); | ||
if (!isValid) { | ||
return new Response("Unauthorized", { status: 401 }); | ||
} | ||
} | ||
|
||
const { linkId } = body; | ||
|
||
const link = await prisma.link.findUnique({ | ||
where: { | ||
id: linkId, | ||
}, | ||
}); | ||
|
||
if (!link) { | ||
return new Response("Link not found", { status: 200 }); | ||
} | ||
|
||
const invalidFavicon = await fetch( | ||
`${GOOGLE_FAVICON_URL}${getApexDomain(link.url)}`, | ||
).then((res) => !res.ok); | ||
|
||
if (invalidFavicon) { | ||
await log({ | ||
message: `Suspicious link detected: ${link.domain}/${link.key} → ${link.url}`, | ||
type: "links", | ||
mention: true, | ||
}); | ||
} | ||
|
||
return new Response("OK", { status: 200 }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters