stats.json Fix

This commit is contained in:
ssyyhhrr
2022-12-30 10:03:34 +00:00
parent 1c41b66b7e
commit 514557e183
3 changed files with 5 additions and 14 deletions

1
.gitignore vendored
View File

@@ -1,5 +1,4 @@
node_modules
driver.txt
drivers.json
stats.json
.idea

17
app.js
View File

@@ -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) => {

1
assets/stats.json Normal file
View File

@@ -0,0 +1 @@
{}