Move server files to lib/ to clean up root directory
This commit is contained in:
parent
7b54b2fcc0
commit
7840fa35e8
6
.gitignore
vendored
Normal file
6
.gitignore
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
*.swp
|
||||
cfg.json
|
||||
chandump
|
||||
chanlogs
|
||||
*.log
|
||||
node_modules
|
11
changelog
11
changelog
|
@ -1,3 +1,14 @@
|
|||
Thu Sep 5 13:45 2013 CDT
|
||||
* acp.js, actionlog.js, api.js, channel.js, chatcommand.js, config.js,
|
||||
customembed.js, database.js, filter.js, get-info.js, logger.js,
|
||||
media.js, notwebsocket.js, playlist.js, poll.js, rank.js, server.js,
|
||||
stats.js, ullist.js, user.js, utilities.js: move server
|
||||
files into lib/ folder to clean up the root directory of the project.
|
||||
* api.js: replace regex with $util.isValidChannelName (L68);
|
||||
fix relative file paths (per moving api.js to lib/)
|
||||
* server.js: fix relative file paths
|
||||
* channel.js: fix relative file paths
|
||||
|
||||
Wed Sep 4 22:45 2013 CDT
|
||||
* changelog: initialize changelog file
|
||||
|
||||
|
|
BIN
lib/.logger.js.swp
Normal file
BIN
lib/.logger.js.swp
Normal file
Binary file not shown.
|
@ -11,6 +11,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|||
|
||||
var Logger = require("./logger");
|
||||
var fs = require("fs");
|
||||
var path = require("path");
|
||||
var $util = require("./utilities");
|
||||
|
||||
module.exports = function (Server) {
|
||||
|
@ -60,16 +61,16 @@ module.exports = function (Server) {
|
|||
});
|
||||
|
||||
/* REGION channels */
|
||||
|
||||
|
||||
/* data about a specific channel */
|
||||
app.get("/api/channels/:channel", function (req, res) {
|
||||
Server.stats.record("api", "/api/channels/:channel");
|
||||
var name = req.params.channel;
|
||||
if(!name.match(/^[\w-_]+$/)) {
|
||||
if(!$util.isValidChannelName(name)) {
|
||||
res.send(404);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
var data = {
|
||||
name: name,
|
||||
loaded: false
|
||||
|
@ -125,7 +126,7 @@ module.exports = function (Server) {
|
|||
}
|
||||
|
||||
// If we get here, the filter is public channels
|
||||
|
||||
|
||||
var channels = [];
|
||||
for(var key in Server.channels) {
|
||||
var channel = Server.channels[key];
|
||||
|
@ -170,11 +171,11 @@ module.exports = function (Server) {
|
|||
});
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Only record login-success for admins
|
||||
if(row.global_rank >= 255)
|
||||
ActionLog.record(getIP(req), name, "login-success");
|
||||
|
||||
|
||||
res.jsonp({
|
||||
success: true,
|
||||
name: name,
|
||||
|
@ -201,7 +202,7 @@ module.exports = function (Server) {
|
|||
});
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if(toomany) {
|
||||
ActionLog.record(ip, name, "register-failure",
|
||||
"Too many recent registrations");
|
||||
|
@ -225,7 +226,7 @@ module.exports = function (Server) {
|
|||
|
||||
|
||||
if(!$util.isValidUserName(name)) {
|
||||
ActionLog.record(ip, name, "register-failure",
|
||||
ActionLog.record(ip, name, "register-failure",
|
||||
"Invalid name");
|
||||
res.jsonp({
|
||||
success: false,
|
||||
|
@ -338,11 +339,11 @@ module.exports = function (Server) {
|
|||
}
|
||||
|
||||
var msg = "A password reset request was issued for your " +
|
||||
"account '"+ name + "' on " + Server.cfg["domain"] +
|
||||
"account '"+ name + "' on " + Server.cfg["domain"] +
|
||||
". This request is valid for 24 hours. If you did "+
|
||||
"not initiate this, there is no need to take action."+
|
||||
" To reset your password, copy and paste the " +
|
||||
"following link into your browser: " +
|
||||
"following link into your browser: " +
|
||||
Server.cfg["domain"] + "/reset.html?"+hash;
|
||||
|
||||
var mail = {
|
||||
|
@ -435,7 +436,7 @@ module.exports = function (Server) {
|
|||
});
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
db.setUserProfile(name, { image: img, text: text },
|
||||
function (err, dbres) {
|
||||
if(err) {
|
||||
|
@ -483,8 +484,7 @@ module.exports = function (Server) {
|
|||
}
|
||||
|
||||
if(email.match(/.*@(localhost|127\.0\.0\.1)/i)) {
|
||||
res.jsonp({
|
||||
success: false,
|
||||
res.jsonp({ success: false,
|
||||
error: "Nice try, but no"
|
||||
});
|
||||
return;
|
||||
|
@ -583,7 +583,7 @@ module.exports = function (Server) {
|
|||
ActionLog.listActions(types, function (err, actions) {
|
||||
if(err)
|
||||
actions = [];
|
||||
|
||||
|
||||
res.jsonp(actions);
|
||||
});
|
||||
});
|
||||
|
@ -597,10 +597,11 @@ module.exports = function (Server) {
|
|||
return;
|
||||
}
|
||||
var start = data.size - len;
|
||||
if(start < 0) {
|
||||
if(start < 0)
|
||||
start = 0;
|
||||
}
|
||||
var end = data.size - 1;
|
||||
if(end < 0)
|
||||
end = 0;
|
||||
fs.createReadStream(file, { start: start, end: end })
|
||||
.pipe(res);
|
||||
});
|
||||
|
@ -630,7 +631,7 @@ module.exports = function (Server) {
|
|||
return;
|
||||
}
|
||||
|
||||
pipeLast(res, "sys.log", 1048576);
|
||||
pipeLast(res, path.join(__dirname, "../sys.log"), 1048576);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -658,7 +659,7 @@ module.exports = function (Server) {
|
|||
return;
|
||||
}
|
||||
|
||||
pipeLast(res, "error.log", 1048576);
|
||||
pipeLast(res, path.join(__dirname, "../error.log"), 1048576);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -692,9 +693,11 @@ module.exports = function (Server) {
|
|||
return;
|
||||
}
|
||||
|
||||
fs.exists("chanlogs/" + chan + ".log", function(exists) {
|
||||
fs.exists(path.join(__dirname, "../chanlogs", chan + ".log"),
|
||||
function(exists) {
|
||||
if(exists) {
|
||||
pipeLast(res, "chanlogs/" + chan + ".log", 1048576);
|
||||
pipeLast(res, path.join(__dirname, "../chanlogs",
|
||||
chan + ".log"), 1048576);
|
||||
} else {
|
||||
res.send(404);
|
||||
}
|
|
@ -11,6 +11,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|||
*/
|
||||
|
||||
var fs = require("fs");
|
||||
var path = require("path");
|
||||
var Poll = require("./poll.js").Poll;
|
||||
var Media = require("./media.js").Media;
|
||||
var Logger = require("./logger.js");
|
||||
|
@ -101,7 +102,8 @@ var Channel = function(name, Server) {
|
|||
self.ip_alias = {};
|
||||
self.name_alias = {};
|
||||
self.login_hist = [];
|
||||
self.logger = new Logger.Logger("chanlogs/" + self.canonical_name + ".log");
|
||||
self.logger = new Logger.Logger(path.join(__dirname, "../chanlogs",
|
||||
self.canonical_name + ".log"));
|
||||
self.i = 0;
|
||||
self.time = new Date().getTime();
|
||||
self.plmeta = {
|
||||
|
@ -146,7 +148,8 @@ Channel.prototype.loadDump = function() {
|
|||
var self = this;
|
||||
if(self.name === "")
|
||||
return;
|
||||
fs.stat("chandump/" + self.name, function (err, stats) {
|
||||
fs.stat(path.join(__dirname, "../chandump", self.name),
|
||||
function (err, stats) {
|
||||
if(!err) {
|
||||
var mb = stats.size / 1048576;
|
||||
mb = parseInt(mb * 100) / 100;
|
||||
|
@ -154,13 +157,14 @@ Channel.prototype.loadDump = function() {
|
|||
Logger.errlog.log("Large chandump detected: " + self.name +
|
||||
" (" + mb + " MB)");
|
||||
self.updateMotd("Your channel file has exceeded the " +
|
||||
"maximum size of 1MB and cannot be " +
|
||||
"loaded. Please ask an administrator " +
|
||||
"maximum size of 1MB and cannot be " +
|
||||
"loaded. Please ask an administrator " +
|
||||
"for assistance in restoring it.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
fs.readFile("chandump/" + self.name, function(err, data) {
|
||||
fs.readFile(path.join(__dirname, "../chandump", self.name),
|
||||
function(err, data) {
|
||||
if(err) {
|
||||
if(err.code == "ENOENT") {
|
||||
Logger.errlog.log("WARN: missing dump for " + self.name);
|
||||
|
@ -286,7 +290,7 @@ Channel.prototype.saveDump = function() {
|
|||
js: this.js
|
||||
};
|
||||
var text = JSON.stringify(dump);
|
||||
fs.writeFileSync("chandump/" + this.name, text);
|
||||
fs.writeFileSync(path.join(__dirname, "../chandump", this.name), text);
|
||||
}
|
||||
|
||||
// Save channel dumps every 5 minutes, in case of crash
|
||||
|
@ -398,7 +402,7 @@ Channel.prototype.tryRegister = function (user) {
|
|||
return;
|
||||
}
|
||||
|
||||
self.server.actionlog.record(user.ip, user.name,
|
||||
self.server.actionlog.record(user.ip, user.name,
|
||||
"channel-register-success", self.name);
|
||||
self.registered = true;
|
||||
self.initialized = true;
|
||||
|
@ -438,7 +442,7 @@ Channel.prototype.unregister = function (user) {
|
|||
});
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
self.registered = false;
|
||||
user.socket.emit("unregisterChannel", { success: true });
|
||||
});
|
||||
|
@ -638,7 +642,7 @@ Channel.prototype.tryIPBan = function(actor, name, range) {
|
|||
}
|
||||
|
||||
self.ipbans[ip] = [name, actor.name];
|
||||
self.logger.log("*** " + actor.name + " banned " + ip +
|
||||
self.logger.log("*** " + actor.name + " banned " + ip +
|
||||
" (" + name + ")");
|
||||
|
||||
for(var i = 0; i < self.users.length; i++) {
|
||||
|
@ -1271,7 +1275,7 @@ Channel.prototype.tryQueue = function(user, data) {
|
|||
|
||||
Channel.prototype.addMedia = function(data, user) {
|
||||
var self = this;
|
||||
if(data.type === "yp" &&
|
||||
if(data.type === "yp" &&
|
||||
!self.hasPermission(user, "playlistaddlist")) {
|
||||
user.socket.emit("queueFail", "You don't have permission to add " +
|
||||
"playlists");
|
||||
|
@ -1488,7 +1492,7 @@ Channel.prototype.tryDequeue = function(user, data) {
|
|||
|
||||
if(typeof data !== "number")
|
||||
return;
|
||||
|
||||
|
||||
var plitem = this.playlist.items.find(data);
|
||||
if(plitem && plitem.media)
|
||||
this.logger.log("### " + user.name + " deleted " + plitem.media.title);
|
||||
|
@ -1508,7 +1512,7 @@ Channel.prototype.tryUncache = function(user, data) {
|
|||
if(err)
|
||||
return;
|
||||
|
||||
self.logger.log("*** " + user.name + " deleted " + data.id +
|
||||
self.logger.log("*** " + user.name + " deleted " + data.id +
|
||||
" from library");
|
||||
});
|
||||
}
|
||||
|
@ -1619,12 +1623,12 @@ Channel.prototype.move = function(data, user) {
|
|||
if(typeof data.moveby !== "undefined")
|
||||
moveby = data.moveby;
|
||||
|
||||
|
||||
|
||||
var fromit = chan.playlist.items.find(data.from);
|
||||
var afterit = chan.playlist.items.find(data.after);
|
||||
var aftertitle = afterit && afterit.media ? afterit.media.title : "";
|
||||
if(fromit) {
|
||||
chan.logger.log("### " + user.name + " moved " + fromit.media.title
|
||||
chan.logger.log("### " + user.name + " moved " + fromit.media.title
|
||||
+ (aftertitle ? " after " + aftertitle : ""));
|
||||
}
|
||||
|
||||
|
@ -2066,7 +2070,7 @@ Channel.prototype.trySetRank = function(user, data) {
|
|||
receiver.rank = data.rank;
|
||||
if(receiver.loggedIn) {
|
||||
self.saveRank(receiver, function (err, res) {
|
||||
self.logger.log("*** " + user.name + " set " +
|
||||
self.logger.log("*** " + user.name + " set " +
|
||||
data.user + "'s rank to " + data.rank);
|
||||
self.sendAllWithPermission("acl", "setChannelRank", data);
|
||||
});
|
||||
|
@ -2080,8 +2084,8 @@ Channel.prototype.trySetRank = function(user, data) {
|
|||
return;
|
||||
self.server.db.setChannelRank(self.name, data.user,
|
||||
data.rank, function (err, res) {
|
||||
|
||||
self.logger.log("*** " + user.name + " set " +
|
||||
|
||||
self.logger.log("*** " + user.name + " set " +
|
||||
data.user + "'s rank to " + data.rank);
|
||||
self.sendAllWithPermission("acl", "setChannelRank", data);
|
||||
});
|
|
@ -10,6 +10,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|||
*/
|
||||
|
||||
var fs = require("fs");
|
||||
var path = require("path");
|
||||
|
||||
function getTimeString() {
|
||||
var d = new Date();
|
||||
|
@ -51,8 +52,8 @@ Logger.prototype.close = function () {
|
|||
}
|
||||
}
|
||||
|
||||
var errlog = new Logger("error.log");
|
||||
var syslog = new Logger("sys.log");
|
||||
var errlog = new Logger(path.join(__dirname, "../error.log"));
|
||||
var syslog = new Logger(path.join(__dirname, "../sys.log"));
|
||||
errlog.actualLog = errlog.log;
|
||||
errlog.log = function(what) { console.log(what); this.actualLog(what); }
|
||||
syslog.actualLog = syslog.log;
|
|
@ -96,7 +96,8 @@ var Server = {
|
|||
this.db = new Database(self.cfg);
|
||||
this.db.init();
|
||||
this.actionlog = require("./actionlog")(self);
|
||||
this.httpaccess = new Logger.Logger("httpaccess.log");
|
||||
this.httpaccess = new Logger.Logger(path.join(__dirname,
|
||||
"../httpaccess.log"));
|
||||
this.app = express();
|
||||
this.app.use(express.bodyParser());
|
||||
// channel path
|
||||
|
@ -108,7 +109,9 @@ var Server = {
|
|||
else {
|
||||
self.stats.record("http", "/r/" + c);
|
||||
self.logHTTP(req);
|
||||
res.sendfile(__dirname + "/www/channel.html");
|
||||
res.sendfile("channel.html", {
|
||||
root: path.join(__dirname, "../www")
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -118,13 +121,15 @@ var Server = {
|
|||
self.app.get("/", function (req, res, next) {
|
||||
self.logHTTP(req);
|
||||
self.stats.record("http", "/");
|
||||
res.sendfile(__dirname + "/www/index.html");
|
||||
res.sendfile("index.html", {
|
||||
root: path.join(__dirname, "../www")
|
||||
});
|
||||
});
|
||||
|
||||
// default path
|
||||
self.app.get("/:thing(*)", function (req, res, next) {
|
||||
var opts = {
|
||||
root: __dirname + "/www",
|
||||
root: path.join(__dirname, "../www"),
|
||||
maxAge: self.cfg["asset-cache-ttl"]
|
||||
}
|
||||
res.sendfile(req.params.thing, opts, function (err) {
|
||||
|
@ -231,15 +236,17 @@ var Server = {
|
|||
|
||||
Logger.syslog.log("Starting CyTube v" + VERSION);
|
||||
|
||||
fs.exists("chanlogs", function (exists) {
|
||||
exists || fs.mkdir("chanlogs");
|
||||
var chanlogpath = path.join(__dirname, "../chanlogs");
|
||||
fs.exists(chanlogpath, function (exists) {
|
||||
exists || fs.mkdir(chanlogpath);
|
||||
});
|
||||
|
||||
fs.exists("chandump", function (exists) {
|
||||
exists || fs.mkdir("chandump");
|
||||
var chandumppath = path.join(__dirname, "../chandump");
|
||||
fs.exists(chandumppath, function (exists) {
|
||||
exists || fs.mkdir(chandumppath);
|
||||
});
|
||||
|
||||
Config.load(Server, "cfg.json", function () {
|
||||
Config.load(Server, path.join(__dirname, "../cfg.json"), function () {
|
||||
Server.init();
|
||||
if(!Server.cfg["debug"]) {
|
||||
process.on("uncaughtException", function (err) {
|
Loading…
Reference in a new issue