Skip to content

Commit 43aa12e

Browse files
committed
V1.5.6
1 parent b7c0aa1 commit 43aa12e

File tree

3 files changed

+43
-39
lines changed

3 files changed

+43
-39
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
Claim [available free game promotions](https://www.epicgames.com/store/free-games) from the Epic Games Store.
66

77
## Requirements
8-
* [DeviceAuthGenerator](https://github.com/xMistt/DeviceAuthGenerator/releases)
8+
* [DeviceAuthGenerator](https://github.com/jackblk/DeviceAuthGenerator/releases)
99
* [Git](https://git-scm.com/downloads)
1010
* [Node.js](https://nodejs.org/download/) (with build tools checked)
1111

1212
## Instructions - Quick
1313
0. (Optional) ☆ Star this project :)
1414
1. Download/clone this repository
1515
2. Run `npm install`
16-
3. Generate `data/device_auths.json` (using [DeviceAuthGenerator](https://github.com/xMistt/DeviceAuthGenerator))
16+
3. Generate `data/device_auths.json` (using [DeviceAuthGenerator](https://github.com/jackblk/DeviceAuthGenerator))
1717
4. (Optional) Copy `data/config.example.json` to `data/config.json` and edit it
1818
5. Run `npm start`
1919

@@ -34,6 +34,7 @@ To which I will say, why not? Most of these games are actually outstanding games
3434
## Changelog
3535
### V1.5.6
3636
* Added optional Apprise notifications (#143)
37+
* Improved update checking (#)
3738

3839
### V1.5.5
3940
* Fixed testing (#137)

claimer.js

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,22 @@
11
"use strict";
22

3-
const { "Launcher": EpicGames } = require("epicgames-client");
4-
const { freeGamesPromotions } = require("./src/gamePromotions");
5-
const Logger = require("tracer").console(`${__dirname}/logger.js`);
63
const { writeFile, writeFileSync, existsSync, readFileSync } = require("fs");
7-
8-
const Auths = require(`${__dirname}/data/device_auths.json`);
9-
const getLatestVersion = require("./src/checkUpdate.js");
104
if (!existsSync(`${__dirname}/data/config.json`)) {
115
writeFileSync(`${__dirname}/data/config.json`, readFileSync(`${__dirname}/data/config.example.json`));
126
}
13-
const Config = require(`${__dirname}/data/config.json`);
14-
const Fork = require("child_process");
157
if (!existsSync(`${__dirname}/data/history.json`)) {
16-
try {
17-
writeFileSync(`${__dirname}/data/history.json`, "{}");
18-
} catch (err) {
19-
Logger.error(`Failed to generate data/history.json file (${err})`);
20-
process.exit(1);
21-
}
8+
writeFileSync(`${__dirname}/data/history.json`, "{}");
229
}
10+
11+
const { "Launcher": EpicGames } = require("epicgames-client");
12+
const { freeGamesPromotions } = require(`${__dirname}/src/gamePromotions`);
13+
const { latestVersion } = require(`${__dirname}/src/latestVersion.js`);
14+
const Auths = require(`${__dirname}/data/device_auths.json`);
15+
const Config = require(`${__dirname}/data/config.json`);
16+
const Fork = require("child_process");
2317
const History = require(`${__dirname}/data/history.json`);
24-
const Package = require("./package.json");
18+
const Logger = require("tracer").console(`${__dirname}/logger.js`);
19+
const Package = require(`${__dirname}/package.json`);
2520

2621
function appriseNotify(appriseUrl, notificationMessages) {
2722
if (!appriseUrl || notificationMessages.length === 0) {
@@ -39,7 +34,7 @@ function appriseNotify(appriseUrl, notificationMessages) {
3934
appriseUrl,
4035
]);
4136

42-
let output = s.stdout ? s.stdout.toString() : "ERROR: maybe apprise not found";
37+
let output = s.stdout ? s.stdout.toString() : "ERROR: Maybe apprise not found?";
4338
if (output && output.includes("ERROR")) {
4439
Logger.error(`Failed to send push notification (${output})`);
4540
} else if (output) {
@@ -65,16 +60,17 @@ function sleep(delay) {
6560
let { options, delay, loop, appriseUrl } = Config;
6661

6762
do {
68-
Logger.info(`Epicgames Freebies Claimer ${Package.version}`);
69-
let latestVersion = await getLatestVersion().catch((err) => {
63+
Logger.info(`Epicgames Freebies Claimer (${Package.version}) by ${Package.author.name || Package.author}`);
64+
65+
let latest = await latestVersion().catch((err) => {
7066
Logger.error(`Failed to check for updates (${err})`);
7167
});
72-
if (latestVersion && latestVersion !== Package.version) {
73-
Logger.warn(`Latest release version ${latestVersion} available: ${Package.url}`);
68+
69+
if (latest && latest !== Package.version) {
70+
Logger.warn(`There is a new release available (${latest}): ${Package.url}`);
7471
}
7572

7673
let notificationMessages = [];
77-
7874
for (let email in Auths) {
7975
let { country } = Auths[email];
8076
let claimedPromos = History[email] || [];
@@ -83,6 +79,7 @@ function sleep(delay) {
8379
let rememberDevicesPath = `${__dirname}/data/device_auths.json`;
8480
let clientOptions = { email, ...options, rememberDevicesPath };
8581
let client = new EpicGames(clientOptions);
82+
8683
if (!await client.init()) {
8784
let errMess = "Error while initialize process.";
8885
notificationMessages.push(errMess);
Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,64 @@
11
"use strict";
22

3-
const https = require("https");
3+
const HTTPS = require("https");
44

55
// taken & modified from https://stackoverflow.com/a/38543075/8068153
66
function httpsRequest(params, postData) {
7-
return new Promise((resolve, reject) => {
8-
let req = https.request(params, (res) => {
7+
return new Promise((res, rej) => {
8+
let req = HTTPS.request(params, (response) => {
99
// reject on bad status
10-
if (res.statusCode < 200 || res.statusCode >= 300) {
11-
reject(new Error(`statusCode=${res.statusCode}`));
10+
if (response.statusCode < 200 || response.statusCode >= 300) {
11+
rej(new Error(`HTTP Error ${response.statusCode}`));
1212
}
13+
1314
// cumulate data
1415
let body = [];
15-
res.on("data", (chunk) => {
16+
response.on("data", (chunk) => {
1617
body.push(chunk);
1718
});
19+
1820
// resolve on end
19-
res.on("end", () => {
21+
response.on("end", () => {
2022
try {
2123
body = JSON.parse(Buffer.concat(body).toString());
2224
// Get latest release, remove "v" prefix.
23-
return resolve(body[0].tag_name.substring(1));
25+
return res(body[0].tag_name.substring(1));
2426
} catch (e) {
25-
return reject(e);
27+
return rej(e);
2628
}
2729
});
2830
});
31+
2932
// reject on request error
3033
req.on("error", (err) => {
3134
// This is not a "Second reject", just a different sort of failure
32-
reject(err);
35+
rej(err);
3336
});
37+
3438
// Sometimes github actions network will have hiccup...
3539
// https://github.com/Revadike/epicgames-freebies-claimer/issues/152
3640
req.on("timeout", () => {
3741
req.destroy();
38-
reject(new Error("Request timeout"));
42+
rej(new Error("Request timeout"));
3943
});
44+
4045
if (postData) {
4146
req.write(postData);
4247
}
48+
4349
// IMPORTANT
4450
req.end();
4551
});
4652
}
4753

48-
module.exports = function latestRelease() {
49-
let options = {
54+
function latestVersion() {
55+
return httpsRequest({
5056
"host": "api.github.com",
5157
"path": "/repos/Revadike/epicgames-freebies-claimer/releases",
5258
"method": "GET",
5359
"headers": { "user-agent": "EFC" },
5460
"timeout": 3000,
61+
});
62+
}
5563

56-
};
57-
return httpsRequest(options);
58-
};
64+
module.exports = { latestVersion };

0 commit comments

Comments
 (0)