Archived
RelPopLoc
This commit is contained in:
+24
-12
@@ -87,17 +87,29 @@ low(new FileAsync(__dirname + '/db.json')) // production
|
||||
res.set({
|
||||
'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;
|
||||
let setReason = function (reason='Starter', oldArr = [], prevId) {
|
||||
// if (oldObj.hasOwnProperty(reason, prevId)) {
|
||||
// ++oldObj[reason];
|
||||
// return oldObj;
|
||||
// }
|
||||
// else {
|
||||
// Object.defineProperty(oldObj,
|
||||
// reason, { value: 1, enumerable: true, writable: true }
|
||||
// )
|
||||
// return oldObj;
|
||||
// }
|
||||
let j=oldArr.findIndex(el=>el.prevId===prevId && el.reason===reason)
|
||||
if (j>=0) {++oldArr[j].timesWatched; return oldArr}
|
||||
else {
|
||||
let tmp={
|
||||
prevId,
|
||||
reason,
|
||||
timesWatched:1
|
||||
}
|
||||
oldArr.push(tmp)
|
||||
return oldArr
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const videos = db.get('videos');
|
||||
@@ -106,7 +118,7 @@ low(new FileAsync(__dirname + '/db.json')) // production
|
||||
row
|
||||
.update('timesWatched', (n) => ++n)
|
||||
.update('lastWatched', () => new Date().toISOString())
|
||||
.update('reason', (n) => setReason(req.body.reason, n))
|
||||
.update('reason', (n) => setReason(req.body.reason, n, req.body.id))
|
||||
.write()
|
||||
.then(output => res.send(200, output))
|
||||
} else {
|
||||
@@ -114,7 +126,7 @@ low(new FileAsync(__dirname + '/db.json')) // production
|
||||
"id": req.body.id.toString(),
|
||||
"timesWatched": 1,
|
||||
"lastWatched": new Date().toISOString(),
|
||||
"reason": setReason(req.body.reason)
|
||||
"reason": setReason(req.body.reason,[],req.body.id)
|
||||
}
|
||||
videos.push(newRow).last().write().then(output => res.send(200, output))
|
||||
}
|
||||
|
||||
+2
-1
@@ -90,7 +90,8 @@ class VideoPlayer extends React.Component {
|
||||
axios
|
||||
.post('http://site1854.tw.cs.unibo.it/videotrack', {
|
||||
id: videoIdWatched.toString(),
|
||||
reason: reason || undefined
|
||||
reason: reason || undefined,
|
||||
prevId: localStorage['prevId']
|
||||
})
|
||||
.then(
|
||||
response => console.info(response.data),
|
||||
|
||||
Reference in New Issue
Block a user