mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-13 15:06:59 +03:00
Prevented db errors from crashing the server.
This commit is contained in:
15
index.js
15
index.js
@@ -190,12 +190,19 @@ app.get('/api/postVideoSponsorTimes', async function (req, res) {
|
|||||||
|
|
||||||
if (row == null) {
|
if (row == null) {
|
||||||
//not a duplicate, execute query
|
//not a duplicate, execute query
|
||||||
db.prepare("INSERT INTO sponsorTimes VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)").run(videoID, startTime, endTime, startingVotes, UUID, userID, timeSubmitted, 0, shadowBanned);
|
db.prepare("INSERT INTO sponsorTimes VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)").run(videoID, startTime, endTime, startingVotes, UUID, userID, timeSubmitted, 0, shadowBanned, function (err) {
|
||||||
|
if (err) {
|
||||||
|
//a DB change probably occurred, respond as if it is a duplicate
|
||||||
|
res.sendStatus(409);
|
||||||
|
|
||||||
//add to private db as well
|
console.log("Error when putting sponsorTime in the DB: " + videoID + ", " + startTime + ", " + "endTime" + ", " + userID);
|
||||||
privateDB.prepare("INSERT INTO sponsorTimes VALUES(?, ?, ?)").run(videoID, hashedIP, timeSubmitted);
|
} else {
|
||||||
|
//add to private db as well
|
||||||
|
privateDB.prepare("INSERT INTO sponsorTimes VALUES(?, ?, ?)").run(videoID, hashedIP, timeSubmitted);
|
||||||
|
|
||||||
res.sendStatus(200);
|
res.sendStatus(200);
|
||||||
|
}
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
res.sendStatus(409);
|
res.sendStatus(409);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user