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