Archived
videotrack
This commit is contained in:
+29
-1
@@ -43,9 +43,22 @@ low(new FileAsync(__dirname + '/db.json')) // production
|
|||||||
});
|
});
|
||||||
|
|
||||||
// ==============
|
// ==============
|
||||||
|
// OPTIONS /globpop
|
||||||
|
app.options('/globpop', (req, res) => {
|
||||||
|
res.set({
|
||||||
|
'Access-Control-Allow-Origin': '*',
|
||||||
|
'Access-Control-Allow-Methods': ' GET, OPTIONS',
|
||||||
|
'Access-Control-Allow-Headers': 'Content-Type',
|
||||||
|
'Access-Control-Max-Age': 600
|
||||||
|
})
|
||||||
|
res.status(200).end();
|
||||||
|
})
|
||||||
|
|
||||||
// GET /globpop
|
// GET /globpop
|
||||||
app.get('/globpop', (req, res) => {
|
app.get('/globpop', (req, res) => {
|
||||||
|
res.set({
|
||||||
|
'Access-Control-Allow-Origin': '*'
|
||||||
|
});
|
||||||
req.query.id ? res.send(req.query.id) : res.status(400).send('Bad Request');
|
req.query.id ? res.send(req.query.id) : res.status(400).send('Bad Request');
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -74,19 +87,34 @@ low(new FileAsync(__dirname + '/db.json')) // production
|
|||||||
res.set({
|
res.set({
|
||||||
'Access-Control-Allow-Origin': '*'
|
'Access-Control-Allow-Origin': '*'
|
||||||
});
|
});
|
||||||
|
let setReason = function (reason='Starter', oldObj = {}) {
|
||||||
|
if (oldObj.hasOwnProperty(reason)) {
|
||||||
|
++oldObj[reason];
|
||||||
|
return oldObj;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Object.defineProperty(oldObj,
|
||||||
|
reason, { value: 1, enumerable: true, writable: true }
|
||||||
|
)
|
||||||
|
return oldObj;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const videos = db.get('videos');
|
const videos = db.get('videos');
|
||||||
const row = videos.getById(req.body.id);
|
const row = videos.getById(req.body.id);
|
||||||
if (row.value()) {
|
if (row.value()) {
|
||||||
row
|
row
|
||||||
.update('timesWatched', (n) => ++n)
|
.update('timesWatched', (n) => ++n)
|
||||||
.update('lastWatched', () => new Date().toISOString())
|
.update('lastWatched', () => new Date().toISOString())
|
||||||
|
.update('reason', (n) => setReason(req.body.reason, n))
|
||||||
.write()
|
.write()
|
||||||
.then(output => res.send(output))
|
.then(output => res.send(200, output))
|
||||||
} else {
|
} else {
|
||||||
let newRow = {
|
let newRow = {
|
||||||
"id": req.body.id.toString(),
|
"id": req.body.id.toString(),
|
||||||
"timesWatched": 1,
|
"timesWatched": 1,
|
||||||
"lastWatched": new Date().toISOString(),
|
"lastWatched": new Date().toISOString(),
|
||||||
|
"reason": setReason(req.body.reason)
|
||||||
}
|
}
|
||||||
videos.push(newRow).last().write().then(output => res.send(200, output))
|
videos.push(newRow).last().write().then(output => res.send(200, output))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user