This commit is contained in:
Mateusz Pstrucha committed 2020-09-19 23:16:28 +02:00
1 parent 3e2488b03b
commit e8dd98e540
4 files changed
+21 -196

No files matched your search

+8 -78
View File
@@ -135,28 +135,24 @@ const credentials = {
const Previous = {
tracks: [],
new(tid, played) {
// if (Object.keys(tid).length < 1) return
pretty.log(`Previous: new track`, 2)
var previous = { tid: tid, played: played.getTime() }
this.tracks.push(previous)
// tid.played = played.getTime()
// this.tracks.unshift(tid)
this._send(previous)
},
_send(previous) {
// pretty.log(`Previous: updating previous history`)
server.emit('previous', {
new: previous,
})
},
async update() {
this.tracks = []
for (previous of await db.history.get()) {
this.new(previous.tid, previous.createdAt)
}
},
get() {
if (this.tracks.length < 1) return []
return {
all: this.tracks.slice(0, 20)
}
@@ -218,7 +214,7 @@ const Previous = {
set serial(value) {
this._serial = value
this._changed = true
if (this._serial - this._sentAt > this.threshold) {
if (this._serial - this._sentAt > this.threshold) { // force update after 'thershold' of votes
this.update()
this._changed = false
}
@@ -245,20 +241,11 @@ const Previous = {
return this.values[b].total - this.values[a].total
})
// return console.log(this.tids)
// this.tids = (Object.keys(values).sort(function (a, b) { return values[a] - values[b] })).reverse()
for (let tid in this.values) {
let track = await Tracks.get(tid)
// tracks.get(tid).then(track => {
// track.votes = values[tid]
// track.placement = this.tids.indexOf(tid) + 1
// })
if (track.banned) {
this.tids.splice(this.tids.indexOf(tid), 1)
continue
}
track.votes = this.values[tid]
track.placement = this.tids.indexOf(tid) + 1
if (track.banned) this.tids.splice(this.tids.indexOf(tid), 1)
}
this._changed = false
this._sentAt = this._serial
@@ -358,53 +345,9 @@ www.on('listening', function () {
pretty.log(`www: listening on ${port}`)
});
// app.get('/login', function (req, res) {
// var scopes = ['user-read-private', 'user-read-email'],
// redirect = spotify.createAuthorizeURL(scopes, 'what')
// res.redirect(redirect)
// // res.redirect('https://accounts.spotify.com/authorize' +
// // '?response_type=code' +
// // '&client_id=' + credentials.spotify.clientId +
// // (scopes ? '&scope=' + encodeURIComponent(scopes) : '') +
// // '&redirect_uri=' + encodeURIComponent('https://radio-rolnik.mtps.pl/logedin'));
// });
// app.get('/logedin', function (req, res) {
// console.log(req.query.code)
// spotify.authorizationCodeGrant(req.query.code).then(
// function (data) {
// console.log('The token expires in ' + data.body['expires_in']);
// console.log('The access token is ' + data.body['access_token']);
// console.log('The refresh token is ' + data.body['refresh_token']);
// // Set the access token on the API object to use it in later calls
// spotify.setAccessToken(data.body['access_token']);
// spotify.setRefreshToken(data.body['refresh_token']);
// },
// function (err) {
// console.log('Something went wrong!', err);
// }
// );
// })
// setInterval(function () {
// console.log(Stats._authed)
// }, 5e3)
Chart.interval()
Previous.update()
// Tracks.get('7GhIk7Il098yCjg4BQjzvb').then(track => {
// Player.set(track)
// Tracks.get('6habFhsOp2NvshLv26DqMb').then(track => {
// Player.set(track)
// Tracks.get('3yfqSUWxFvZELEM4PmlwIR').then(track => {
// Player.set(track)
// })
// })
// })
server.on('connection', socket => {
Stats.connect()
@@ -430,9 +373,6 @@ server.on('connection', socket => {
socket.on('clear', function (data) {
Stats.deauth(socket)
socket.user = undefined
// socket.emit('auth', { // demand token clear
// clear: true
// })
})
socket.on('auth', function (tokens) {
@@ -532,26 +472,16 @@ server.on('connection', socket => {
socket.on('flags', function (tid) {
if (!socket.user) return
db.votes.validUser(socket.user, tid).then(vote => {
// let flags = vote ? {
// up: vote.flag == 'up',
// down: vote.flag == 'down',
// report: vote.report
// } : {
// up: false,
// down: false,
// report: false
// }
socket.emit('flags', {
tid: tid,
flags: vote !== null ? vote.flag : null
})
}).catch(err => {
throw err
// socket.emit('meta', {
// type: 'error',
// action: 'flags',
// message: `Flags: api error for '${data.query}'`
// })
socket.emit('meta', {
type: 'error',
action: 'flags',
message: `Flags: api error for '${data.query}'`
})
})
})
+2 -35
View File
@@ -16,7 +16,6 @@ body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
font-family: 'Lato', sans-serif;
line-height: 1.3rem;
/* font-weight: 600; */
}
.hidden {
@@ -25,9 +24,7 @@ body {
::-webkit-scrollbar {
width: 0px;
/* Remove scrollbar space */
background: transparent;
/* Optional: just make scrollbar invisible */
}
#offline {
@@ -49,12 +46,10 @@ body {
}
#wrapper {
/* height: calc(100vh - 2rem); */
height: 100vh;
max-width: 900px;
background: var(--color-2grey);
box-sizing: border-box;
/* border-radius: 5px; */
position: relative;
left: 0;
right: 0;
@@ -63,19 +58,13 @@ body {
overflow: hidden;
}
/* #wrapper.admin {
max-width: 100%;
} */
#player {
position: relative;
}
#player>.current {
width: 100%;
/* padding: 0.5rem; */
background: var(--color-primary);
/* border-radius: 5px 5px 0px 0px; */
transition: background .3s ease-in-out;
box-sizing: border-box;
overflow: hidden;
@@ -125,12 +114,6 @@ body {
background-color: #93474C;
}
@media only screen and (max-width: 768px) {
.admin>#nav>.button>.label {
display: none;
}
}
@media only screen and (max-width: 630px) {
#nav>.button>.label {
display: none;
@@ -184,7 +167,6 @@ a:hover {
-webkit-transform: translateY(-50%);
transform: translateY(-50%);
font-size: 1.2rem;
/* background: inherit; */
text-shadow: 0px 0px 8px black;
}
@@ -252,12 +234,8 @@ a:hover {
.pane.search>.query>.icons {
background: var(--color-1grey);
/* float: right; */
/* height: 2.5rem; */
padding: .5rem;
padding-right: 18px;
/* width: 100%; */
/* box-sizing: border-box; */
text-align: right;
margin-top: 8px;
overflow: hidden;
@@ -336,7 +314,6 @@ a:hover {
.pane.preview>.buttons>i.clicked {
background: var(--color-primary);
/* cursor: default; */
}
.pane.preview>.params {
@@ -351,7 +328,6 @@ a:hover {
.pane.preview>.params>tbody>tr.highlight {
font-weight: bold;
/* background: #ffffff11; */
}
.pane.preview>.params>tbody>tr.highlight::before {
@@ -453,16 +429,13 @@ a:hover {
.chart>.list>.track::before {
content: counter(number)" ";
position: absolute;
left: .95rem;
left: .9rem;
top: 1.25rem;
font-size: 1rem;
/* height: 2.6rem; */
/* -webkit-transform: translateX(-50%); */
/* transform: translateY(-50%); */
}
.chart>.list>.track:nth-child(n+10)::before {
left: .65rem;
left: .6rem;
}
.chart>.list>.track:nth-child(n+100)::before {
@@ -530,10 +503,4 @@ a:hover {
text-align: center;
padding: .5rem;
cursor: pointer;
}
/* Admin */
.pane.admin {
padding: .5rem;
}
-3
View File
@@ -167,9 +167,6 @@
<div class="button" data-target='settings'>
<i class="icon-cog-alt"></i>
<span class="label">Ustawienia</span></div>
<div class="button hidden" data-target='admin'>
<i class="icon-flag"></i>
<span class="label">Admin</span></div>
</div>
</div>
</body>
+11 -80
View File
@@ -263,12 +263,6 @@ pretty = {
}
}
// function checkLoginState() {
// FB.getLoginStatus(function (response) {
// auth.response(response)
// });
// }
Tracks = {
_list: {},
_promises: {},
@@ -373,15 +367,6 @@ Hash = {
}
Vote = {
up(track) {
this._send(track, 'up')
},
down(track) {
this._send(track, 'down')
},
report(track) {
this._send(track, 'report')
},
send(track, flag) {
this._emit(track, flag)
},
@@ -469,27 +454,25 @@ Search = {
list: [],
update(tids, total) {
pretty.info('Search', `${total} results`)
Elements.search.container.innerHTML = ''
Elements.search.info.textContent = `${total} utworów`
for (let tid of tids) {
Tracks.get(tid).then(track => {
this._append(track)
})
// var result = new Track(track)
}
},
submit() {
var value = Elements.search.input.value
if (value === '') return
Elements.search.info.textContent = ''
Socket.emit('search', {
query: value,
source: 'spotify'
})
gtag('event', 'search', {
'search_term': value
});
},
_append(result) {
this.list.push(result)
@@ -566,13 +549,6 @@ window.onload = function () {
report: document.querySelector('.pane.preview>.buttons>.icon-flag'),
},
status: null,
// reset(flag) {
// // if (typeof flag == 'undefined') var flags = Preview.track.flags
// this.status = {
// up: this._clicked('up', flag == 'up'),
// down: this._clicked('down', flag == 'down'),
// }
// },
_clicked(flag, status = false) {
if (status) Elements.flags[flag].classList.add('clicked')
else Elements.flags[flag].classList.remove('clicked')
@@ -607,12 +583,13 @@ window.onload = function () {
this.flags.set(track.flag)
},
goto(track) {
Panes.switch('preview')
this.change(track)
Panes.switch('preview')
Hash.set(`track:${this.track.id}`)
},
update() {
pretty.info('Preview', `update`)
Elements.preview.table.innerHTML = ''
Elements.preview.table.append(...this.track.tbody().children)
}
@@ -695,19 +672,6 @@ window.onload = function () {
Elements.auth.prof.style.backgroundImage = `url('https://graph.facebook.com/${this.info.id}/picture?type=large')`
Elements.auth.username.textContent = this.info.name
Elements.auth.fbLogin.classList.add('hidden')
// this.el.params.innerHTML = ''
// this.el.params.append(...new Table([
// ['Zalogowano', ok ? 'tak' : 'nie'],
// ['Użytkownik', this.info.name],
// ['Token', this.tokens.local ? 'tak' : 'nie'],
// ['Facebook', this.facebook.status ? this.facebook.status : '~']
// ]).children)
gtag('event', 'login');
// if(this.info.admin)
// document.querySelector('#wrapper').classList.add('admin')
// document.querySelector('#nav>.button[data-target=admin]').classList.remove('hidden')
} else {
this.successful = false
Elements.auth.buttons.classList.add('disabled')
@@ -755,44 +719,21 @@ window.onload = function () {
values: {},
serial: null,
async update(tids, values, serial) {
console.log(serial)
if (serial === this.serial) return
pretty.info('Chart', `update, serial '${serial}' vs '${this.serial}'`)
this.tids = tids
this.values = values
this.serial = serial
// return console.log(this)
// tids.map(tid => {
// let track = await tracks.get(tid)
// track.votes = values[tid]
// if (preview.track.id == tid) preview.update()
// return track
// }).forEach(track => {
// this.el.append(track.el())
// })
let top = []
this.el.innerHTML = ''
for (let tid of tids) {
let track = await Tracks.get(tid)
track.votes = values[tid]
track.placement = tids.indexOf(tid) + 1
top.push(track)
this.el.append(track.el())
if (Preview.track.id == tid) Preview.update()
}
// this.el.innerHTML = ''
// tracks.forEach(track => {
// this.el.append(track.el())
// })
// for (let tid in values) {
// if (tracks._list[tid]) {
// tracks._list[tid].votes = values[tid]
// }
// }
// tracks.update()
}
}
@@ -802,6 +743,7 @@ window.onload = function () {
// ############ Click events
// main navigation buttons
document.querySelectorAll('#nav>.button').forEach(button => {
button.addEventListener('click', function (e) {
Panes.switch(this.getAttribute('data-target'))
@@ -809,6 +751,7 @@ window.onload = function () {
})
})
// search input autosearch
var keyupTimeout
document.querySelector('.pane.search>.query>.input').addEventListener("keyup", function (e) {
clearTimeout(keyupTimeout)
@@ -819,6 +762,7 @@ window.onload = function () {
}
})
// search buttons
document.querySelector('.pane.search>.query>.icons').addEventListener('click', function (e) {
if (e.target.classList.value.startsWith('icon-')) {
switch (e.target.classList.value.slice(5)) {
@@ -832,6 +776,7 @@ window.onload = function () {
}
})
// track preview buttons
document.querySelector('.pane.preview>.buttons').addEventListener('click', function (e) {
if (e.target.classList.value.startsWith('icon-')) {
let target = e.target.classList.value.split(' ')[0].slice(5)
@@ -843,9 +788,6 @@ window.onload = function () {
text: `Sprawdź "${Preview.track.title}" na radio-rolnik`,
url: location.href,
})
gtag('event', 'share', {
'method': 'navigator.share'
});
}
break;
case 'music':
@@ -904,6 +846,7 @@ window.onload = function () {
}
})
// settings buttons
document.querySelector('.pane.settings>.actions').addEventListener('click', function (e) {
if (e.target.getAttribute('data-target')) {
switch (e.target.getAttribute('data-target')) {
@@ -925,8 +868,6 @@ window.onload = function () {
// ############ Miscellaneous
// FB.Event.subscribe('auth.statusChange', function () { auth.fbReq() })
// go to hash location
if (location.hash == '') Hash.set('history')
else Hash.change()
@@ -946,16 +887,6 @@ window.onload = function () {
}, 30e3)
}
// register service worker
if (false)
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/sw.js').then(function (registration) {
pretty.info('ServiceWorker', 'registration successful');
}, function (err) {
pretty.info('ServiceWorker', `registration failed: ${err.message}`);
});
}
// ############ Socket events
Socket.on('connect', function () {