From 29977e16e518deb3e99d3b2f0bbf8850d168227e Mon Sep 17 00:00:00 2001 From: Kevin Cui Date: Wed, 18 Dec 2024 16:37:19 +0800 Subject: [PATCH] fix(search): author is `???` in result Signed-off-by: Kevin Cui --- app/core/service/PackageSearchService.ts | 10 ++++++++++ app/repository/SearchRepository.ts | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/app/core/service/PackageSearchService.ts b/app/core/service/PackageSearchService.ts index 4ef75858..392080ec 100644 --- a/app/core/service/PackageSearchService.ts +++ b/app/core/service/PackageSearchService.ts @@ -141,6 +141,16 @@ export class PackageSearchService extends AbstractService { const { hits, total } = res; return { objects: hits?.map(item => { + // 从 https://github.com/npm/cli/pull/7407 (npm cli v10.6.0) 开始,npm cli 使用 publisher 字段(以前使用 maintainers 字段) + // 从现有数据来看,_npmUser 字段和 publisher 字段是等价的 + // 为了兼容老版本,不删除 _npmUser 字段 + if (!item._source?.package.publisher && item._source?.package._npmUser) { + item._source.package.publisher = { + username: item._source.package._npmUser.name, + email: item._source.package._npmUser.email, + }; + } + return item._source; }), total: (total as estypes.SearchTotalHits).value, diff --git a/app/repository/SearchRepository.ts b/app/repository/SearchRepository.ts index 2cdf7cd5..583336fb 100644 --- a/app/repository/SearchRepository.ts +++ b/app/repository/SearchRepository.ts @@ -17,6 +17,10 @@ export type SearchMappingType = Pick & C name: string; email: string; } + publisher?: { + username: string; + email: string; + } };