Skip to content

Commit

Permalink
Fix repairing config, advancedconfig & data.json not working
Browse files Browse the repository at this point in the history
  • Loading branch information
3urobeat committed May 6, 2023
1 parent 7a69ff4 commit 46a6120
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
14 changes: 7 additions & 7 deletions src/dataManager/dataImport.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Created Date: 09.07.2021 16:26:00
* Author: 3urobeat
*
* Last Modified: 05.05.2023 14:38:24
* Last Modified: 06.05.2023 11:56:55
* Modified By: 3urobeat
*
* Copyright (c) 2021 3urobeat <https://github.com/HerrEurobeat>
Expand Down Expand Up @@ -71,8 +71,8 @@ DataManager.prototype._importFromDisk = function() {
logger("warn", "'data.json' seems to have lost it's data/is corrupted. Trying to restore from backup...", true);

// Check if cache.json has a backup of config.json and try to restore it. If not then pull the file directly from GitHub.
if (_this.cache.datajson) _this._restoreBackup("data.json", srcdir + "/data/data.json", _this.cache.datajson, "https://raw.githubusercontent.com/HerrEurobeat/steam-comment-service-bot/master/src/data/data.json", resolve);
else _this._pullNewFile("data.json", srcdir + "/data/data.json", resolve);
if (_this.cachefile.datajson) _this._restoreBackup("data.json", srcdir + "/data/data.json", _this.cachefile.datajson, "https://raw.githubusercontent.com/HerrEurobeat/steam-comment-service-bot/master/src/data/data.json", resolve);
else _this._pullNewFile("data.json", "./src/data/data.json", resolve);
}
}
});
Expand Down Expand Up @@ -107,8 +107,8 @@ DataManager.prototype._importFromDisk = function() {
// Wait restoreTimeout ms if set by firststart check from above
setTimeout(() => {
// Check if cache.json has a backup of config.json and try to restore it. If not then pull the file directly from GitHub.
if (_this.cache.configjson) _this._restoreBackup("config.json", srcdir + "/../config.json", _this.cache.configjson, "https://raw.githubusercontent.com/HerrEurobeat/steam-comment-service-bot/master/config.json", resolve);
else _this._pullNewFile("config.json", srcdir + "/../config.json", resolve);
if (_this.cachefile.configjson) _this._restoreBackup("config.json", srcdir + "/../config.json", _this.cachefile.configjson, "https://raw.githubusercontent.com/HerrEurobeat/steam-comment-service-bot/master/config.json", resolve);
else _this._pullNewFile("config.json", "./config.json", resolve);
}, restoreTimeout);
}
}
Expand All @@ -125,8 +125,8 @@ DataManager.prototype._importFromDisk = function() {
logger("warn", "advancedconfig.json seems to have lost it's data/is corrupted. Trying to restore from backup...", true);

// Check if cache.json has a backup of config.json and try to restore it. If not then pull the file directly from GitHub.
if (_this.cache.advancedconfigjson) _this._restoreBackup("advancedconfig.json", srcdir + "/../advancedconfig.json", _this.cache.advancedconfigjson, "https://raw.githubusercontent.com/HerrEurobeat/steam-comment-service-bot/master/advancedconfig.json", resolve);
else _this._pullNewFile("advancedconfig.json", srcdir + "/../advancedconfig.json", resolve);
if (_this.cachefile.advancedconfigjson) _this._restoreBackup("advancedconfig.json", srcdir + "/../advancedconfig.json", _this.cachefile.advancedconfigjson, "https://raw.githubusercontent.com/HerrEurobeat/steam-comment-service-bot/master/advancedconfig.json", resolve);
else _this._pullNewFile("advancedconfig.json", "./advancedconfig.json", resolve);
}
}
});
Expand Down
4 changes: 2 additions & 2 deletions src/dataManager/dataManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Created Date: 21.03.2023 22:34:51
* Author: 3urobeat
*
* Last Modified: 01.05.2023 20:45:34
* Last Modified: 06.05.2023 12:09:01
* Modified By: 3urobeat
*
* Copyright (c) 2023 3urobeat <https://github.com/HerrEurobeat>
Expand Down Expand Up @@ -135,7 +135,7 @@ DataManager.prototype._restoreBackup = function(name, filepath, cacheentry, onli
/**
* Internal: Helper function to pull new file from GitHub
*/
DataManager.prototype._pullNewFile = function(name, filepath, resolve) {}; // eslint-disable-line
DataManager.prototype._pullNewFile = async function(name, filepath, resolve) {}; // eslint-disable-line


// Export our freshly baked bread
Expand Down
9 changes: 5 additions & 4 deletions src/dataManager/helpers/repairFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Created Date: 22.03.2023 12:35:01
* Author: 3urobeat
*
* Last Modified: 29.03.2023 12:47:09
* Last Modified: 06.05.2023 12:09:48
* Modified By: 3urobeat
*
* Copyright (c) 2023 3urobeat <https://github.com/HerrEurobeat>
Expand Down Expand Up @@ -75,15 +75,16 @@ DataManager.prototype._restoreBackup = function(name, filepath, cacheentry, onli
/**
* Internal: Helper function to pull new file from GitHub
*/
DataManager.prototype._pullNewFile = function(name, filepath, resolve) {
DataManager.prototype._pullNewFile = async function(name, filepath, resolve) {
logger("warn", "Backup seems to be broken/not available! Pulling file from GitHub...", true);

let file = this.checkAndGetFile(filepath, logger, true, true);
let file = await this.checkAndGetFile(filepath, logger, true, true);
if (!file) return;

// Only tell user to reconfigure config.json
if (name == "config.json") logger("info", `Successfully pulled new ${name} from GitHub. Please configure it again!\n`, true);
else logger("info", `Successfully pulled new ${name} from GitHub.\n`, true);

resolve(require(filepath));
// Hack the path together: Take the srcdir path as we otherwise would start here, go back a level and append the filepath. filepath needs to start at project root level so that checkAndGetFile() works so we need to work around it here.
resolve(require(`${srcdir}/../${filepath}`));
};

0 comments on commit 46a6120

Please sign in to comment.