Skip to content

Commit

Permalink
feat: extra nameCN for character & person (#846)
Browse files Browse the repository at this point in the history
  • Loading branch information
everpcpc authored Dec 1, 2024
1 parent 8904e5a commit 409ab9a
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lib/types/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 [];
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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');
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions lib/types/res.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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(),
Expand All @@ -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(), {
Expand All @@ -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(),
Expand Down
12 changes: 12 additions & 0 deletions routes/__snapshots__/index.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions routes/private/routes/__snapshots__/character.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions routes/private/routes/__snapshots__/person.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions routes/private/routes/__snapshots__/subject.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions routes/private/routes/__snapshots__/user.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 409ab9a

Please sign in to comment.