-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrestapi.js
50 lines (40 loc) · 1.17 KB
/
restapi.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
var fs = require('fs-extra');
var express = require('express');
module.exports = function RestAPI(lib, app) {
var that = {
lib: lib,
app: app,
};
that.app.get('/library/songs/', function (req, res) {
that.lib.random(function (results) {
res.json({results: results});
})
});
that.app.get('/library/artists/:name', function (req, res) {
var name = req.params.name;
that.lib.getArtist(name, function (artist) {
res.json(artist);
});
});
that.app.get('/library/search/', function (req, res) {
var query = req.query.q;
that.lib.search(query, function (results) {
res.json({results: results});
})
});
that.app.get('/stream/:id', function (req, res) {
that.lib.get(req.params.id, function (doc) {
res.sendFile(doc.path, {lastModified: false}, function (err) {
res.end();
});
});
});
that.app.get('/library/waveforms/:id', function (req, res) {
var list = [];
for(var i=0; i<1000; i++) {
list.push(Math.random());
}
res.send(list);
});
return that;
};