feat: labels (WIP)

This commit is contained in:
Philipinho
2026-02-17 02:01:32 +00:00
parent 0aeaa43112
commit ca173a9c98
13 changed files with 562 additions and 0 deletions
@@ -48,6 +48,7 @@ import { EventEmitter2 } from '@nestjs/event-emitter';
import { CollaborationGateway } from '../../../collaboration/collaboration.gateway';
import { markdownToHtml } from '@docmost/editor-ext';
import { WatcherService } from '../../watcher/watcher.service';
import { LabelRepo } from '@docmost/db/repos/label/label.repo';
@Injectable()
export class PageService {
@@ -64,6 +65,7 @@ export class PageService {
private eventEmitter: EventEmitter2,
private collaborationGateway: CollaborationGateway,
private readonly watcherService: WatcherService,
private readonly labelRepo: LabelRepo,
) {}
async findById(
@@ -729,11 +731,18 @@ export class PageService {
}
if (pageIds.length > 0) {
const affectedLabelIds =
await this.labelRepo.findLabelIdsByPageIds(pageIds);
await this.db.deleteFrom('pages').where('id', 'in', pageIds).execute();
this.eventEmitter.emit(EventName.PAGE_DELETED, {
pageIds: pageIds,
workspaceId,
});
if (affectedLabelIds.length > 0) {
await this.labelRepo.deleteOrphanedLabels(affectedLabelIds);
}
}
}
@@ -5,6 +5,7 @@ import { KyselyDB } from '@docmost/db/types/kysely.types';
import { InjectQueue } from '@nestjs/bullmq';
import { Queue } from 'bullmq';
import { QueueJob, QueueName } from '../../../integrations/queue/constants';
import { LabelRepo } from '@docmost/db/repos/label/label.repo';
@Injectable()
export class TrashCleanupService {
@@ -14,6 +15,7 @@ export class TrashCleanupService {
constructor(
@InjectKysely() private readonly db: KyselyDB,
@InjectQueue(QueueName.ATTACHMENT_QUEUE) private attachmentQueue: Queue,
private readonly labelRepo: LabelRepo,
) {}
@Interval('trash-cleanup', 24 * 60 * 60 * 1000) // every 24 hours
@@ -104,7 +106,14 @@ export class TrashCleanupService {
try {
if (pageIds.length > 0) {
const affectedLabelIds =
await this.labelRepo.findLabelIdsByPageIds(pageIds);
await this.db.deleteFrom('pages').where('id', 'in', pageIds).execute();
if (affectedLabelIds.length > 0) {
await this.labelRepo.deleteOrphanedLabels(affectedLabelIds);
}
}
} catch (error) {
// Log but don't throw - pages might have been deleted by another node