refactor[epic-games]: migrate to GraphQL API and modularize authentication logic
This commit refactors epic-games.js to use the GraphQL API instead of the legacy promotions endpoint for retrieving free games. Key architectural improvements include: - Added modular authentication module (device-auths.ts) supporting persistent device auth tokens - Introduces cookie management module (cookie.ts) for persistent session handling - Extracts GraphQL query structures and API endpoints into constants.ts - Implements multiple fallback strategies: device auth login, token exchange, and fallback to standard login - Adds support for both GraphQL and promotions-based game discovery - Streamlines claim process with improved tracking and error handling - Removes legacy selectors and redundant logic Additionally, updates package.json to include TypeScript and reorganizes dependency order for better maintainability.
This commit is contained in:
parent
0d35a5ee85
commit
728b0c734b
6 changed files with 626 additions and 137 deletions
38
src/device-auths.ts
Normal file
38
src/device-auths.ts
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
// Device authentication management for Epic Games
|
||||
// Based on https://github.com/claabs/epicgames-freegames-node
|
||||
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { dataDir } from './util.js';
|
||||
|
||||
const CONFIG_DIR = dataDir('config');
|
||||
const deviceAuthsFilename = path.join(CONFIG_DIR, 'device-auths.json');
|
||||
|
||||
// Ensure config directory exists
|
||||
if (!fs.existsSync(CONFIG_DIR)) {
|
||||
fs.mkdirSync(CONFIG_DIR, { recursive: true });
|
||||
}
|
||||
|
||||
export async function getDeviceAuths() {
|
||||
try {
|
||||
const deviceAuths = JSON.parse(fs.readFileSync(deviceAuthsFilename, 'utf-8'));
|
||||
return deviceAuths;
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
export async function getAccountAuth(account) {
|
||||
const deviceAuths = await getDeviceAuths();
|
||||
return deviceAuths?.[account];
|
||||
}
|
||||
|
||||
export async function writeDeviceAuths(deviceAuths) {
|
||||
fs.writeFileSync(deviceAuthsFilename, JSON.stringify(deviceAuths, null, 2));
|
||||
}
|
||||
|
||||
export async function setAccountAuth(account, accountAuth) {
|
||||
const existingDeviceAuths = (await getDeviceAuths()) ?? {};
|
||||
existingDeviceAuths[account] = accountAuth;
|
||||
await writeDeviceAuths(existingDeviceAuths);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue