Skip to content

Commit

Permalink
Merge pull request #84 from fishshi/main
Browse files Browse the repository at this point in the history
fix: Fix search with title when using vndb api
  • Loading branch information
ximu3 authored Dec 6, 2024
2 parents 5fa34d2 + 80c5ad1 commit e970d03
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/main/scraper/vndb/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,21 @@ export async function getGameScreenshots(vnId: string): Promise<string[]> {
}

export async function getGameScreenshotsByTitle(title: string): Promise<string[]> {
const fields = ['screenshots{url}'] as const
const fields = ['titles{title}', 'screenshots{url}'] as const

try {
const data = await fetchVNDB({
filters: ['search', '=', title],
fields,
results: 1
fields
})

return data.results[0].screenshots.map((screenshot) => screenshot.url)
if (data.results.length > 0) {
let vn = data.results.find((result) =>
result.titles.some((titleJson) => titleJson.title.toLowerCase() === title.toLowerCase())
)
vn = vn || data.results[0]
return vn.screenshots.map((screenshot) => screenshot.url)
}
return []
} catch (error) {
console.error(`Error fetching images for VN ${title}:`, error)
return []
Expand Down

0 comments on commit e970d03

Please sign in to comment.