The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
update sanitizeSocialHandle
Steven Teyd462e54feea4
diff --git a/apps/web/lib/social-utils.ts b/apps/web/lib/social-utils.tsindex 275c06dab9..f73b443c86 100644--- a/apps/web/lib/social-utils.ts+++ b/apps/web/lib/social-utils.ts@@ -74,8 +74,7 @@ export const sanitizeSocialHandle = (handle = handle.replace(/\/.*$/, "").replace(/\?.*$/, "")- .replace(allowedChars, "")- .toLowerCase();+ .replace(allowedChars, "");if (maxLength) {handle = handle.substring(0, maxLength);diff --git a/apps/web/scripts/sanitize-social-handles.ts b/apps/web/scripts/partners/sanitize-social-handles.tssimilarity index 65%rename from apps/web/scripts/sanitize-social-handles.tsrename to apps/web/scripts/partners/sanitize-social-handles.tsindex af80d39250..a2894795cd 100644--- a/apps/web/scripts/sanitize-social-handles.ts+++ b/apps/web/scripts/partners/sanitize-social-handles.ts@@ -1,5 +1,6 @@import { sanitizeSocialHandle, type SocialPlatform } from "@/lib/social-utils";import { prisma } from "@dub/prisma";+import { deepEqual } from "@dub/utils";import { Partner } from "@prisma/client";import "dotenv-flow/config";@@ -7,11 +8,16 @@ async function main() {const partners = await prisma.partner.findMany({where: {OR: [- { youtube: { not: null } },- { twitter: { not: null } },- { linkedin: { not: null } },- { instagram: { not: null } },- { tiktok: { not: null } },+ { youtube: { contains: "@" } },+ { youtube: { contains: "http" } },+ { twitter: { contains: "@" } },+ { twitter: { contains: "http" } },+ { linkedin: { contains: "@" } },+ { linkedin: { contains: "http" } },+ { instagram: { contains: "@" } },+ { instagram: { contains: "http" } },+ { tiktok: { contains: "@" } },+ { tiktok: { contains: "http" } },],},select: {@@ -22,8 +28,7 @@ async function main() {instagram: true,tiktok: true,},- skip: 0,- take: 10,+ take: 50,});if (partners.length === 0) {@@ -44,19 +49,16 @@ async function main() {...socialHandles,};- let needsUpdate = false;-for (const [platform, value] of Object.entries(socialHandles)) {- if (value && (value.startsWith("http") || value.startsWith("@"))) {- updatedSocialHandles[platform] = sanitizeSocialHandle(- value,- platform as SocialPlatform,- );-- needsUpdate = true;- }+ updatedSocialHandles[platform] = sanitizeSocialHandle(+ value,+ platform as SocialPlatform,+ );}+ const needsUpdate =+ deepEqual(socialHandles, updatedSocialHandles) === false;+if (needsUpdate) {updatedPartners.push({id,