diff --git a/apikey b/apikey index 8b9e5dd..761981b 100644 --- a/apikey +++ b/apikey @@ -1 +1 @@ -AIzaSyA21Odw9UdfiOJnxvA_eDfOW0OxuUfHKig \ No newline at end of file +'AIzaSyBYSHhu7AwZqT1JK3x4G8Yzs7iRqoS_QUg' \ No newline at end of file diff --git a/dev.js b/dev.js new file mode 100644 index 0000000..b607da5 --- /dev/null +++ b/dev.js @@ -0,0 +1,87 @@ +process.env['NODE_ENV'] = 'production'; +const express = require('express'); +const compression = require('compression') +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 + +app.use(compression()); // enables gzip compression +app.use(bodyParser.urlencoded({ extended: false })) // parse application/x-www-form-urlencoded +app.use(bodyParser.json()) // parse application/json + + +// Create database instance and start server +// const adapter = new FileAsync(__dirname + '/db.json'); +low(new FileAsync(__dirname + '/db.json')) // production + .then(db => { + db._.mixin(lodashId); + // DATABASE ROUTES + + // ============== + + app.post('/test', (req, res) => { + // "reason": { + // "fitali": req.body.reason.toString() === "fvitali" ? 1:0, + // "": req.body.reason.toString() === "" ? 1:0, + // "": req.body.reason.toString() === "" ? 1:0, + // } + // try { + // let test = table.updateById(req.body.id, { }) + // } + // catch(e) { + // } + res.send(req.body); + }); + + // ============== + + // GET /globpop + app.get('/globpop', (req, res) => { + req.query.id ? res.send(req.query.id) : res.status(400).send('Bad Request'); + }); + + // OPTIONS /videotrack + app.options('/videotrack', (req, res) => { + res.set({ + 'Access-Control-Allow-Origin': '*', + 'Access-Control-Allow-Methods': 'POST, GET, OPTIONS', + 'Access-Control-Allow-Headers': 'Content-Type', + 'Access-Control-Max-Age': 600 + }) + res.status(200).end(); + }) + + // GET /videotrack + app.get('/videotrack', (req, res) => { + const videos = db.get('videos'); + req.query.id ? res.send(videos.getById(req.query.id).value()) : res.send(videos.value()) + }); + + // POST /videotrack + app.post('/videotrack', (req, res) => { + const videos = db.get('videos'); + const row = videos.getById(req.body.id); + if (row.value()) { + row + .update('timesWatched', (n) => ++n) + .update('lastWatched', () => new Date().toISOString()) + .write() + .then(output => res.send(output)) + } else { + let newRow = { + "id": req.body.id.toString(), + "timesWatched": 1, + "lastWatched": new Date().toISOString(), + } + videos.push(newRow).last().write().then(output => res.send(output)) + } + }); + + // Set db default values + return db.defaults({ videos: [] }).write(); + }) + .then(() => { + app.listen(8000, () => console.log('listen on 8000')); // bind to port 8000 as required from specs + }); diff --git a/node-entry.js b/node-entry.js index 8e18cbd..d02724f 100644 --- a/node-entry.js +++ b/node-entry.js @@ -1,5 +1,5 @@ process.env['NODE_ENV'] = 'production'; -process.env.APIKEY = 'AIzaSyA21Odw9UdfiOJnxvA_eDfOW0OxuUfHKig'; +//'AIzaSyBYSHhu7AwZqT1JK3x4G8Yzs7iRqoS_QUg' = 'AIzaSyBYSHhu7AwZqT1JK3x4G8Yzs7iRqoS_QUg'; const express = require('express'); const compression = require('compression') const bodyParser = require('body-parser'); @@ -13,8 +13,8 @@ app.use(bodyParser.urlencoded({ extended: false })) // parse application/x-www-f app.use(bodyParser.json()) // parse application/json -app.get('/a', (req, res) => { -res.send(process.env); +app.get('/a', (req, res) => { + res.send(process.env); }); @@ -26,14 +26,14 @@ low(new FileAsync(__dirname + '/db.json')) // production db._.mixin(lodashId); // DATABASE ROUTES -// ============== + // ============== - app.post('/test',(req,res)=>{ - // "reason": { - // "fitali": req.body.reason.toString() === "fvitali" ? 1:0, - // "": req.body.reason.toString() === "" ? 1:0, - // "": req.body.reason.toString() === "" ? 1:0, - // } + app.post('/test', (req, res) => { + // "reason": { + // "fitali": req.body.reason.toString() === "fvitali" ? 1:0, + // "": req.body.reason.toString() === "" ? 1:0, + // "": req.body.reason.toString() === "" ? 1:0, + // } // try { // let test = table.updateById(req.body.id, { }) // } @@ -42,39 +42,50 @@ low(new FileAsync(__dirname + '/db.json')) // production res.send(req.body); }); -// ============== + // ============== - // GET /videotrack/:id? + // GET /globpop app.get('/globpop', (req, res) => { - 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'); }); - // GET /videotrack/:id? - app.get('/videotrack/:id?', (req, res) => { + // OPTIONS /videotrack + app.options('/videotrack', (req, res) => { + res.set({ + 'Access-Control-Allow-Origin': '*', + 'Access-Control-Allow-Methods': 'POST, GET, OPTIONS', + 'Access-Control-Allow-Headers': 'Content-Type', + 'Access-Control-Max-Age': 600 + }) + res.status(200).end(); + }) + + // GET /videotrack + app.get('/videotrack', (req, res) => { const videos = db.get('videos'); - req.params.id ? res.send(videos.getById(req.params.id).value()) : res.send(videos.value()) + req.query.id ? res.send(videos.getById(req.query.id).value()) : res.send(videos.value()) }); // POST /videotrack app.post('/videotrack', (req, res) => { - const videos = db.get('videos'); - const row = videos.getById(req.body.id); - if(row.value()) { + const videos = db.get('videos'); + const row = videos.getById(req.body.id); + if (row.value()) { row - .update('timesWatched',(n) => ++n) - .update('lastWatched',() => new Date().toISOString()) - .write() - .then(output => res.send(output)) + .update('timesWatched', (n) => ++n) + .update('lastWatched', () => new Date().toISOString()) + .write() + .then(output => res.send(output)) } else { let newRow = { - "id": req.body.id.toString(), + "id": req.body.id.toString(), "timesWatched": 1, "lastWatched": new Date().toISOString(), } videos.push(newRow).last().write().then(output => res.send(output)) } }); - + // Set db default values return db.defaults({ videos: [] }).write(); }) diff --git a/src/App.js b/src/App.js index 021c2d6..3d7aa03 100644 --- a/src/App.js +++ b/src/App.js @@ -61,8 +61,8 @@ static getDerivedStateFromProps(nextProps, prevState) { xs="12" lg={this.state.isInfoToggled ? { span: 5, order: 1 } : { span: 3, order: 1 }} className="p-0 p-sm-0" - style={{ 'overflow': "auto", 'max-height': this.state.playerHeight }} > -
+ style={{ 'overflow': "auto", 'maxHeight': this.state.playerHeight }} > +