From 409ab9a4d1c6b33097c241abfeefe977058c5cf4 Mon Sep 17 00:00:00 2001 From: everpcpc Date: Sun, 1 Dec 2024 19:48:51 +0800 Subject: [PATCH] feat: extra nameCN for character & person (#846) --- lib/types/convert.ts | 16 ++++++++++++++-- lib/types/res.ts | 4 ++++ routes/__snapshots__/index.test.ts.snap | 12 ++++++++++++ .../routes/__snapshots__/character.test.ts.snap | 1 + .../routes/__snapshots__/person.test.ts.snap | 1 + .../routes/__snapshots__/subject.test.ts.snap | 4 ++++ .../routes/__snapshots__/user.test.ts.snap | 2 ++ 7 files changed, 38 insertions(+), 2 deletions(-) diff --git a/lib/types/convert.ts b/lib/types/convert.ts index 97618de6..e3f56084 100644 --- a/lib/types/convert.ts +++ b/lib/types/convert.ts @@ -20,6 +20,10 @@ export function splitTags(tags: string): string[] { .filter((x) => x !== ''); } +export function extractNameCN(infobox: res.IInfobox): string { + return infobox.find((x) => ['中文名', '简体中文名'].includes(x.key))?.values[0]?.v ?? ''; +} + export function toSubjectTags(tags: string): res.ISubjectTag[] { if (!tags) { return []; @@ -290,9 +294,11 @@ export function toSubjectEpStatus( } export function toSlimCharacter(character: orm.ICharacter): res.ISlimCharacter { + const infobox = toInfobox(character.infobox); return { id: character.id, name: character.name, + nameCN: extractNameCN(infobox), role: character.role, images: personImages(character.img) || undefined, nsfw: character.nsfw, @@ -301,11 +307,13 @@ export function toSlimCharacter(character: orm.ICharacter): res.ISlimCharacter { } export function toCharacter(character: orm.ICharacter): res.ICharacter { + const infobox = toInfobox(character.infobox); return { id: character.id, name: character.name, + nameCN: extractNameCN(infobox), role: character.role, - infobox: toInfobox(character.infobox), + infobox: infobox, summary: character.summary, images: personImages(character.img) || undefined, comment: character.comment, @@ -317,9 +325,11 @@ export function toCharacter(character: orm.ICharacter): res.ICharacter { } export function toSlimPerson(person: orm.IPerson): res.ISlimPerson { + const infobox = toInfobox(person.infobox); return { id: person.id, name: person.name, + nameCN: extractNameCN(infobox), type: person.type, images: personImages(person.img) || undefined, nsfw: person.nsfw, @@ -328,6 +338,7 @@ export function toSlimPerson(person: orm.IPerson): res.ISlimPerson { } export function toPerson(person: orm.IPerson): res.IPerson { + const infobox = toInfobox(person.infobox); const career = []; if (person.producer) { career.push('producer'); @@ -356,8 +367,9 @@ export function toPerson(person: orm.IPerson): res.IPerson { return { id: person.id, name: person.name, + nameCN: extractNameCN(infobox), type: person.type, - infobox: toInfobox(person.infobox), + infobox: infobox, career, summary: person.summary, images: personImages(person.img) || undefined, diff --git a/lib/types/res.ts b/lib/types/res.ts index 99737a5b..e24b68be 100644 --- a/lib/types/res.ts +++ b/lib/types/res.ts @@ -298,6 +298,7 @@ export const Character = t.Object( { id: t.Integer(), name: t.String(), + nameCN: t.String(), role: t.Integer(), infobox: t.Ref(Infobox), summary: t.String(), @@ -320,6 +321,7 @@ export const SlimCharacter = t.Object( { id: t.Integer(), name: t.String(), + nameCN: t.String(), role: t.Integer(), images: t.Optional(t.Ref(PersonImages)), lock: t.Boolean(), @@ -337,6 +339,7 @@ export const Person = t.Object( { id: t.Integer(), name: t.String(), + nameCN: t.String(), type: t.Integer(), infobox: t.Ref(Infobox), career: t.Array(t.String(), { @@ -363,6 +366,7 @@ export const SlimPerson = t.Object( { id: t.Integer(), name: t.String(), + nameCN: t.String(), type: t.Integer(), images: t.Optional(t.Ref(PersonImages)), lock: t.Boolean(), diff --git a/routes/__snapshots__/index.test.ts.snap b/routes/__snapshots__/index.test.ts.snap index d3ff3813..03b503fc 100644 --- a/routes/__snapshots__/index.test.ts.snap +++ b/routes/__snapshots__/index.test.ts.snap @@ -81,6 +81,8 @@ exports[`should build private api spec 1`] = ` type: boolean name: type: string + nameCN: + type: string nsfw: type: boolean redirect: @@ -92,6 +94,7 @@ exports[`should build private api spec 1`] = ` required: - id - name + - nameCN - role - infobox - summary @@ -710,6 +713,8 @@ exports[`should build private api spec 1`] = ` type: boolean name: type: string + nameCN: + type: string nsfw: type: boolean redirect: @@ -721,6 +726,7 @@ exports[`should build private api spec 1`] = ` required: - id - name + - nameCN - type - infobox - career @@ -913,6 +919,8 @@ exports[`should build private api spec 1`] = ` type: boolean name: type: string + nameCN: + type: string nsfw: type: boolean role: @@ -920,6 +928,7 @@ exports[`should build private api spec 1`] = ` required: - id - name + - nameCN - role - lock - nsfw @@ -955,6 +964,8 @@ exports[`should build private api spec 1`] = ` type: boolean name: type: string + nameCN: + type: string nsfw: type: boolean type: @@ -962,6 +973,7 @@ exports[`should build private api spec 1`] = ` required: - id - name + - nameCN - type - lock - nsfw diff --git a/routes/private/routes/__snapshots__/character.test.ts.snap b/routes/private/routes/__snapshots__/character.test.ts.snap index d81da768..02d3288b 100644 --- a/routes/private/routes/__snapshots__/character.test.ts.snap +++ b/routes/private/routes/__snapshots__/character.test.ts.snap @@ -112,6 +112,7 @@ Object { ], "lock": false, "name": "ちぃ", + "nameCN": "小叽", "nsfw": false, "redirect": 0, "role": 1, diff --git a/routes/private/routes/__snapshots__/person.test.ts.snap b/routes/private/routes/__snapshots__/person.test.ts.snap index 02967c79..93300f87 100644 --- a/routes/private/routes/__snapshots__/person.test.ts.snap +++ b/routes/private/routes/__snapshots__/person.test.ts.snap @@ -172,6 +172,7 @@ Object { ], "lock": false, "name": "水樹奈々", + "nameCN": "水树奈奈", "nsfw": false, "redirect": 0, "summary": "原名 近藤 奈々(こんどう なな),日本女性声优兼歌手。有个妹妹名字是近藤美香,为Daisy×Daisy主唱。 diff --git a/routes/private/routes/__snapshots__/subject.test.ts.snap b/routes/private/routes/__snapshots__/subject.test.ts.snap index 50fbf269..6bbd02cc 100644 --- a/routes/private/routes/__snapshots__/subject.test.ts.snap +++ b/routes/private/routes/__snapshots__/subject.test.ts.snap @@ -423,6 +423,7 @@ Object { }, "lock": false, "name": "ちぃ", + "nameCN": "小叽", "nsfw": false, "role": 1, }, @@ -441,6 +442,7 @@ Object { }, "lock": false, "name": "本須和秀樹", + "nameCN": "本须和秀树", "nsfw": false, "role": 1, }, @@ -575,6 +577,7 @@ Object { }, "lock": false, "name": "CLAMP", + "nameCN": "", "nsfw": false, "type": 3, }, @@ -596,6 +599,7 @@ Object { }, "lock": false, "name": "浅香守生", + "nameCN": "浅香守生", "nsfw": false, "type": 1, }, diff --git a/routes/private/routes/__snapshots__/user.test.ts.snap b/routes/private/routes/__snapshots__/user.test.ts.snap index 8bd17774..2db5361b 100644 --- a/routes/private/routes/__snapshots__/user.test.ts.snap +++ b/routes/private/routes/__snapshots__/user.test.ts.snap @@ -145,6 +145,7 @@ Object { ], "lock": false, "name": "ちぃ", + "nameCN": "小叽", "nsfw": false, "redirect": 0, "role": 1, @@ -341,6 +342,7 @@ Object { ], "lock": false, "name": "ちぃ", + "nameCN": "小叽", "nsfw": false, "redirect": 0, "role": 1,