This commit is contained in:
calzoneman 2014-01-23 15:53:53 -06:00
parent 551d5b2c36
commit 6e2d9c3caa
5 changed files with 29 additions and 23 deletions

View File

@ -1926,6 +1926,7 @@ Channel.prototype.handleJumpTo = function (user, data) {
Channel.prototype.clear = function () { Channel.prototype.clear = function () {
this.playlist.clear(); this.playlist.clear();
this.plqueue.reset(); this.plqueue.reset();
this.updatePlaylistMeta();
this.sendPlaylist(this.users); this.sendPlaylist(this.users);
}; };
@ -2103,11 +2104,15 @@ Channel.prototype.checkVoteskipPass = function () {
return false; return false;
} }
if (this.playlist.length === 0) {
return false;
}
var max = this.calcVoteskipMax(); var max = this.calcVoteskipMax();
var need = Math.ceil(max * this.opts.voteskip_ratio); var need = Math.ceil(max * this.opts.voteskip_ratio);
if (this.voteskip.counts[0] >= need) { if (this.voteskip.counts[0] >= need) {
this.logger.log("### Voteskip passed, skipping to next video"); this.logger.log("### Voteskip passed, skipping to next video");
this.playNext(); this.playlist.next();
} }
this.sendVoteskipUpdate(this.users); this.sendVoteskipUpdate(this.users);

View File

@ -146,25 +146,30 @@ Server.prototype.isChannelLoaded = function (name) {
}; };
Server.prototype.getChannel = function (name) { Server.prototype.getChannel = function (name) {
var self = this;
var cname = name.toLowerCase(); var cname = name.toLowerCase();
for (var i = 0; i < this.channels.length; i++) { for (var i = 0; i < self.channels.length; i++) {
if (this.channels[i].uniqueName === cname) if (self.channels[i].uniqueName === cname)
return this.channels[i]; return self.channels[i];
} }
var c = new Channel(name); var c = new Channel(name);
this.channels.push(c); c.on("empty", function () {
self.unloadChannel(c);
});
self.channels.push(c);
return c; return c;
}; };
Server.prototype.unloadChannel = function (chan) { Server.prototype.unloadChannel = function (chan) {
if (chan.registered) if (chan.registered) {
chan.saveState(); chan.saveState();
}
chan.playlist.die(); chan.playlist.die();
chan.logger.close(); chan.logger.close();
for (var i = 0; i < this.channels.length; i++) { for (var i = 0; i < this.channels.length; i++) {
if (this.channels[i].canonical_name === chan.canonical_name) { if (this.channels[i].uniqueName === chan.uniqueName) {
this.channels.splice(i, 1); this.channels.splice(i, 1);
i--; i--;
} }

View File

@ -32,26 +32,13 @@ Set.prototype.forEach = function (fn) {
} }
}; };
var USERNAME_REGEX = new RegExp(
"^[-\\w" + // Hyphen and a-zA-Z0-9_
"\\u00c0-\\u00c5" + // Uppercase A
"\\u00c7-\\u00cf" + // Uppercase C, E and I
"\\u00d1-\\u00d6" + // Uppercase N and O
"\\u00d9-\\u00dd" + // Uppercase U and Y
"\\u00e0-\\u00e5" + // Lowercase A
"\\u00e7-\\u00ef" + // Lowercase C, E anf I
"\\u00f1-\\u00f6" + // Lowercase N anf O
"\\u00f9-\\u00ff" + // Lowercase U anf Y
"]{1,20}$"
);
module.exports = { module.exports = {
isValidChannelName: function (name) { isValidChannelName: function (name) {
return name.match(/^[\w-_]{1,30}$/); return name.match(/^[\w-]{1,30}$/);
}, },
isValidUserName: function (name) { isValidUserName: function (name) {
return name.match(USERNAME_REGEX); return name.match(/^[\w-]{1,20}$/);
}, },
isValidEmail: function (email) { isValidEmail: function (email) {

View File

@ -142,6 +142,15 @@ function handleIndex(req, res) {
loginName = req.cookies.auth.split(":")[0]; loginName = req.cookies.auth.split(":")[0];
} }
var channels = Server.getServer().packChannelList(true);
channels.sort(function (a, b) {
if (a.usercount === b.usercount) {
return a.uniqueName > b.uniqueName ? 1 : -1;
}
return a.usercount - b.usercount;
});
sendJade(res, "index", { sendJade(res, "index", {
loggedIn: loginName !== false, loggedIn: loginName !== false,
loginName: loginName, loginName: loginName,

View File

@ -24,7 +24,7 @@ html(lang="en")
tbody tbody
each chan in channels each chan in channels
tr tr
td #{chan.pagetitle} (#{chan.name}) td: a(href="/r/#{chan.name}") #{chan.pagetitle} (#{chan.name})
td= chan.usercount td= chan.usercount
td= chan.mediatitle td= chan.mediatitle
.col-lg-3.col-md-3 .col-lg-3.col-md-3