Archived
visualizzazioni video tracciate
This commit is contained in:
+52
-6
@@ -1,22 +1,68 @@
|
||||
const express = require('express');
|
||||
const bodyParser = require('body-parser');
|
||||
const low = require('lowdb');
|
||||
const lodashId = require('lodash-id');
|
||||
const FileAsync = require('lowdb/adapters/FileAsync');
|
||||
const app = express(); // app is an instance of express
|
||||
const axios = require('axios');
|
||||
|
||||
app.use(bodyParser.urlencoded({ extended: false })) // parse application/x-www-form-urlencoded
|
||||
app.use(bodyParser.json()) // parse application/json
|
||||
app.use(express.static(__dirname + '/build')); // serve static build site
|
||||
app.post('/test',(req,res)=>{
|
||||
res.send(req.body);
|
||||
})
|
||||
|
||||
|
||||
app.get('/test/:id',(req,res) =>{
|
||||
axios.post('http://localhost:8000/test', {
|
||||
"id": req.params.id.toString(),
|
||||
"reason": req.query.reason.toString()
|
||||
}).then(response => res.send(response.data), error => console.log(error))
|
||||
});
|
||||
|
||||
// Create database instance and start server
|
||||
// const adapter = new FileAsync(__dirname + '/db.json');
|
||||
low(new FileAsync(__dirname + '/db.json'))
|
||||
low(new FileAsync(__dirname + '/db.json')) // production
|
||||
// low(new FileAsync('/tmp/db.json')) // dev
|
||||
.then(db => {
|
||||
db._.mixin(lodashId);
|
||||
// DATABASE ROUTES
|
||||
|
||||
// ==============
|
||||
|
||||
app.post('/test',(req,res)=>{
|
||||
//console.log(req.body);
|
||||
const table = db.get('videos');
|
||||
let row = table.getById(req.body.id);
|
||||
if(row.value()) {
|
||||
row
|
||||
.update('timesWatched',(n) => ++n)
|
||||
.update('lastWatched',() => new Date().toISOString())
|
||||
.write()
|
||||
.then(final => res.send(final))
|
||||
} else {
|
||||
// "reason": {
|
||||
// "fitali": req.body.reason.toString() === "fvitali" ? 1:0,
|
||||
// "": req.body.reason.toString() === "" ? 1:0,
|
||||
// "": req.body.reason.toString() === "" ? 1:0,
|
||||
// }
|
||||
let post = {
|
||||
"id": req.body.id.toString(),
|
||||
"timesWatched": 1,
|
||||
"lastWatched": new Date().toISOString(),
|
||||
}
|
||||
table.push(post).last().write().then(final => res.send(final))
|
||||
}
|
||||
|
||||
// try {
|
||||
// let test = table.updateById(req.body.id, { })
|
||||
// }
|
||||
// catch(e) {
|
||||
|
||||
// }
|
||||
|
||||
});
|
||||
|
||||
// ==============
|
||||
|
||||
// GET /videolog
|
||||
app.get('/videolog', (req, res) => {
|
||||
const post = db
|
||||
@@ -31,9 +77,9 @@ low(new FileAsync(__dirname + '/db.json'))
|
||||
db.get('videos')
|
||||
.push(req.body)
|
||||
.last()
|
||||
.update('timesWatched', n => n + 1 )
|
||||
//.update('timesWatched', n => n + 1 )
|
||||
.write()
|
||||
.then(post => res.send(post)); // non funziona minimamente lol
|
||||
.then(post => res.send(post)); //
|
||||
});
|
||||
|
||||
// Set db default values
|
||||
|
||||
Reference in New Issue
Block a user