From 60a8cb896d9cece279a363632bc354d1325d886e Mon Sep 17 00:00:00 2001 From: YaoJunchang Date: Thu, 14 May 2026 10:25:31 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20refactor=20bookmark=20handling=20to?= =?UTF-8?q?=20use=20stripBookmarkInternals=20for=20cleaner=20response=20st?= =?UTF-8?q?ructure?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/domain/orchestrator/bookmark.ts | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/domain/orchestrator/bookmark.ts b/src/domain/orchestrator/bookmark.ts index 78fe8ef..214b39b 100644 --- a/src/domain/orchestrator/bookmark.ts +++ b/src/domain/orchestrator/bookmark.ts @@ -1,11 +1,27 @@ import { inject, injectable } from '../../decorators/di' import { ContextManager } from '../../utils/context' -import { BookmarkNotFoundError, BookmarkOverviewContentError } from '../../const/err' +import { BookmarkNotFoundError } from '../../const/err' import { BookmarkService } from '../bookmark' import { TagService } from '../tag' import { MarkService } from '../mark' import { MixTagsOverviewResult } from '../aigc' +type BookmarkRow = { id: number; content_key: string; content_md_key: string | null; private_user: number; [key: string]: unknown } + +export function stripBookmarkInternals( + bookmark: T, + encodeId: (id: number) => number +): Omit & { bookmark_id: number } { + const copy = { ...bookmark } as Record + const id = copy.id as number + delete copy.id + delete copy.content_key + delete copy.content_md_key + delete copy.private_user + copy.bookmark_id = encodeId(id) + return copy as Omit & { bookmark_id: number } +} + @injectable() export class BookmarkOrchestrator { constructor( @@ -33,12 +49,11 @@ export class BookmarkOrchestrator { this.bookmarkService.getUserBookmarkOverview(ctx.getUserId(), bmId), this.tagService.getBookmarkTags(ctx, ctx.getUserId(), bmId) ]) - const { id, content_key, content_md_key, private_user, ...bookmarkWithoutId } = res.bookmark const { overview, key_takeaways } = this.parseOverviewRes(overviewResult.status === 'fulfilled' ? (overviewResult.value ?? null) : null) + const base = stripBookmarkInternals(res.bookmark, id => ctx.hashIds.encodeId(id)) return { - ...bookmarkWithoutId, - bookmark_id: ctx.hashIds.encodeId(res.bookmark.id), + ...base, archived: res.archive_status === 1 ? 'archive' : res.archive_status === 2 ? 'later' : 'inbox', starred: res.is_starred ? 'star' : 'unstar', alias_title: res.alias_title, @@ -64,13 +79,11 @@ export class BookmarkOrchestrator { this.bookmarkService.getUserBookmarkOverview(userId, bmId) ]) - // eslint-disable-next-line @typescript-eslint/no-unused-vars - const { id, content_key, content_md_key, private_user, ...bookmarkWithoutId } = res.bookmark const { overview, key_takeaways } = this.parseOverviewRes(overviewResult.status === 'fulfilled' ? (overviewResult.value ?? null) : null) + const base = stripBookmarkInternals(res.bookmark, id => ctx.hashIds.encodeId(id)) return { - ...bookmarkWithoutId, - bookmark_id: ctx.hashIds.encodeId(res.bookmark.id), + ...base, content: contentResult.status === 'fulfilled' ? contentResult.value : undefined, archived: res.archive_status === 1 ? 'archive' : res.archive_status === 2 ? 'later' : 'inbox', starred: res.is_starred ? 'star' : 'unstar',