mirror of
https://github.com/docmost/docmost.git
synced 2025-11-18 01:31:10 +10:00
Store share key in lowercase
This commit is contained in:
@ -7,7 +7,7 @@ import {
|
|||||||
import { CreateShareDto, ShareInfoDto, UpdateShareDto } from './dto/share.dto';
|
import { CreateShareDto, ShareInfoDto, UpdateShareDto } from './dto/share.dto';
|
||||||
import { InjectKysely } from 'nestjs-kysely';
|
import { InjectKysely } from 'nestjs-kysely';
|
||||||
import { KyselyDB } from '@docmost/db/types/kysely.types';
|
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 { PageRepo } from '@docmost/db/repos/page/page.repo';
|
||||||
import { TokenService } from '../auth/services/token.service';
|
import { TokenService } from '../auth/services/token.service';
|
||||||
import { jsonToNode } from '../../collaboration/collaboration.util';
|
import { jsonToNode } from '../../collaboration/collaboration.util';
|
||||||
@ -66,7 +66,7 @@ export class ShareService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return await this.shareRepo.insertShare({
|
return await this.shareRepo.insertShare({
|
||||||
key: generateSlugId(),
|
key: nanoIdGen().toLowerCase(),
|
||||||
pageId: page.id,
|
pageId: page.id,
|
||||||
includeSubPages: createShareDto.includeSubPages || true,
|
includeSubPages: createShareDto.includeSubPages || true,
|
||||||
searchIndexing: createShareDto.searchIndexing || true,
|
searchIndexing: createShareDto.searchIndexing || true,
|
||||||
@ -224,7 +224,7 @@ export class ShareService {
|
|||||||
.as('found'),
|
.as('found'),
|
||||||
])
|
])
|
||||||
.where(
|
.where(
|
||||||
!isValidUUID(childPageId) ? 'slugId' : 'id',
|
isValidUUID(childPageId) ? 'id' : 'slugId',
|
||||||
'=',
|
'=',
|
||||||
childPageId,
|
childPageId,
|
||||||
)
|
)
|
||||||
|
|||||||
@ -59,7 +59,7 @@ export class ShareRepo {
|
|||||||
if (isValidUUID(shareId)) {
|
if (isValidUUID(shareId)) {
|
||||||
query = query.where('id', '=', shareId);
|
query = query.where('id', '=', shareId);
|
||||||
} else {
|
} else {
|
||||||
query = query.where('key', '=', shareId);
|
query = query.where(sql`LOWER(key)`, '=', shareId.toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
return query.executeTakeFirst();
|
return query.executeTakeFirst();
|
||||||
@ -98,7 +98,7 @@ export class ShareRepo {
|
|||||||
return dbOrTx(this.db, trx)
|
return dbOrTx(this.db, trx)
|
||||||
.updateTable('shares')
|
.updateTable('shares')
|
||||||
.set({ ...updatableShare, updatedAt: new Date() })
|
.set({ ...updatableShare, updatedAt: new Date() })
|
||||||
.where(!isValidUUID(shareId) ? 'key' : 'id', '=', shareId)
|
.where(isValidUUID(shareId) ? 'id' : sql`LOWER(key)`, '=', shareId.toLowerCase())
|
||||||
.returning(this.baseFields)
|
.returning(this.baseFields)
|
||||||
.executeTakeFirst();
|
.executeTakeFirst();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user