IGDB auto-enrichment: Server-Start + Frontend auto-trigger
- Server enriched bestehende User beim Plugin-Start automatisch (fire-and-forget) - Frontend triggert IGDB-Enrichment automatisch beim Öffnen einer User-Bibliothek - Reduzierte Log-Ausgabe (kein Spam pro Cache-Hit mehr) - IGDB-Button zeigt Lade-Animation während Enrichment Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
916006e815
commit
4994d5c245
4 changed files with 68 additions and 6 deletions
|
|
@ -271,14 +271,18 @@ export async function enrichGames(
|
|||
for (const game of games) {
|
||||
const cached = enrichmentCache.get(game.appid);
|
||||
if (cached) {
|
||||
console.log(`[IGDB] Cache hit for appid ${game.appid} ("${cached.name}")`);
|
||||
result.set(game.appid, cached);
|
||||
} else {
|
||||
toFetch.push(game);
|
||||
}
|
||||
}
|
||||
|
||||
if (toFetch.length === 0) return result;
|
||||
if (toFetch.length === 0) {
|
||||
console.log(`[IGDB] All ${games.length} games found in cache`);
|
||||
return result;
|
||||
}
|
||||
|
||||
console.log(`[IGDB] ${result.size} cache hits, ${toFetch.length} to fetch`);
|
||||
|
||||
const BATCH_SIZE = 4;
|
||||
for (let i = 0; i < toFetch.length; i += BATCH_SIZE) {
|
||||
|
|
|
|||
|
|
@ -118,8 +118,41 @@ const gameLibraryPlugin: Plugin = {
|
|||
description: 'Steam Spielebibliothek',
|
||||
|
||||
async init(ctx) {
|
||||
loadData(ctx); // ensure file exists
|
||||
const data = loadData(ctx); // ensure file exists
|
||||
console.log('[GameLibrary] Initialized');
|
||||
|
||||
// Fire-and-forget: auto-enrich all existing users with IGDB data
|
||||
const allUsers = Object.values(data.users);
|
||||
const unenrichedUsers = allUsers.filter(u =>
|
||||
u.games.some(g => !g.igdb),
|
||||
);
|
||||
if (unenrichedUsers.length > 0) {
|
||||
console.log(`[GameLibrary] Auto-enriching ${unenrichedUsers.length} user(s) with IGDB data...`);
|
||||
(async () => {
|
||||
for (const user of unenrichedUsers) {
|
||||
try {
|
||||
const unenrichedGames = user.games.filter(g => !g.igdb).map(g => ({ appid: g.appid, name: g.name }));
|
||||
console.log(`[GameLibrary] IGDB auto-enriching ${user.personaName}: ${unenrichedGames.length} games...`);
|
||||
const igdbMap = await enrichGames(unenrichedGames);
|
||||
// Reload fresh to avoid stale writes
|
||||
const freshData = loadData(ctx);
|
||||
const freshUser = freshData.users[user.steamId];
|
||||
if (freshUser) {
|
||||
let count = 0;
|
||||
for (const game of freshUser.games) {
|
||||
const info = igdbMap.get(game.appid);
|
||||
if (info) { game.igdb = info; count++; }
|
||||
}
|
||||
saveData(ctx, freshData);
|
||||
console.log(`[GameLibrary] IGDB startup enrichment for ${user.personaName}: ${count}/${unenrichedGames.length} games matched`);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(`[GameLibrary] IGDB startup enrichment error for ${user.personaName}:`, err);
|
||||
}
|
||||
}
|
||||
console.log('[GameLibrary] IGDB startup enrichment complete.');
|
||||
})();
|
||||
}
|
||||
},
|
||||
|
||||
registerRoutes(app: express.Application, ctx: PluginContext) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue