-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrequestHandlers.js
More file actions
36 lines (33 loc) · 1014 Bytes
/
Copy pathrequestHandlers.js
File metadata and controls
36 lines (33 loc) · 1014 Bytes
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
var util = require('util'),
exec = require('child_process').exec;
function index(req, res) {
exec('find -L public/audio -type f', function(err, stdout, stderr) {
var files = stdout.split('\n');
files = files.filter(function(x) { return x !== ''; });
var audioFiles = [];
for (i in files) {
fullName = files[i].substring(0, files[i].lastIndexOf('.'));
fullName = fullName.substring(fullName.lastIndexOf('/') + 1);
dash = fullName.lastIndexOf('-');
if (dash == -1) {
artist = 'Unknown Artist';
title = fullName;
} else {
artist = fullName.substring(0, dash);
title = fullName.substring(dash + 1);
}
audioFiles.push({
artist: artist,
title: title,
url:'/' + files[i]
});
}
res.render('index', {audioFiles: audioFiles.sort(function(a, b) {
return strcmp(a.artist, b.artist);
})});
});
}
function strcmp(a, b) {
return (a<b?-1:(a>b?1:0));
}
exports.index = index