diff --git a/node-entry.js b/node-entry.js index 0a522fd..b65686a 100644 --- a/node-entry.js +++ b/node-entry.js @@ -59,7 +59,46 @@ low(new FileAsync(__dirname + '/db.json')) // production res.set({ 'Access-Control-Allow-Origin': '*' }); - req.query.id ? res.send(req.query.id) : res.status(400).send('Bad Request'); + const videos1 = db.get('videos'); + let videos = JSON.parse(JSON.stringify(videos1.values())); + if (req.query.id) { + let tmpRes; + let row = videos1.getById(req.query.id); + if (row.value()) { + let tmpA = videos.filter(x => x.id !== req.query.id).map(x => { + return { + "videoId": x.id, + "timesWatched": x.timesWatched, + "prevalentReason": x.reason.sort((a, b) => a.timesWatched - b.timesWatched).reverse()[0].reason, + "lastSelected": x.lastWatched + } + }) + tmpRes = { + "site": "site1854.tw.cs.unibo.it", + "recommender": req.query.id.toString(), + "lastWatched": row.value().lastWatched, + "recomended": tmpA + } + } + else { + let tmpA = videos.map(x => { + return { + "videoId": x.id, + "timesWatched": x.timesWatched, + "prevalentReason": x.reason.sort((a, b) => a.timesWatched - b.timesWatched).reverse()[0].reason, + "lastSelected": x.lastWatched + } + }) + tmpRes = { + "site": "site1854.tw.cs.unibo.it", + "recommender": req.query.id.toString(), + "lastWatched": "Never Watched", + "recomended": tmpA + } + } + res.send(tmpRes) + } else + res.status(400).send('Bad Request'); }); // OPTIONS /videotrack @@ -89,9 +128,9 @@ low(new FileAsync(__dirname + '/db.json')) // production for (let j = 0; j < videos[i].reason.length; j++) { console.log(videos[i].reason[j]) if (videos[i].reason[j].prevId === req.query.prevId) { - let tmp2 = { - ...videos[i].reason[j], - 'id': videos[i].id + let tmp2 = { + ...videos[i].reason[j], + 'id': videos[i].id } tmp.push(tmp2); } @@ -108,23 +147,23 @@ low(new FileAsync(__dirname + '/db.json')) // production res.set({ 'Access-Control-Allow-Origin': '*' }); - let setReason = function (reason='Starter', oldArr = [], prevId) { - let j=oldArr.findIndex(el=>el.prevId===prevId && el.reason===reason) - if (j>=0) { - ++oldArr[j].timesWatched; + let setReason = function (reason = 'Starter', oldArr = [], prevId) { + 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 + else { + let tmp = { + prevId, + reason, + timesWatched: 1 } oldArr.push(tmp) return oldArr } } - + const videos = db.get('videos'); const row = videos.getById(req.body.id); if (row.value()) { @@ -139,7 +178,7 @@ low(new FileAsync(__dirname + '/db.json')) // production "id": req.body.id.toString(), "timesWatched": 1, "lastWatched": new Date().toISOString(), - "reason": setReason(req.body.reason,[],req.body.prevId) + "reason": setReason(req.body.reason, [], req.body.prevId) } videos.push(newRow).last().write().then(output => res.send(200, output)) } diff --git a/src/Wikipedia.js b/src/Wikipedia.js index ff08663..ad36bba 100644 --- a/src/Wikipedia.js +++ b/src/Wikipedia.js @@ -54,7 +54,7 @@ class Wikipedia extends Component { const musicbrainzBaseUrl = "https://musicbrainz.org/ws/2"; // more readable let artist = this.props.artist || this.props.artist2; let title = this.props.title || this.props.title2; - console.log('porcodio', P175.toLowerCase(), artist.trim().toLowerCase(), P175.toLowerCase() === artist.trim().toLowerCase()) + console.log('accipicchia', P175.toLowerCase(), artist.trim().toLowerCase(), P175.toLowerCase() === artist.trim().toLowerCase()) if (P175.toLowerCase() === artist.trim().toLowerCase()) { axios .get(`https://musicbrainz.org/ws/2/recording`, { diff --git a/src/reccomenders/popGlobaleAssoluta.js b/src/reccomenders/popGlobaleAssoluta.js index df61fe6..27b6dc8 100644 --- a/src/reccomenders/popGlobaleAssoluta.js +++ b/src/reccomenders/popGlobaleAssoluta.js @@ -24,7 +24,7 @@ class popGlobaleAssoluta extends React.Component { // let listSiti = ['1828', '1829', '1838', '1839', '1846', '1822', '1847', '1831', '1827', '1848', '1824', '1830', '1836', '1850', '1849', '1851', '1861', '1823', '1863', '1834', '1904', '1906', '1901', '1862', '1859']; - let listSiti = ['1828', '1838', '1839', '1846', '1847', '1831', '1827', '1849', '1823', '1863', '1834', '1901', '1859']; + let listSiti = ['1828', '1838', '1839', '1846', '1831', '1827', '1849', '1823', '1863', '1834', '1901', '1859']; let axiosReq = []; for (let i = 0; i < listSiti.length; i++) { console.log(`http://site${listSiti[i]}.tw.cs.unibo.it/globpop`)