Fix IGDB search: remove where category=0 filter that blocked all results; fix cover.url handling in both search and applyIgdbId; add debug logging
This commit is contained in:
@@ -97,9 +97,8 @@ public class IgdbService {
|
|||||||
String apql = "search \"" + sanitize(query) + "\";"
|
String apql = "search \"" + sanitize(query) + "\";"
|
||||||
+ " fields name,first_release_date,genres.name,"
|
+ " fields name,first_release_date,genres.name,"
|
||||||
+ " involved_companies.company.name,involved_companies.developer,involved_companies.publisher,"
|
+ " involved_companies.company.name,involved_companies.developer,involved_companies.publisher,"
|
||||||
+ " summary,cover,platforms;"
|
+ " summary,cover.url,platforms;"
|
||||||
+ " where category = 0;"
|
+ " limit 20;";
|
||||||
+ " limit 10;";
|
|
||||||
|
|
||||||
HttpRequest req = igdbRequest("/games")
|
HttpRequest req = igdbRequest("/games")
|
||||||
.POST(HttpRequest.BodyPublishers.ofString(apql))
|
.POST(HttpRequest.BodyPublishers.ofString(apql))
|
||||||
@@ -107,12 +106,15 @@ public class IgdbService {
|
|||||||
|
|
||||||
HttpResponse<String> res = http.send(req, HttpResponse.BodyHandlers.ofString());
|
HttpResponse<String> res = http.send(req, HttpResponse.BodyHandlers.ofString());
|
||||||
if (res.statusCode() != 200) {
|
if (res.statusCode() != 200) {
|
||||||
LOG.warning("IGDB search failed: HTTP " + res.statusCode());
|
LOG.warning("IGDB search failed: HTTP " + res.statusCode() + " " + res.body());
|
||||||
return List.of();
|
return List.of();
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonNode results = mapper.readTree(res.body());
|
JsonNode results = mapper.readTree(res.body());
|
||||||
if (!results.isArray()) return List.of();
|
if (!results.isArray() || results.isEmpty()) {
|
||||||
|
LOG.info("IGDB search: no results for '" + query + "'. Response: " + res.body());
|
||||||
|
return List.of();
|
||||||
|
}
|
||||||
|
|
||||||
List<Map<String, Object>> out = new ArrayList<>();
|
List<Map<String, Object>> out = new ArrayList<>();
|
||||||
for (JsonNode game : results) {
|
for (JsonNode game : results) {
|
||||||
@@ -167,9 +169,16 @@ public class IgdbService {
|
|||||||
entry.put("is_dos", isDos);
|
entry.put("is_dos", isDos);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cover URL (fetch from covers endpoint if ID is present)
|
// Cover URL — IGDB now returns cover as object with url (since we use cover.url in fields)
|
||||||
if (game.has("cover") && game.get("cover").has("id")) {
|
if (game.has("cover") && game.get("cover").has("url")) {
|
||||||
int coverId = game.get("cover").get("id").asInt();
|
String thumbUrl = game.get("cover").get("url").asText();
|
||||||
|
// IGDB URL format: //images.igdb.com/igdb/image/upload/t_thumb/co1x8h.jpg
|
||||||
|
// Replace t_thumb with our desired size
|
||||||
|
String coverUrl = "https:" + thumbUrl.replace("t_thumb", COVER_SIZE);
|
||||||
|
entry.put("cover_url", coverUrl);
|
||||||
|
} else if (game.has("cover") && game.get("cover").isInt()) {
|
||||||
|
// Fallback: cover is just an integer ID, fetch URL separately
|
||||||
|
int coverId = game.get("cover").asInt();
|
||||||
String coverUrl = fetchCoverUrl(coverId);
|
String coverUrl = fetchCoverUrl(coverId);
|
||||||
if (coverUrl != null) {
|
if (coverUrl != null) {
|
||||||
entry.put("cover_url", coverUrl);
|
entry.put("cover_url", coverUrl);
|
||||||
@@ -245,7 +254,7 @@ public class IgdbService {
|
|||||||
// Fetch game details from IGDB by ID
|
// Fetch game details from IGDB by ID
|
||||||
String apql = "fields name,first_release_date,genres.name,"
|
String apql = "fields name,first_release_date,genres.name,"
|
||||||
+ " involved_companies.company.name,involved_companies.developer,involved_companies.publisher,"
|
+ " involved_companies.company.name,involved_companies.developer,involved_companies.publisher,"
|
||||||
+ " summary,cover;"
|
+ " summary,cover.url;"
|
||||||
+ " where id = " + igdbId + ";";
|
+ " where id = " + igdbId + ";";
|
||||||
|
|
||||||
HttpRequest req = igdbRequest("/games")
|
HttpRequest req = igdbRequest("/games")
|
||||||
@@ -379,11 +388,21 @@ public class IgdbService {
|
|||||||
map.put("summary", node.get("summary").asText());
|
map.put("summary", node.get("summary").asText());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch cover URL
|
// Fetch cover URL — handle cover.url object or raw ID
|
||||||
if (node.has("cover") && node.get("cover").has("id")) {
|
if (node.has("cover")) {
|
||||||
|
JsonNode cover = node.get("cover");
|
||||||
try {
|
try {
|
||||||
String coverUrl = fetchCoverUrl(node.get("cover").get("id").asInt());
|
if (cover.has("url")) {
|
||||||
|
String thumbUrl = cover.get("url").asText();
|
||||||
|
String coverUrl = "https:" + thumbUrl.replace("t_thumb", COVER_SIZE);
|
||||||
|
map.put("cover_url", coverUrl);
|
||||||
|
} else if (cover.isInt() || cover.isLong()) {
|
||||||
|
String coverUrl = fetchCoverUrl(cover.asInt());
|
||||||
if (coverUrl != null) map.put("cover_url", coverUrl);
|
if (coverUrl != null) map.put("cover_url", coverUrl);
|
||||||
|
} else if (cover.has("id")) {
|
||||||
|
String coverUrl = fetchCoverUrl(cover.get("id").asInt());
|
||||||
|
if (coverUrl != null) map.put("cover_url", coverUrl);
|
||||||
|
}
|
||||||
} catch (Exception ignored) {}
|
} catch (Exception ignored) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user