From 3030b21f18591837d34ea103a6a74fa419dd4f56 Mon Sep 17 00:00:00 2001 From: Nicolas Meienberger Date: Thu, 29 Jan 2026 20:23:05 +0100 Subject: [PATCH] refactor: remove slug constraint in volume name Closes #413 --- .../components/create-notification-form.tsx | 3 +- .../volumes/components/create-volume-form.tsx | 3 +- .../notifications/notifications.service.ts | 24 ++------------ app/server/modules/volumes/volume.service.ts | 32 ++----------------- 4 files changed, 8 insertions(+), 54 deletions(-) diff --git a/app/client/modules/notifications/components/create-notification-form.tsx b/app/client/modules/notifications/components/create-notification-form.tsx index 6e669e4d..bea6e566 100644 --- a/app/client/modules/notifications/components/create-notification-form.tsx +++ b/app/client/modules/notifications/components/create-notification-form.tsx @@ -2,7 +2,7 @@ import { arktypeResolver } from "@hookform/resolvers/arktype"; import { type } from "arktype"; import { useEffect } from "react"; import { useForm } from "react-hook-form"; -import { cn, slugify } from "~/client/lib/utils"; +import { cn } from "~/client/lib/utils"; import { deepClean } from "~/utils/object"; import { Form, @@ -141,7 +141,6 @@ export const CreateNotificationForm = ({ onSubmit, mode = "create", initialValue field.onChange(slugify(e.target.value))} max={32} min={2} /> diff --git a/app/client/modules/volumes/components/create-volume-form.tsx b/app/client/modules/volumes/components/create-volume-form.tsx index 745f9eb3..eb630069 100644 --- a/app/client/modules/volumes/components/create-volume-form.tsx +++ b/app/client/modules/volumes/components/create-volume-form.tsx @@ -4,7 +4,7 @@ import { type } from "arktype"; import { CheckCircle, Loader2, Plug, Save, XCircle } from "lucide-react"; import { useEffect, useState } from "react"; import { useForm } from "react-hook-form"; -import { cn, slugify } from "~/client/lib/utils"; +import { cn } from "~/client/lib/utils"; import { deepClean } from "~/utils/object"; import { Button } from "../../../components/ui/button"; import { @@ -122,7 +122,6 @@ export const CreateVolumeForm = ({ onSubmit, mode = "create", initialValues, for field.onChange(slugify(e.target.value))} maxLength={32} minLength={2} /> diff --git a/app/server/modules/notifications/notifications.service.ts b/app/server/modules/notifications/notifications.service.ts index 342c91bf..ed777093 100644 --- a/app/server/modules/notifications/notifications.service.ts +++ b/app/server/modules/notifications/notifications.service.ts @@ -1,6 +1,5 @@ import { eq, and, ne, inArray } from "drizzle-orm"; import { ConflictError, InternalServerError, NotFoundError } from "http-errors-enhanced"; -import slugify from "slugify"; import { db } from "../../db/db"; import { notificationDestinationsTable, @@ -139,22 +138,14 @@ async function decryptSensitiveFields(config: NotificationConfig): Promise { const organizationId = getOrganizationId(); - const slug = slugify(name, { lower: true, strict: true }); - - const existing = await db.query.notificationDestinationsTable.findFirst({ - where: and(eq(notificationDestinationsTable.name, slug), eq(notificationDestinationsTable.organizationId, organizationId)), - }); - - if (existing) { - throw new ConflictError("Notification destination with this name already exists"); - } + const trimmedName = name.trim(); const encryptedConfig = await encryptSensitiveFields(config); const [created] = await db .insert(notificationDestinationsTable) .values({ - name: slug, + name: trimmedName, type: config.type, config: encryptedConfig, organizationId, @@ -184,16 +175,7 @@ const updateDestination = async ( }; if (updates.name !== undefined) { - const slug = slugify(updates.name, { lower: true, strict: true }); - - const conflict = await db.query.notificationDestinationsTable.findFirst({ - where: and(eq(notificationDestinationsTable.name, slug), ne(notificationDestinationsTable.id, id), eq(notificationDestinationsTable.organizationId, organizationId)), - }); - - if (conflict) { - throw new ConflictError("Notification destination with this name already exists"); - } - updateData.name = slug; + updateData.name = updates.name.trim(); } if (updates.enabled !== undefined) { diff --git a/app/server/modules/volumes/volume.service.ts b/app/server/modules/volumes/volume.service.ts index a570f268..32af879f 100644 --- a/app/server/modules/volumes/volume.service.ts +++ b/app/server/modules/volumes/volume.service.ts @@ -3,7 +3,6 @@ import * as os from "node:os"; import * as path from "node:path"; import { and, eq, ne } from "drizzle-orm"; import { ConflictError, InternalServerError, NotFoundError } from "http-errors-enhanced"; -import slugify from "slugify"; import { db } from "../../db/db"; import { volumesTable } from "../../db/schema"; import { cryptoUtils } from "../../utils/crypto"; @@ -65,15 +64,7 @@ const findVolume = async (idOrShortId: string | number) => { const createVolume = async (name: string, backendConfig: BackendConfig) => { const organizationId = getOrganizationId(); - const slug = slugify(name, { lower: true, strict: true }); - - const existing = await db.query.volumesTable.findFirst({ - where: and(eq(volumesTable.name, slug), eq(volumesTable.organizationId, organizationId)), - }); - - if (existing) { - throw new ConflictError("Volume already exists"); - } + const trimmedName = name.trim(); const shortId = generateShortId(); const encryptedConfig = await encryptSensitiveFields(backendConfig); @@ -82,7 +73,7 @@ const createVolume = async (name: string, backendConfig: BackendConfig) => { .insert(volumesTable) .values({ shortId, - name: slug, + name: trimmedName, config: encryptedConfig, type: backendConfig.backend, organizationId, @@ -191,24 +182,7 @@ const updateVolume = async (idOrShortId: string | number, volumeData: UpdateVolu throw new NotFoundError("Volume not found"); } - let newName = existing.name; - if (volumeData.name !== undefined && volumeData.name !== existing.name) { - const newSlug = slugify(volumeData.name, { lower: true, strict: true }); - - const conflict = await db.query.volumesTable.findFirst({ - where: and( - eq(volumesTable.name, newSlug), - ne(volumesTable.id, existing.id), - eq(volumesTable.organizationId, organizationId), - ), - }); - - if (conflict) { - throw new ConflictError("A volume with this name already exists"); - } - - newName = newSlug; - } + const newName = volumeData.name !== undefined ? volumeData.name.trim() : existing.name; const configChanged = JSON.stringify(existing.config) !== JSON.stringify(volumeData.config) && volumeData.config !== undefined;