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.

return early if valid JSON

Steven Tey9029dbd42ff5
diff --git a/apps/web/app/api/cron/import/bitly/sanitize-json.ts b/apps/web/app/api/cron/import/bitly/sanitize-json.ts
index 925b030ce0..45b19d4605 100644
--- a/apps/web/app/api/cron/import/bitly/sanitize-json.ts
+++ b/apps/web/app/api/cron/import/bitly/sanitize-json.ts
@@ -1,4 +1,12 @@
export function sanitizeBitlyJson(body: string): string {
+ try {
+ // if body is already valid JSON, return it
+ JSON.parse(body);
+ return body;
+ } catch (err) {
+ console.error("Error parsing JSON, starting sanitization...");
+ }
+
// First, remove "title" field which can sometimes contain invalid values that break the JSON parsing
body = body.replace(
/"long_url":"([^"]+)".+?"archived"/g,
diff --git a/apps/web/app/api/cron/migrate/route.ts b/apps/web/app/api/cron/migrate/route.ts
index 5525176157..a1d07d695a 100644
--- a/apps/web/app/api/cron/migrate/route.ts
+++ b/apps/web/app/api/cron/migrate/route.ts
@@ -64,7 +64,7 @@ export async function POST(req: Request) {
`Final deleted link: ${finalDeletedLink.key} (${new Date(finalDeletedLink.createdAt).toISOString()})`,
);
- if (finalDeletedLink.createdAt <= new Date("2024-09-20T03:40:10.000Z")) {
+ if (finalDeletedLink.createdAt <= new Date("2024-05-18T11:54:08.000Z")) {
console.log("Reached previously imported links point, pausing for now...");
return NextResponse.json({
status: `Reached previously imported links point, pausing for now...`,