Skip to content

Commit c6acac2

Browse files
committed
fix: syncing vndb ja name error
1 parent 6f7e018 commit c6acac2

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

migration/sync-ts/api/vndb.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ async function vndbPost<T>(path: string, body: any): Promise<T> {
1414
return (await res.json()) as T
1515
}
1616

17+
// Normalize VNDB VN id for filters.
18+
// Accepts 'v1234', 'V1234', '1234' and returns a numeric id when possible.
19+
function normalizeVnIdForFilter(id: string | number): string | number {
20+
if (typeof id === 'number') return id
21+
const s = String(id || '').trim()
22+
const m = s.match(/^(?:[vV])?(\d+)$/)
23+
if (m) return Number(m[1])
24+
return s.toLowerCase()
25+
}
26+
1727
// Basic types (partial)
1828
export type VndbId = string
1929
export interface VndbImage {
@@ -92,8 +102,9 @@ export async function vndbFindVnByName(
92102
}
93103

94104
export async function vndbGetVnById(id: string): Promise<VndbVnDetail | null> {
105+
const normId = normalizeVnIdForFilter(id)
95106
const data = await vndbPost<{ results?: VndbVnDetail[] }>('/vn', {
96-
filters: ['id', '=', id],
107+
filters: ['id', '=', normId],
97108
fields:
98109
// Include alttitle and olang as per VNDB docs so we can
99110
// accurately resolve the Japanese original title when present.
@@ -134,8 +145,9 @@ export interface VndbRelease {
134145
export async function vndbGetReleasesByVn(
135146
vnId: string
136147
): Promise<VndbRelease[]> {
148+
const normId = normalizeVnIdForFilter(vnId)
137149
const data = await vndbPost<{ results?: VndbRelease[] }>('/release', {
138-
filters: ['vn', '=', ['id', '=', vnId]],
150+
filters: ['vn', '=', ['id', '=', normId]],
139151
fields:
140152
'id, title, released, platforms, languages{lang,latin,main,mtl,title}, minage, images{id,url,dims,sexual,violence,votecount,thumbnail,thumbnail_dims,type,languages,photo,vn}, producers{developer,publisher,id,name,original,aliases,description,type,lang,extlinks{id,label,name,url}}'
141153
})
@@ -233,14 +245,15 @@ export async function vndbGetCharactersByIds(
233245
export async function vndbGetCharactersByVn(
234246
vnId: string
235247
): Promise<VndbCharacterDetail[]> {
248+
const normId = normalizeVnIdForFilter(vnId)
236249
const results: VndbCharacterDetail[] = []
237250
let page = 1
238251
while (true) {
239252
const data = await vndbPost<{
240253
results?: VndbCharacterDetail[]
241254
more?: boolean
242255
}>('/character', {
243-
filters: ['vn', '=', ['id', '=', vnId]],
256+
filters: ['vn', '=', ['id', '=', normId]],
244257
fields:
245258
'id, name, original, image{id,url,dims,sexual,violence,votecount}, description, gender, height, weight, bust, waist, hips, cup, age, aliases, vns{id, role}',
246259
results: 100,

migration/sync-ts/mapping/bangumi.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,18 @@ export async function handleBangumiSubjectAndTags(
5151
)
5252
const zhName = subject?.name_cn || ''
5353
const jaName = (subject as any)?.nameJa || ''
54-
await prisma.patch
55-
.update({
56-
where: { id: patchId },
57-
data: {
58-
introduction_zh_cn: zhFromSummary,
59-
introduction_ja_jp: jaFromSummary,
60-
name_zh_cn: zhName,
61-
name_ja_jp: jaName
62-
}
63-
})
64-
.catch(() => {})
54+
// Only update fields when we actually have a non-empty value to avoid overwriting
55+
// VNDB-populated values with empty strings.
56+
const patchUpdate: any = {}
57+
if (zhFromSummary) patchUpdate.introduction_zh_cn = zhFromSummary
58+
if (jaFromSummary) patchUpdate.introduction_ja_jp = jaFromSummary
59+
if (zhName) patchUpdate.name_zh_cn = zhName
60+
if (jaName) patchUpdate.name_ja_jp = jaName
61+
if (Object.keys(patchUpdate).length) {
62+
await prisma.patch
63+
.update({ where: { id: patchId }, data: patchUpdate })
64+
.catch(() => {})
65+
}
6566

6667
// create patch_alias from bangumi names and infobox aliases
6768
try {

0 commit comments

Comments
 (0)