Archived
commit prepotente
This commit is contained in:
+7
-3
@@ -1,4 +1,4 @@
|
||||
process.env['NODE_ENV'] = 'development';
|
||||
process.env['NODE_ENV'] = 'production';
|
||||
process.env.APIKEY = 'AIzaSyA21Odw9UdfiOJnxvA_eDfOW0OxuUfHKig';
|
||||
const express = require('express');
|
||||
const compression = require('compression')
|
||||
@@ -11,7 +11,6 @@ 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
|
||||
app.use(express.static(__dirname + '/build')); // serve static build site
|
||||
|
||||
|
||||
app.get('/a', (req, res) => {
|
||||
@@ -23,7 +22,6 @@ res.send(process.env);
|
||||
// Create database instance and start server
|
||||
// const adapter = 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
|
||||
@@ -46,6 +44,11 @@ low(new FileAsync(__dirname + '/db.json')) // production
|
||||
|
||||
// ==============
|
||||
|
||||
// GET /videotrack/:id?
|
||||
app.get('/globpop', (req, res) => {
|
||||
req.query.id ? res.send(req.query.id):res.status(400).send('Bad Request');
|
||||
});
|
||||
|
||||
// GET /videotrack/:id?
|
||||
app.get('/videotrack/:id?', (req, res) => {
|
||||
const videos = db.get('videos');
|
||||
@@ -76,5 +79,6 @@ low(new FileAsync(__dirname + '/db.json')) // production
|
||||
return db.defaults({ videos: [] }).write();
|
||||
})
|
||||
.then(() => {
|
||||
app.use(express.static(__dirname + '/build')); // serve static build site
|
||||
app.listen(8000, () => console.log('listen on 8000')); // bind to port 8000 as required from specs
|
||||
});
|
||||
|
||||
+2
-2
@@ -17,7 +17,7 @@ class App extends React.Component {
|
||||
navHeight: null,
|
||||
blackbgHeight: null,
|
||||
isInfoToggled: false,
|
||||
videoId: localStorage['lastId']?localStorage['lastId']:'0J2QdDbelmY'
|
||||
videoId: localStorage['lastId']
|
||||
};
|
||||
|
||||
// componentDidMount(){
|
||||
@@ -79,7 +79,7 @@ static getDerivedStateFromProps(nextProps, prevState) {
|
||||
</Collapse>
|
||||
</Col>
|
||||
</ReactHeight>
|
||||
<Row style={{ "max-height": `calc(98vh - ${this.state.blackbgHeight}px - ${this.state.navHeight}px)` }} className='mt-1 downSection'>
|
||||
<Row style={{ "max-height": `calc(90vh - ${this.state.blackbgHeight}px )` }} className='mt-1 downSection'>
|
||||
<Switch>
|
||||
<Route exact path='/' component={VideoList} />
|
||||
<Route path={["/video/:id", "/search/:query"]} component={Suggestion} />
|
||||
|
||||
+12
-7
@@ -7,12 +7,15 @@ import { withRouter } from 'react-router-dom';
|
||||
class VideoPlayer extends React.Component {
|
||||
state = {
|
||||
opt: {
|
||||
height: '390',
|
||||
width: '640',
|
||||
// height: '390',
|
||||
// width: '640',
|
||||
playerVars: {
|
||||
// https://developers.google.com/youtube/player_parameters
|
||||
autoplay: 0,
|
||||
modestbranding: 1
|
||||
modestbranding: 1,
|
||||
fs: 0,
|
||||
iv_load_policy:3,
|
||||
rel: 0
|
||||
}
|
||||
},
|
||||
promise1: null,
|
||||
@@ -91,10 +94,12 @@ class VideoPlayer extends React.Component {
|
||||
error => console.info(error, videoIdWatched.toString())
|
||||
);
|
||||
// local storage logic for recent reccomender
|
||||
// let temp=localStorage.getItem('lastWatched');
|
||||
// temp.push({id: videoIdWatched.toString(), date: new Date})
|
||||
|
||||
|
||||
let tmp = JSON.parse(localStorage.getItem('lastWatched'))
|
||||
tmp.push({
|
||||
'id': videoIdWatched.toString(),
|
||||
'date' : new Date()
|
||||
});
|
||||
localStorage.setItem('lastWatched', JSON.stringify(tmp));
|
||||
//.finally(()=>{})
|
||||
clearInterval(timerId1);
|
||||
},
|
||||
|
||||
+3
-4
@@ -5,9 +5,8 @@ import ReactDOM from 'react-dom';
|
||||
import App from './App';
|
||||
import registerServiceWorker from './registerServiceWorker';
|
||||
import { HashRouter, BrowserRouter } from 'react-router-dom'; // eslint-disable-line
|
||||
localStorage.setItem('lastWatched', JSON.stringify([]))
|
||||
localStorage['lastId'] ? function (){}() : localStorage.setItem('lastId','0J2QdDbelmY')
|
||||
|
||||
let lastWatchedList=[];
|
||||
localStorage.setItem('lastWatched', lastWatchedList)
|
||||
|
||||
ReactDOM.render(<BrowserRouter><App /></BrowserRouter>, document.getElementById('root'));
|
||||
ReactDOM.render(<HashRouter><App /></HashRouter>, document.getElementById('root'));
|
||||
registerServiceWorker();
|
||||
|
||||
+43
-23
@@ -15,41 +15,61 @@ class Search extends React.Component {
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
axios.get('https://www.googleapis.com/youtube/v3/search', { //Richiesta per ottenere i commenti del video
|
||||
params: {
|
||||
'part': 'snippet',
|
||||
'q': this.state.query,
|
||||
'videoEmbeddable': 'true',
|
||||
'type': 'video',
|
||||
'maxResults': 30,
|
||||
'topicId': '/m/04rlf, /m/02jjt',
|
||||
'key': 'AIzaSyA21Odw9UdfiOJnxvA_eDfOW0OxuUfHKig' // process.env.APIKEY in production
|
||||
}
|
||||
}).then(
|
||||
res => {
|
||||
console.log(res.data);
|
||||
this.setState({
|
||||
res: res.data
|
||||
})
|
||||
},
|
||||
error => {console.error(error)}
|
||||
)
|
||||
console.log('called didmo');
|
||||
}
|
||||
|
||||
// shouldComponentUpdate(nextProps, nextState) {
|
||||
|
||||
// }
|
||||
|
||||
// componentDidUpdate(prevProps, prevState) {
|
||||
|
||||
// }
|
||||
componentDidUpdate(prevProps, prevState) {
|
||||
console.log('called didup');
|
||||
if(new RegExp("[0-9A-Za-z_-]{10}[048AEIMQUYcgkosw]").test(this.state.query.toString()))
|
||||
axios.get('https://www.googleapis.com/youtube/v3/videos',{
|
||||
params: {
|
||||
'part':'id',
|
||||
'id': this.state.query,
|
||||
'key': process.env.APIKEY ? process.env.APIKEY : 'AIzaSyA21Odw9UdfiOJnxvA_eDfOW0OxuUfHKig',
|
||||
'field': 'pageInfo/resultsPerPage'
|
||||
}
|
||||
}).then(
|
||||
res => {
|
||||
res.data.pageInfo.resultsPerPage ?
|
||||
this.props.history.push('/video/' + this.state.query) :
|
||||
this.youtubeSearch()
|
||||
},
|
||||
error => {
|
||||
console.error(error)
|
||||
}
|
||||
)
|
||||
else
|
||||
this.youtubeSearch();
|
||||
}
|
||||
|
||||
// componentWillUnmount() {
|
||||
|
||||
// }
|
||||
|
||||
youtubeSearch() {
|
||||
|
||||
return axios.get('https://www.googleapis.com/youtube/v3/search', {
|
||||
params: {
|
||||
'part': 'snippet',
|
||||
'q': this.state.query,
|
||||
'videoEmbeddable': 'true',
|
||||
'type': 'video',
|
||||
'maxResults': 30,
|
||||
'topicId': '/m/04rlf, /m/02jjt',
|
||||
'key': process.env.APIKEY ? process.env.APIKEY : 'AIzaSyA21Odw9UdfiOJnxvA_eDfOW0OxuUfHKig'
|
||||
}
|
||||
}).then(
|
||||
res => {
|
||||
console.log(res.data);
|
||||
this.setState({
|
||||
res: res.data
|
||||
})
|
||||
},
|
||||
error => { console.error(error) }
|
||||
)
|
||||
}
|
||||
|
||||
render() {
|
||||
|
||||
Reference in New Issue
Block a user