This commit is contained in:
calzoneman 2013-07-16 11:46:09 -04:00
parent 5a9b3128d1
commit 824a313b19
6 changed files with 52 additions and 27 deletions

4
acp.js
View File

@ -115,14 +115,14 @@ module.exports = function (Server) {
user.socket.on("acp-list-loaded", function() {
var chans = [];
var all = Server.getAllChannels();
var all = Server.channels;
for(var c in all) {
var chan = all[c];
if(!chan)
continue;
chans.push({
name: c,
name: chan.name,
title: chan.opts.pagetitle,
usercount: chan.users.length,
mediatitle: chan.playlist.current ? chan.playlist.current.media.title : "-",

47
api.js
View File

@ -28,26 +28,10 @@ function getIP(req) {
}
module.exports = function (Server) {
return {
plainHandlers: {
"readlog" : this.handleReadLog
},
jsonHandlers: {
"channeldata" : this.handleChannelData,
"listloaded" : this.handleChannelList,
"login" : this.handleLogin,
"register" : this.handleRegister,
"changepass" : this.handlePasswordChange,
"resetpass" : this.handlePasswordReset,
"recoverpw" : this.handlePasswordRecover,
"setprofile" : this.handleProfileChange,
"getprofile" : this.handleProfileGet,
"setemail" : this.handleEmailChange,
"admreports" : this.handleAdmReports,
"readactionlog" : this.handleReadActionLog
},
var API = function () {
}
API.prototype = {
handle: function (path, req, res) {
var parts = path.split("/");
var last = parts[parts.length - 1];
@ -576,11 +560,34 @@ module.exports = function (Server) {
else {
res.send(404);
}
});
}.bind(this));
}
else {
res.send(400);
}
}
};
var api = new API();
api.plainHandlers = {
"readlog" : api.handleReadLog.bind(api)
};
api.jsonHandlers = {
"channeldata" : api.handleChannelData.bind(api),
"listloaded" : api.handleChannelList.bind(api),
"login" : api.handleLogin.bind(api),
"register" : api.handleRegister.bind(api),
"changepass" : api.handlePasswordChange.bind(api),
"resetpass" : api.handlePasswordReset.bind(api),
"recoverpw" : api.handlePasswordRecover.bind(api),
"setprofile" : api.handleProfileChange.bind(api),
"getprofile" : api.handleProfileGet.bind(api),
"setemail" : api.handleEmailChange.bind(api),
"admreports" : api.handleAdmReports.bind(api),
"readactionlog" : api.handleReadActionLog.bind(api)
};
return api;
}

View File

@ -647,8 +647,7 @@ Channel.prototype.userLeave = function(user) {
this.logger.log("--- /" + user.ip + " (" + user.name + ") left");
if(this.users.length == 0) {
this.logger.log("*** Channel empty, unloading");
var name = this.name;
this.server.unload(this);
this.server.unloadChannel(this);
}
}
@ -1203,6 +1202,10 @@ Channel.prototype.tryQueue = function(user, data) {
}
Channel.prototype.addMedia = function(data, user) {
if(data.type === "yp" && !this.hasPermission(user, "playlistaddlist")) {
user.socket.emit("queueFail", "You don't have permission to add playlists");
return;
}
data.temp = isLive(data.type) || !this.hasPermission(user, "addnontemp");
data.maxlength = this.hasPermission(user, "exceedmaxlength") ? 0 : this.opts.maxlength;
var chan = this;

View File

@ -35,6 +35,11 @@ function getJSONInternal(transport, options, callback) {
m = buffer.match(/([0-9]+ not found)/);
Logger.errlog.log("Media request failed: "+options.host+options.path);
if(m) {
if(m[1] === "too_many_recent_calls") {
m[1] = "YouTube is throttling the server right "+
"now for making too many requests. "+
"Please try again in a moment.";
}
Logger.errlog.log("Reason: " + m[1]);
callback(m[1], res.statusCode, null);
}

View File

@ -35,7 +35,7 @@ PlaylistItem.prototype.pack = function() {
function Playlist(chan) {
if(chan.name in AllPlaylists && AllPlaylists[chan.name]) {
var pl = AllPlaylists[chan.name];
if("_leadInterval" in pl)
if(!pl.dead)
pl.die();
}
this.items = new ULList();
@ -130,6 +130,7 @@ Playlist.prototype.die = function () {
}
for(var key in this)
delete this[key];
this.dead = true;
}
Playlist.prototype.load = function(data, callback) {
@ -272,6 +273,8 @@ Playlist.prototype.addMediaList = function(data, callback) {
var x = data.list[i];
(function(i, x) {
setTimeout(function() {
if(pl.dead)
return;
x.queueby = data.queueby;
x.pos = data.pos;
if(start && x == start) {
@ -310,7 +313,14 @@ Playlist.prototype.addYouTubePlaylist = function(data, callback) {
return;
}
if(data.pos === "next")
vids.reverse();
vids.forEach(function(media) {
if(data.maxlength && media.seconds > data.maxlength) {
callback("Media is too long!", null);
return;
}
var it = pl.makeItem(media);
it.temp = data.temp;
it.queueby = data.queueby;

View File

@ -84,7 +84,7 @@ var Server = {
this.api = require("./api")(this);
this.app.get("/api/:apireq(*)", function (req, res, next) {
this.api.handle(req.url.substring(5), req, res);
});
}.bind(this));
// default path
this.app.get("/:thing(*)", function (req, res, next) {
@ -121,7 +121,7 @@ var Server = {
socket.on("disconnect", function () {
this.ips[ip]--;
});
}.bind(this));
if(!(ip in this.ips))
this.ips[ip] = 0;