From b22dfa27c216d3eab514d9f0429b46ae36af6442 Mon Sep 17 00:00:00 2001 From: Philipinho <16838612+Philipinho@users.noreply.github.com> Date: Tue, 17 Feb 2026 03:01:21 +0000 Subject: [PATCH] limit --- apps/server/src/core/label/label.service.ts | 11 ++++++++++- apps/server/src/database/repos/label/label.repo.ts | 14 ++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/apps/server/src/core/label/label.service.ts b/apps/server/src/core/label/label.service.ts index 168ec3fd..912cca54 100644 --- a/apps/server/src/core/label/label.service.ts +++ b/apps/server/src/core/label/label.service.ts @@ -1,10 +1,12 @@ -import { Injectable } from '@nestjs/common'; +import { BadRequestException, Injectable } from '@nestjs/common'; import { LabelRepo, LabelType } from '@docmost/db/repos/label/label.repo'; import { InjectKysely } from 'nestjs-kysely'; import { KyselyDB } from '@docmost/db/types/kysely.types'; import { executeTx } from '@docmost/db/utils'; import { PaginationOptions } from '@docmost/db/pagination/pagination-options'; +const MAX_LABELS_PER_PAGE = 25; + @Injectable() export class LabelService { constructor( @@ -18,6 +20,13 @@ export class LabelService { workspaceId: string, ) { await executeTx(this.db, async (trx) => { + const currentCount = await this.labelRepo.getPageLabelCount(pageId, trx); + if (currentCount + names.length > MAX_LABELS_PER_PAGE) { + throw new BadRequestException( + `A page can have a maximum of ${MAX_LABELS_PER_PAGE} labels`, + ); + } + for (const name of names) { const label = await this.labelRepo.findOrCreate( name.trim(), diff --git a/apps/server/src/database/repos/label/label.repo.ts b/apps/server/src/database/repos/label/label.repo.ts index 13f88771..62abd678 100644 --- a/apps/server/src/database/repos/label/label.repo.ts +++ b/apps/server/src/database/repos/label/label.repo.ts @@ -164,6 +164,20 @@ export class LabelRepo { .execute(); } + async getPageLabelCount( + pageId: string, + trx?: KyselyTransaction, + ): Promise { + const db = dbOrTx(this.db, trx); + const result = await db + .selectFrom('pageLabels') + .select((eb) => eb.fn.count('id').as('count')) + .where('pageId', '=', pageId) + .executeTakeFirst(); + + return Number(result?.count ?? 0); + } + async getLabelPageCount( labelId: string, trx?: KyselyTransaction,