Added post function and fixed database download function

This commit is contained in:
Ajay Ramachandran 2019-07-09 14:42:59 -04:00
parent ca479bc2f7
commit 7bf99e35fe
2 changed files with 25 additions and 4 deletions

View file

@ -4,6 +4,9 @@ var http = require('http');
// Create a service (the app object is just a callback).
var app = express();
//uuid service
var uuidv1 = require('uuid/v1');
//load database
var sqlite3 = require('sqlite3').verbose();
var db = new sqlite3.Database('./databases/sponsorTimes.db');
@ -35,10 +38,27 @@ app.get('/api/get', function (req, res) {
});
//add the post function
app.get('/api/get', function (req, res) {
app.get('/api/post', function (req, res) {
let videoID = req.query.videoID;
let startTime = req.query.startTime;
let endTime = req.query.endTime;
if (typeof videoID != 'string' || startTime == undefined || endTime == undefined) {
//invalid request
res.sendStatus(400);
return;
}
startTime = parseInt(startTime);
endTime = parseInt(endTime);
let UUID = uuidv1();
db.prepare("INSERT INTO sponsorTimes VALUES(?, ?, ?, ?)").run(videoID, startTime, endTime, UUID);
res.sendStatus(200);
});
app.get('/downloadDatabase', function (req, res) {
res.sendFile("./databases/sponsorTimes.db");
app.get('/database.db', function (req, res) {
res.sendFile("./databases/sponsorTimes.db", { root: __dirname });
});

View file

@ -12,6 +12,7 @@
"dependencies": {
"express": "^4.17.1",
"http": "0.0.0",
"sqlite3": "^4.0.9"
"sqlite3": "^4.0.9",
"uuid": "^3.3.2"
}
}