forked from nestorInc/jukebox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoken_api.rb
More file actions
36 lines (29 loc) · 790 Bytes
/
token_api.rb
File metadata and controls
36 lines (29 loc) · 790 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
#!/usr/bin/env ruby
require 'rev'
require 'socket'
require 'http.rb'
require 'display.rb'
require 'db.rb'
class TokenManager < HttpNode
def initialize(library)
@library = library;
super();
end
def on_request(s, req)
if(s.auth != "httpAuth" && s.auth != "cookie")
rep = HttpResponse.generate401(req);
s.write(rep.to_s);
return;
end
token = @library.get_user_login_token(s.user);
if( token == nil )
rep = HttpResponse.generate401(req);
s.write(rep.to_s);
return;
end
rep = HttpResponse.new(req.proto, 200, "OK",
"Content-Type" => "audio/x-mpegurl");
rep.setData("http://#{Socket.gethostname}:#{s.local_address.ip_port}/stream?token=#{token}\n");
s.write(rep.to_s);
end
end