dotenv, minor fixes
This commit is contained in:
1 parent
3e18448072
commit
9c2b0fe83f
6 files changed
+42
-28
No files matched your search
+2
-1
@@ -1,3 +1,4 @@
|
||||
node_modules/
|
||||
*cred.json
|
||||
.vscode/
|
||||
.vscode/
|
||||
.env
|
||||
@@ -103,11 +103,19 @@ module.exports = {
|
||||
},
|
||||
votes: {
|
||||
timeValid: () => {
|
||||
var monday = new Date();
|
||||
monday.setHours(0, 0, 0)
|
||||
monday.setDate(monday.getDate() - (monday.getDay() + 6) % 7);
|
||||
switch (process.env.valid_type) {
|
||||
default:
|
||||
case 'monday':
|
||||
var monday = new Date();
|
||||
monday.setHours(0, 0, 0)
|
||||
monday.setDate(monday.getDate() - (monday.getDay() + 6) % 7);
|
||||
|
||||
return monday
|
||||
case 'date':
|
||||
let date = new Date(...JSON.parse(process.env.valid_date))
|
||||
return date
|
||||
}
|
||||
|
||||
return monday
|
||||
},
|
||||
add(user, tid, flag) {
|
||||
return new Promise((resolve, reject) => {
|
||||
@@ -128,7 +136,7 @@ module.exports = {
|
||||
action: 'error'
|
||||
})
|
||||
resolve(vote)
|
||||
pretty.log(`'${user.name}' changed vote to '${flag}' on '${tid}'`, 2)
|
||||
pretty.log(`'${user.name}' changed vote to '${flag == 'up' ? ' up ' : flag}' on '${tid}'`, 2)
|
||||
})
|
||||
} else {
|
||||
Vote.create({
|
||||
@@ -143,7 +151,7 @@ module.exports = {
|
||||
})
|
||||
})
|
||||
},
|
||||
get(uid, tid){
|
||||
get(uid, tid) {
|
||||
return new Promise((resolve, reject) => {
|
||||
Vote.find({
|
||||
$or: [
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
const express = require('express'),
|
||||
const dotenv = require('dotenv').config(),
|
||||
express = require('express'),
|
||||
path = require('path'),
|
||||
cookieParser = require('cookie-parser'),
|
||||
http = require('http'),
|
||||
@@ -136,8 +137,6 @@ const credentials = {
|
||||
const Previous = {
|
||||
tracks: [],
|
||||
new(tid, played = new Date) {
|
||||
pretty.log(`Previous: new track`, 2)
|
||||
|
||||
var previous = { tid: tid, played: played.getTime() }
|
||||
this.tracks.push(previous)
|
||||
this._send(previous)
|
||||
@@ -165,6 +164,7 @@ const Previous = {
|
||||
set(track) {
|
||||
this.now = track
|
||||
Previous.new(this.now.id)
|
||||
pretty.log(`Previous: new track`, 2)
|
||||
server.emit('player', {
|
||||
tid: this.now.id,
|
||||
status: this.status
|
||||
@@ -220,8 +220,8 @@ const Previous = {
|
||||
}
|
||||
},
|
||||
_changed: true,
|
||||
delay: 30e3,
|
||||
threshold: 10,
|
||||
delay: process.env.chart_delay,
|
||||
threshold: process.env.chart_threshold,
|
||||
interval() {
|
||||
if (this._changed) {
|
||||
this.update()
|
||||
@@ -318,16 +318,15 @@ if (new Date().getTime() >= credentials.spotify.lastToken.expires) {
|
||||
|
||||
var app = express(),
|
||||
www = http.createServer(app),
|
||||
port = 5500,
|
||||
server = io(www);
|
||||
|
||||
app.use(express.json());
|
||||
app.use(express.urlencoded({ extended: false }));
|
||||
app.use(cookieParser());
|
||||
app.use(express.static(path.join(__dirname, 'public')));
|
||||
app.set('port', port);
|
||||
app.set('port', process.env.port);
|
||||
|
||||
www.listen(port);
|
||||
www.listen(process.env.port);
|
||||
|
||||
www.on('error', function (error) {
|
||||
if (error.syscall !== 'listen') {
|
||||
@@ -335,13 +334,13 @@ www.on('error', function (error) {
|
||||
}
|
||||
|
||||
pretty.log({
|
||||
data: `Error: port ${port}: ${error.code}`,
|
||||
data: `Error: port ${process.env.port}: ${error.code}`,
|
||||
action: 'error'
|
||||
})
|
||||
});
|
||||
|
||||
www.on('listening', function () {
|
||||
pretty.log(`www: listening on ${port}`)
|
||||
pretty.log(`www: listening on ${process.env.port}`)
|
||||
});
|
||||
|
||||
app.use('/api/*', (req, res, next) => {
|
||||
@@ -357,8 +356,8 @@ app.use('/api/*', (req, res, next) => {
|
||||
res.status(401).send('Authentication required.') // custom message
|
||||
})
|
||||
|
||||
app.get('/api/player/set', function(req, res) {
|
||||
if(req.query.tid){
|
||||
app.get('/api/player/set', function (req, res) {
|
||||
if (req.query.tid) {
|
||||
Tracks.get(req.query.tid).then(track => {
|
||||
Player.set(track)
|
||||
res.send('ok')
|
||||
@@ -370,9 +369,9 @@ app.get('/api/player/set', function(req, res) {
|
||||
}
|
||||
})
|
||||
|
||||
app.get('/api/player/status', function(req, res) {
|
||||
app.get('/api/player/status', function (req, res) {
|
||||
let states = ['playing', 'paused', 'stopped']
|
||||
if(states.includes(req.query.set)){
|
||||
if (states.includes(req.query.set)) {
|
||||
Player.update(req.query.set)
|
||||
res.send('ok')
|
||||
res.status(200)
|
||||
@@ -551,7 +550,7 @@ server.on('connection', socket => {
|
||||
})
|
||||
})
|
||||
}
|
||||
if(data.search.tags.includes('user')) {
|
||||
if (data.search.tags.includes('user')) {
|
||||
db.users.search(data.search.query).then(users => {
|
||||
socket.emit('admin', {
|
||||
search: {
|
||||
@@ -583,7 +582,7 @@ server.on('connection', socket => {
|
||||
db.votes.get(data.vote.uid, data.vote.tid).then(votes => {
|
||||
socket.emit('admin', {
|
||||
vote: {
|
||||
votes: votes
|
||||
votes: votes
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
Generated
+9
-4
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "radio-rolnik",
|
||||
"version": "1.0.0",
|
||||
"version": "1.2.0",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
@@ -70,9 +70,9 @@
|
||||
}
|
||||
},
|
||||
"bl": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/bl/-/bl-2.2.0.tgz",
|
||||
"integrity": "sha512-wbgvOpqopSr7uq6fJrLH8EsvYMJf9gzfo2jCsL2eTy75qXPukA4pCgHamOQkZtY5vmfVtjB+P3LNlMHW5CEZXA==",
|
||||
"version": "2.2.1",
|
||||
"resolved": "https://registry.npmjs.org/bl/-/bl-2.2.1.tgz",
|
||||
"integrity": "sha512-6Pesp1w0DEX1N550i/uGV/TqucVL4AM/pgThFSN/Qq9si1/DF9aIHs1BxD8V/QU0HoeHO6cQRTAuYnLPKq1e4g==",
|
||||
"requires": {
|
||||
"readable-stream": "^2.3.5",
|
||||
"safe-buffer": "^5.1.1"
|
||||
@@ -260,6 +260,11 @@
|
||||
"resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz",
|
||||
"integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA="
|
||||
},
|
||||
"dotenv": {
|
||||
"version": "8.2.0",
|
||||
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-8.2.0.tgz",
|
||||
"integrity": "sha512-8sJ78ElpbDJBHNeBzUbUVLsqKdccaa/BXF1uPTw3GrvQTBgrQrtObr2mUrE38vzYd8cEv+m/JBfDLioYcfXoaw=="
|
||||
},
|
||||
"ee-first": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
"homepage": "https://github.com/Maathias/radio-rolnik#readme",
|
||||
"dependencies": {
|
||||
"cookie-parser": "^1.4.5",
|
||||
"dotenv": "^8.2.0",
|
||||
"express": "^4.17.1",
|
||||
"express-metatag": "^0.1.0",
|
||||
"mongoose": "^5.10.0",
|
||||
|
||||
+1
-1
@@ -370,7 +370,7 @@ Vote = {
|
||||
this._emit(track, flag)
|
||||
},
|
||||
_emit(track, flag) {
|
||||
pretty.info('Vote', `${flag}' on ${track.title}`)
|
||||
pretty.info('Vote', `'${flag}' on ${track.title}`)
|
||||
Socket.emit('vote', {
|
||||
tid: track.id,
|
||||
flag: flag
|
||||
|
||||
Reference in new issue
Block a user