-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexpress.js
92 lines (75 loc) · 2.11 KB
/
express.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
var express = require('express');
var sys = require('sys');
var queue = require('./queue.js');
var musicsource = require ('./itunes.js');
var app = express.createServer();
app.configure(function() {
app.use(express.logger());
app.use(express.errorHandler({
dumpExceptions:true,
showTack:true
}));
app.use(express.static(__dirname + '/static'));
});
app.set('views', __dirname + '/views');
var songs = require('./songs');
app.get('/', function(request, response) {
response.render('root.jade');
});
app.get('/status.json', function(req,res) {
res.contentType('application/json');
musicsource.status(function(data) {
res.partial('status.jade', data)
});
});
app.get('/status', function(req,res) {
musicsource.status(function(data) {
res.partial('status.jade', data)
}, function(data) {
res.partial('status.jade', data)
});
});
app.get('/playlist/:name', function(req,res) {
safe_playlist = req.params.name.replace(/[^A-Za-z-_0-9 \-]/g, "")
musicsource.songs_in_playlist(safe_playlist, function(data) {
debugger;
res.render('songindex.jade', {locals: {
songs:data
}});
}, function(error_data) {
res.render('error.jade', {locals: {error:error_data}});
});
});
app.get('/playlists', function(req,res) {
musicsource.all_playlists(function(data) {
res.render('playlists.jade', {locals: {
playlists:data
}});
});
});
app.post('/play/:id', function(req, res) {
safe_id = req.params.id.replace(/[^0-9]/g, "")
musicsource.play(safe_id, function(data) {
res.render('play.jade');
}, function (error_data) {
res.render('error.jade', {locals: {error:error_data}});
});
});
app.post('/stop', function(req, res) {
musicsource.pause(function(data) {
res.render('play.jade');
}, function (error_data) {
res.render('error.jade', {locals: {error:error_data}});
});
});
app.get('/queue/add/:id', function(req, res) {
queue.add(req.params.id);
res.json("", 204);
});
app.get('/queue', function(req, res) {
res.json(queue.contents());
});
app.get('/queue/random', function(req, res) {
res.json(queue.random());
});
app.listen(4000);