Don't query the library table for live media

This commit is contained in:
calzoneman 2013-08-20 14:20:21 -05:00
parent e415e1e1d6
commit e830ba2d41
2 changed files with 43 additions and 29 deletions

View File

@ -1241,11 +1241,45 @@ Channel.prototype.addMedia = function(data, user) {
"custom embeds");
return;
}
if(isLive(data.type) &&
!self.hasPermission(user, "playlistaddlive")) {
user.socket.emit("queueFail", "You don't have " +
"permission to add livestreams");
return;
}
data.temp = data.temp || isLive(data.type);
data.queueby = user ? user.name : "";
data.maxlength = self.hasPermission(user, "exceedmaxlength")
? 0
: this.opts.maxlength;
var postAdd = function (item, cached) {
self.logger.log("### " + user.name + " queued " + item.media.title);
self.sendAll("queue", {
item: item.pack(),
after: item.prev ? item.prev.uid : "prepend"
});
self.broadcastPlaylistMeta();
if(!cached && !item.temp)
self.cacheMedia(item.media);
}
// No need to check library for livestreams - they aren't cached
if(isLive(data.type)) {
self.playlist.addMedia(data, function (err, data) {
if(err) {
if(err === true)
err = false;
if(user)
user.socket.emit("queueFail", err);
return;
}
else {
postAdd(data, false);
}
});
return;
}
self.server.db.getLibraryItem(self.name, data.id,
function (err, item) {
if(err) {
@ -1268,24 +1302,11 @@ Channel.prototype.addMedia = function(data, user) {
if(user)
user.socket.emit("queueFail", err);
return;
}
else {
self.logger.log("### " + user.name + " queued " + item.media.title);
self.sendAll("queue", {
item: item.pack(),
after: item.prev ? item.prev.uid : "prepend"
});
self.broadcastPlaylistMeta();
} else {
postAdd(item, true);
}
});
return;
} else {
if(isLive(data.type) &&
!self.hasPermission(user, "playlistaddlive")) {
user.socket.emit("queueFail", "You don't have " +
"permission to add livestreams");
return;
}
self.playlist.addMedia(data, function(err, item) {
if(err) {
if(err === true)
@ -1293,16 +1314,8 @@ Channel.prototype.addMedia = function(data, user) {
if(user)
user.socket.emit("queueFail", err);
return;
}
else {
self.logger.log("### " + user.name + " queued " + item.media.title);
self.sendAll("queue", {
item: item.pack(),
after: item.prev ? item.prev.uid : "prepend"
});
self.broadcastPlaylistMeta();
if(!item.temp)
self.cacheMedia(item.media);
} else {
postAdd(item, false);
}
});
}

View File

@ -39,14 +39,15 @@ Database.prototype.query = function (query, sub, callback) {
var self = this;
self.pool.getConnection(function (err, conn) {
if(err) {
Logger.errlog.log("! DB connection failed: " + err);
callback("Database failure", null);
} else {
function cback(err, res) {
if(err) {
if(self.cfg["debug"]) {
console.log(query);
console.log(err);
}
Logger.errlog.log("! DB query failed: " + query);
if(sub)
Logger.errlog.log("Substitutions: " + sub);
Logger.errlog.log(err);
callback("Database failure", null);
} else {
callback(null, res);