Store share key in lowercase

This commit is contained in:
Philipinho
2025-04-22 12:22:24 +01:00
parent b5b48378ab
commit 644cbd62de
2 changed files with 5 additions and 5 deletions

View File

@ -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,
)

View File

@ -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();
}