From d654594ed819a215534ca4a2c915ef0f06870d45 Mon Sep 17 00:00:00 2001 From: Kalle <38327916+Sendouc@users.noreply.github.com> Date: Sat, 8 Oct 2022 10:36:28 +0300 Subject: [PATCH] Remove bad custom urls script --- app/routes/u.$identifier/edit.tsx | 8 +++----- scripts/remove-bad-custom-urls.ts | 9 +++++++++ 2 files changed, 12 insertions(+), 5 deletions(-) create mode 100644 scripts/remove-bad-custom-urls.ts diff --git a/app/routes/u.$identifier/edit.tsx b/app/routes/u.$identifier/edit.tsx index 0f988f210..aa8285201 100644 --- a/app/routes/u.$identifier/edit.tsx +++ b/app/routes/u.$identifier/edit.tsx @@ -66,11 +66,9 @@ const userEditActionSchema = z .refine((val) => val === null || isCustomUrl(val), { message: "forms.errors.invalidCustomUrl.numbers", }) - .refine( - // validate val only contains numbers and letters - (val) => val === null || /^[a-zA-Z0-9-_]+$/.test(val), - { message: "forms.errors.invalidCustomUrl.strangeCharacter" } - ) + .refine((val) => val === null || /^[a-zA-Z0-9-_]+$/.test(val), { + message: "forms.errors.invalidCustomUrl.strangeCharacter", + }) .transform((val) => val?.toLowerCase()) .nullable() ), diff --git a/scripts/remove-bad-custom-urls.ts b/scripts/remove-bad-custom-urls.ts new file mode 100644 index 000000000..dc5cba78f --- /dev/null +++ b/scripts/remove-bad-custom-urls.ts @@ -0,0 +1,9 @@ +/* eslint-disable no-console */ +import "dotenv/config"; +import { sql } from "~/db/sql"; + +sql.prepare( + `update "User" set "customUrl" = NULL where "customUrl" like '%/%'` +); + +console.log("Done");