From 644cbd62de5fa776d1a7a051a60bc5acb8ae9502 Mon Sep 17 00:00:00 2001 From: Philipinho <16838612+Philipinho@users.noreply.github.com> Date: Tue, 22 Apr 2025 12:22:24 +0100 Subject: [PATCH] Store share key in lowercase --- apps/server/src/core/share/share.service.ts | 6 +++--- apps/server/src/database/repos/share/share.repo.ts | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/apps/server/src/core/share/share.service.ts b/apps/server/src/core/share/share.service.ts index 77e93f47..a9140c0b 100644 --- a/apps/server/src/core/share/share.service.ts +++ b/apps/server/src/core/share/share.service.ts @@ -7,7 +7,7 @@ import { import { CreateShareDto, ShareInfoDto, UpdateShareDto } from './dto/share.dto'; import { InjectKysely } from 'nestjs-kysely'; import { KyselyDB } from '@docmost/db/types/kysely.types'; -import { generateSlugId } from '../../common/helpers'; +import { nanoIdGen } from '../../common/helpers'; import { PageRepo } from '@docmost/db/repos/page/page.repo'; import { TokenService } from '../auth/services/token.service'; import { jsonToNode } from '../../collaboration/collaboration.util'; @@ -66,7 +66,7 @@ export class ShareService { } return await this.shareRepo.insertShare({ - key: generateSlugId(), + key: nanoIdGen().toLowerCase(), pageId: page.id, includeSubPages: createShareDto.includeSubPages || true, searchIndexing: createShareDto.searchIndexing || true, @@ -224,7 +224,7 @@ export class ShareService { .as('found'), ]) .where( - !isValidUUID(childPageId) ? 'slugId' : 'id', + isValidUUID(childPageId) ? 'id' : 'slugId', '=', childPageId, ) diff --git a/apps/server/src/database/repos/share/share.repo.ts b/apps/server/src/database/repos/share/share.repo.ts index 01209f2a..44e8cd33 100644 --- a/apps/server/src/database/repos/share/share.repo.ts +++ b/apps/server/src/database/repos/share/share.repo.ts @@ -59,7 +59,7 @@ export class ShareRepo { if (isValidUUID(shareId)) { query = query.where('id', '=', shareId); } else { - query = query.where('key', '=', shareId); + query = query.where(sql`LOWER(key)`, '=', shareId.toLowerCase()); } return query.executeTakeFirst(); @@ -98,7 +98,7 @@ export class ShareRepo { return dbOrTx(this.db, trx) .updateTable('shares') .set({ ...updatableShare, updatedAt: new Date() }) - .where(!isValidUUID(shareId) ? 'key' : 'id', '=', shareId) + .where(isValidUUID(shareId) ? 'id' : sql`LOWER(key)`, '=', shareId.toLowerCase()) .returning(this.baseFields) .executeTakeFirst(); }