feat: voting
This commit is contained in:
1 parent
af9934d476
commit
3f25547362
4 files changed
+54
-9
No files matched your search
@@ -1,18 +1,14 @@
|
||||
import dotenv from 'dotenv'
|
||||
import express, { json, urlencoded } from 'express'
|
||||
import { join } from 'path'
|
||||
import cookieParser from 'cookie-parser'
|
||||
import { createServer } from 'http'
|
||||
import fs from 'fs'
|
||||
|
||||
import { broadcast } from './socket.js'
|
||||
import db from './db.js'
|
||||
import { byId } from './spotify.js'
|
||||
|
||||
import track from './routes/track.js'
|
||||
import status from './routes/status.js'
|
||||
import history from './routes/history.js'
|
||||
import search from './routes/search.js'
|
||||
import vote from './routes/vote.js'
|
||||
|
||||
dotenv.config()
|
||||
|
||||
@@ -25,9 +21,9 @@ app.use(cookieParser())
|
||||
app.set('port', process.env.portHttp)
|
||||
|
||||
app.use('/track', track)
|
||||
app.use('/status', status)
|
||||
app.use('/history', history)
|
||||
app.use('/search', search)
|
||||
app.use('/vote', vote)
|
||||
|
||||
www.listen(process.env.portHttp)
|
||||
|
||||
@@ -46,8 +42,8 @@ www.on('listening', function () {
|
||||
setInterval(() => {
|
||||
broadcast({
|
||||
cat: 'status',
|
||||
trackid: '3OcyTN8Nz3bdne5aq9mMR5',
|
||||
trackid: '2FBP8xsTWbJv3zjc1Dix0c',
|
||||
progress: 20e3 + new Date().getMilliseconds(),
|
||||
paused: false,
|
||||
})
|
||||
}, 5e3)
|
||||
}, 10e3)
|
||||
+15
-1
@@ -1,6 +1,7 @@
|
||||
import express from 'express'
|
||||
|
||||
import { byId } from '../spotify.js'
|
||||
import db from '../db.js'
|
||||
|
||||
const router = express.Router()
|
||||
|
||||
@@ -9,7 +10,20 @@ router.get('/', (req, res) => {
|
||||
})
|
||||
|
||||
router.get('/:id', (req, res) => {
|
||||
byId(req.params.id).then((track) => res.send(track))
|
||||
if (req.query.votes) {
|
||||
return res.send({
|
||||
set: 'down',
|
||||
up: 20,
|
||||
down: 10,
|
||||
})
|
||||
}
|
||||
|
||||
db.tracks
|
||||
.get(req.params.id)
|
||||
.then((track) => res.send(track))
|
||||
.catch((err) => {
|
||||
res.status(400).end()
|
||||
})
|
||||
})
|
||||
|
||||
export default router
|
||||
@@ -0,0 +1,29 @@
|
||||
import express from 'express'
|
||||
|
||||
import db from '../db.js'
|
||||
|
||||
const router = express.Router()
|
||||
|
||||
router.get('/', (req, res) => {
|
||||
res.send('Vote for track.')
|
||||
})
|
||||
|
||||
router.get('/:id/', ({ params }, res) => {
|
||||
db.votes.getTrackStats(params.id).then((stats) => {
|
||||
res.send(stats)
|
||||
})
|
||||
})
|
||||
|
||||
router.get('/:id/cast', ({ params, query }, res) => {
|
||||
db.votes.getUserTrack(params.id, query.uid).then((vote) => {
|
||||
res.send(vote ? vote.value : '')
|
||||
})
|
||||
})
|
||||
|
||||
router.patch('/:id/', ({ params, body }, res) => {
|
||||
db.votes.putUserTrack(params.id, body.uid, body.value).then((vote) => {
|
||||
res.end(JSON.stringify(vote))
|
||||
})
|
||||
})
|
||||
|
||||
export default router
|
||||
Reference in new issue
Block a user