Skip to content

Commit e0e9ed5

Browse files
epic-games.js: isGpGameAlreadyClaimed: handle all DONE_STATUSES
1 parent 87fa9e0 commit e0e9ed5

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

epic-games.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,22 @@ function extractGameIdFromUrl(url) {
2727
return match ? match[1] : url.split('/').pop();
2828
}
2929

30+
// Statuses that indicate a game doesn't need to be claimed
31+
const DONE_STATUSES = ['claimed', 'existed', 'manual', 'unavailable-in-region'];
32+
3033
function isGpGameAlreadyClaimed(storeUrl) {
3134
const username = getUsername(PLATFORM, cfg.eg_email);
3235
if (!username) return false; // Username not known yet
33-
36+
3437
const game_id = extractGameIdFromUrl(storeUrl);
3538
const games = db.data[username];
36-
37-
if (games?.[game_id]?.status === 'claimed' || games?.[game_id]?.status === 'existed') {
38-
console.log(`[GamerPower] Already claimed by ${username}: ${storeUrl} -> ${game_id}`);
39+
const status = games?.[game_id]?.status;
40+
41+
if (status && DONE_STATUSES.includes(status)) {
42+
console.log(`[GamerPower] Already claimed by ${username}: ${storeUrl} -> ${game_id} (${status})`);
3943
return true;
4044
}
41-
45+
4246
return false;
4347
}
4448

@@ -59,7 +63,7 @@ async function getUnclaimedGpUrls() {
5963
// Filter out already claimed games
6064
const unclaimed = epicGames.filter(g => !isGpGameAlreadyClaimed(g.storeUrl));
6165
console.log(`[GamerPower] ${unclaimed.length} unclaimed games`);
62-
66+
6367
return unclaimed.map(g => g.storeUrl);
6468
}
6569

@@ -194,14 +198,14 @@ try {
194198
}
195199
user = await page.locator('egs-navigation').getAttribute('displayname'); // 'null' if !isloggedin
196200
console.log(`Signed in as ${user}`);
197-
201+
198202
// Save email -> username mapping if email is configured
199203
if (cfg.eg_email) {
200204
setUsername(PLATFORM, cfg.eg_email, user);
201205
await writeAccountsDb();
202206
}
203207
db.data[user] ||= {};
204-
208+
205209
if (cfg.time) console.timeEnd('login');
206210
if (cfg.time) console.time('claim all games');
207211

@@ -248,8 +252,10 @@ try {
248252

249253
for (const url of urls) {
250254
if (cfg.time) console.time('claim game');
251-
if (db.data[user][url.split('/').pop()]?.status == 'claimed') {
252-
console.log('Already claimed, skipping:', url);
255+
const urlGameId = url.split('/').pop();
256+
const status = db.data[user][urlGameId]?.status;
257+
if (status && DONE_STATUSES.includes(status)) {
258+
console.log(`Already ${status}, skipping:`, url);
253259
if (cfg.time) console.timeEnd('claim game');
254260
continue;
255261
}

0 commit comments

Comments
 (0)