Archived
visualizzazioni video tracciate
This commit is contained in:
+52
-6
@@ -1,22 +1,68 @@
|
|||||||
const express = require('express');
|
const express = require('express');
|
||||||
const bodyParser = require('body-parser');
|
const bodyParser = require('body-parser');
|
||||||
const low = require('lowdb');
|
const low = require('lowdb');
|
||||||
|
const lodashId = require('lodash-id');
|
||||||
const FileAsync = require('lowdb/adapters/FileAsync');
|
const FileAsync = require('lowdb/adapters/FileAsync');
|
||||||
const app = express(); // app is an instance of express
|
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.urlencoded({ extended: false })) // parse application/x-www-form-urlencoded
|
||||||
app.use(bodyParser.json()) // parse application/json
|
app.use(bodyParser.json()) // parse application/json
|
||||||
app.use(express.static(__dirname + '/build')); // serve static build site
|
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
|
// Create database instance and start server
|
||||||
// const adapter = new FileAsync(__dirname + '/db.json');
|
// 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 => {
|
.then(db => {
|
||||||
|
db._.mixin(lodashId);
|
||||||
// DATABASE ROUTES
|
// 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
|
// GET /videolog
|
||||||
app.get('/videolog', (req, res) => {
|
app.get('/videolog', (req, res) => {
|
||||||
const post = db
|
const post = db
|
||||||
@@ -31,9 +77,9 @@ low(new FileAsync(__dirname + '/db.json'))
|
|||||||
db.get('videos')
|
db.get('videos')
|
||||||
.push(req.body)
|
.push(req.body)
|
||||||
.last()
|
.last()
|
||||||
.update('timesWatched', n => n + 1 )
|
//.update('timesWatched', n => n + 1 )
|
||||||
.write()
|
.write()
|
||||||
.then(post => res.send(post)); // non funziona minimamente lol
|
.then(post => res.send(post)); //
|
||||||
});
|
});
|
||||||
|
|
||||||
// Set db default values
|
// Set db default values
|
||||||
|
|||||||
Generated
+5
@@ -8228,6 +8228,11 @@
|
|||||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz",
|
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz",
|
||||||
"integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg=="
|
"integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg=="
|
||||||
},
|
},
|
||||||
|
"lodash-id": {
|
||||||
|
"version": "0.14.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/lodash-id/-/lodash-id-0.14.0.tgz",
|
||||||
|
"integrity": "sha1-uvSJNOVDobXWNG+MhGmLGoyAOJY="
|
||||||
|
},
|
||||||
"lodash._reinterpolate": {
|
"lodash._reinterpolate": {
|
||||||
"version": "3.0.0",
|
"version": "3.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/lodash._reinterpolate/-/lodash._reinterpolate-3.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/lodash._reinterpolate/-/lodash._reinterpolate-3.0.0.tgz",
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
"body-parser": "^1.18.3",
|
"body-parser": "^1.18.3",
|
||||||
"bootstrap": "^4.1.3",
|
"bootstrap": "^4.1.3",
|
||||||
"express": "^4.16.4",
|
"express": "^4.16.4",
|
||||||
|
"lodash-id": "^0.14.0",
|
||||||
"lowdb": "^1.0.0",
|
"lowdb": "^1.0.0",
|
||||||
"react": "^16.6.1",
|
"react": "^16.6.1",
|
||||||
"react-app-polyfill": "^0.1.3",
|
"react-app-polyfill": "^0.1.3",
|
||||||
|
|||||||
+10
-2
@@ -1,5 +1,6 @@
|
|||||||
import React, { Component } from 'react'; // eslint-disable-line no-unused-vars
|
import React, { Component } from 'react'; // eslint-disable-line no-unused-vars
|
||||||
import YouTube from 'react-youtube'; // eslint-disable-line no-unused-vars
|
import YouTube from 'react-youtube'; // eslint-disable-line no-unused-vars
|
||||||
|
import axios from 'axios';
|
||||||
/* eslint no-console: ["error", { allow: ["info", "error", "warn"] }] */
|
/* eslint no-console: ["error", { allow: ["info", "error", "warn"] }] */
|
||||||
|
|
||||||
class VideoPlayer extends Component {
|
class VideoPlayer extends Component {
|
||||||
@@ -92,7 +93,6 @@ class VideoPlayer extends Component {
|
|||||||
}
|
}
|
||||||
}, 500);
|
}, 500);
|
||||||
this.setState({ outsideReject2: reject });
|
this.setState({ outsideReject2: reject });
|
||||||
|
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
this.state.promise2.then(msg => {
|
this.state.promise2.then(msg => {
|
||||||
@@ -111,8 +111,16 @@ class VideoPlayer extends Component {
|
|||||||
this.state.promise1
|
this.state.promise1
|
||||||
.then(
|
.then(
|
||||||
risultato => {
|
risultato => {
|
||||||
console.info(risultato);
|
//console.info(risultato);
|
||||||
// post request to local db
|
// post request to local db
|
||||||
|
axios
|
||||||
|
.post('http://localhost:8000/test', {
|
||||||
|
id: risultato.toString()
|
||||||
|
})
|
||||||
|
.then(
|
||||||
|
response => console.info(response.data),
|
||||||
|
error => console.info(error)
|
||||||
|
);
|
||||||
// local storage logic for recent reccomender
|
// local storage logic for recent reccomender
|
||||||
clearInterval(timerId1);
|
clearInterval(timerId1);
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user