From 514557e183a20b72909b21d0a3cbbbc0665b364c Mon Sep 17 00:00:00 2001 From: ssyyhhrr <44934807+ssyyhhrr@users.noreply.github.com> Date: Fri, 30 Dec 2022 10:03:34 +0000 Subject: [PATCH] stats.json Fix --- .gitignore | 1 - app.js | 17 ++++------------- assets/stats.json | 1 + 3 files changed, 5 insertions(+), 14 deletions(-) create mode 100644 assets/stats.json diff --git a/.gitignore b/.gitignore index 02d6b0e..8b2fe56 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ node_modules driver.txt drivers.json -stats.json .idea \ No newline at end of file diff --git a/app.js b/app.js index 0ad51c8..8ca6af8 100644 --- a/app.js +++ b/app.js @@ -83,13 +83,8 @@ schedule.scheduleJob("0 0 * * *", async () => { throw "Ergast API is unreachable and the drivers.json cache has not been built. Please try again when the Ergast API is online." } }) - let statsFile - if (fs.existsSync(statsPath)) { - let rawStatsFile = fs.readFileSync(statsPath) - statsFile = JSON.parse(rawStatsFile) - } else { - statsFile = {} - } + let rawStatsFile = fs.readFileSync(statsPath) + let statsFile = JSON.parse(rawStatsFile) let date = dayjs.format("YYYY-MM-DD") statsFile[date] = stats let newStatsFile = JSON.stringify(statsFile) @@ -196,12 +191,8 @@ function server() { }) app.get("/stats", (req, res) => { - if (fs.existsSync(statsPath)) { - let rawStatsFile = fs.readFileSync(statsPath) - res.json(JSON.parse(rawStatsFile)) - } else { - res.json(stats) - } + let rawStatsFile = fs.readFileSync(statsPath) + res.json(JSON.parse(rawStatsFile)) }) app.get("/winner", (req, res) => { diff --git a/assets/stats.json b/assets/stats.json new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ b/assets/stats.json @@ -0,0 +1 @@ +{} \ No newline at end of file