mirror of https://github.com/calzoneman/sync.git
Move server files to lib/ to clean up root directory
This commit is contained in:
parent
7b54b2fcc0
commit
7840fa35e8
|
@ -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
|
Wed Sep 4 22:45 2013 CDT
|
||||||
* changelog: initialize changelog file
|
* changelog: initialize changelog 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 Logger = require("./logger");
|
||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
|
var path = require("path");
|
||||||
var $util = require("./utilities");
|
var $util = require("./utilities");
|
||||||
|
|
||||||
module.exports = function (Server) {
|
module.exports = function (Server) {
|
||||||
|
@ -65,7 +66,7 @@ module.exports = function (Server) {
|
||||||
app.get("/api/channels/:channel", function (req, res) {
|
app.get("/api/channels/:channel", function (req, res) {
|
||||||
Server.stats.record("api", "/api/channels/:channel");
|
Server.stats.record("api", "/api/channels/:channel");
|
||||||
var name = req.params.channel;
|
var name = req.params.channel;
|
||||||
if(!name.match(/^[\w-_]+$/)) {
|
if(!$util.isValidChannelName(name)) {
|
||||||
res.send(404);
|
res.send(404);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -483,8 +484,7 @@ module.exports = function (Server) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(email.match(/.*@(localhost|127\.0\.0\.1)/i)) {
|
if(email.match(/.*@(localhost|127\.0\.0\.1)/i)) {
|
||||||
res.jsonp({
|
res.jsonp({ success: false,
|
||||||
success: false,
|
|
||||||
error: "Nice try, but no"
|
error: "Nice try, but no"
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
|
@ -597,10 +597,11 @@ module.exports = function (Server) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var start = data.size - len;
|
var start = data.size - len;
|
||||||
if(start < 0) {
|
if(start < 0)
|
||||||
start = 0;
|
start = 0;
|
||||||
}
|
|
||||||
var end = data.size - 1;
|
var end = data.size - 1;
|
||||||
|
if(end < 0)
|
||||||
|
end = 0;
|
||||||
fs.createReadStream(file, { start: start, end: end })
|
fs.createReadStream(file, { start: start, end: end })
|
||||||
.pipe(res);
|
.pipe(res);
|
||||||
});
|
});
|
||||||
|
@ -630,7 +631,7 @@ module.exports = function (Server) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
pipeLast(res, "sys.log", 1048576);
|
pipeLast(res, path.join(__dirname, "../sys.log"), 1048576);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -658,7 +659,7 @@ module.exports = function (Server) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
pipeLast(res, "error.log", 1048576);
|
pipeLast(res, path.join(__dirname, "../error.log"), 1048576);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -692,9 +693,11 @@ module.exports = function (Server) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
fs.exists("chanlogs/" + chan + ".log", function(exists) {
|
fs.exists(path.join(__dirname, "../chanlogs", chan + ".log"),
|
||||||
|
function(exists) {
|
||||||
if(exists) {
|
if(exists) {
|
||||||
pipeLast(res, "chanlogs/" + chan + ".log", 1048576);
|
pipeLast(res, path.join(__dirname, "../chanlogs",
|
||||||
|
chan + ".log"), 1048576);
|
||||||
} else {
|
} else {
|
||||||
res.send(404);
|
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 fs = require("fs");
|
||||||
|
var path = require("path");
|
||||||
var Poll = require("./poll.js").Poll;
|
var Poll = require("./poll.js").Poll;
|
||||||
var Media = require("./media.js").Media;
|
var Media = require("./media.js").Media;
|
||||||
var Logger = require("./logger.js");
|
var Logger = require("./logger.js");
|
||||||
|
@ -101,7 +102,8 @@ var Channel = function(name, Server) {
|
||||||
self.ip_alias = {};
|
self.ip_alias = {};
|
||||||
self.name_alias = {};
|
self.name_alias = {};
|
||||||
self.login_hist = [];
|
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.i = 0;
|
||||||
self.time = new Date().getTime();
|
self.time = new Date().getTime();
|
||||||
self.plmeta = {
|
self.plmeta = {
|
||||||
|
@ -146,7 +148,8 @@ Channel.prototype.loadDump = function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
if(self.name === "")
|
if(self.name === "")
|
||||||
return;
|
return;
|
||||||
fs.stat("chandump/" + self.name, function (err, stats) {
|
fs.stat(path.join(__dirname, "../chandump", self.name),
|
||||||
|
function (err, stats) {
|
||||||
if(!err) {
|
if(!err) {
|
||||||
var mb = stats.size / 1048576;
|
var mb = stats.size / 1048576;
|
||||||
mb = parseInt(mb * 100) / 100;
|
mb = parseInt(mb * 100) / 100;
|
||||||
|
@ -160,7 +163,8 @@ Channel.prototype.loadDump = function() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fs.readFile("chandump/" + self.name, function(err, data) {
|
fs.readFile(path.join(__dirname, "../chandump", self.name),
|
||||||
|
function(err, data) {
|
||||||
if(err) {
|
if(err) {
|
||||||
if(err.code == "ENOENT") {
|
if(err.code == "ENOENT") {
|
||||||
Logger.errlog.log("WARN: missing dump for " + self.name);
|
Logger.errlog.log("WARN: missing dump for " + self.name);
|
||||||
|
@ -286,7 +290,7 @@ Channel.prototype.saveDump = function() {
|
||||||
js: this.js
|
js: this.js
|
||||||
};
|
};
|
||||||
var text = JSON.stringify(dump);
|
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
|
// Save channel dumps every 5 minutes, in case of crash
|
|
@ -10,6 +10,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
|
var path = require("path");
|
||||||
|
|
||||||
function getTimeString() {
|
function getTimeString() {
|
||||||
var d = new Date();
|
var d = new Date();
|
||||||
|
@ -51,8 +52,8 @@ Logger.prototype.close = function () {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var errlog = new Logger("error.log");
|
var errlog = new Logger(path.join(__dirname, "../error.log"));
|
||||||
var syslog = new Logger("sys.log");
|
var syslog = new Logger(path.join(__dirname, "../sys.log"));
|
||||||
errlog.actualLog = errlog.log;
|
errlog.actualLog = errlog.log;
|
||||||
errlog.log = function(what) { console.log(what); this.actualLog(what); }
|
errlog.log = function(what) { console.log(what); this.actualLog(what); }
|
||||||
syslog.actualLog = syslog.log;
|
syslog.actualLog = syslog.log;
|
|
@ -96,7 +96,8 @@ var Server = {
|
||||||
this.db = new Database(self.cfg);
|
this.db = new Database(self.cfg);
|
||||||
this.db.init();
|
this.db.init();
|
||||||
this.actionlog = require("./actionlog")(self);
|
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 = express();
|
||||||
this.app.use(express.bodyParser());
|
this.app.use(express.bodyParser());
|
||||||
// channel path
|
// channel path
|
||||||
|
@ -108,7 +109,9 @@ var Server = {
|
||||||
else {
|
else {
|
||||||
self.stats.record("http", "/r/" + c);
|
self.stats.record("http", "/r/" + c);
|
||||||
self.logHTTP(req);
|
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.app.get("/", function (req, res, next) {
|
||||||
self.logHTTP(req);
|
self.logHTTP(req);
|
||||||
self.stats.record("http", "/");
|
self.stats.record("http", "/");
|
||||||
res.sendfile(__dirname + "/www/index.html");
|
res.sendfile("index.html", {
|
||||||
|
root: path.join(__dirname, "../www")
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// default path
|
// default path
|
||||||
self.app.get("/:thing(*)", function (req, res, next) {
|
self.app.get("/:thing(*)", function (req, res, next) {
|
||||||
var opts = {
|
var opts = {
|
||||||
root: __dirname + "/www",
|
root: path.join(__dirname, "../www"),
|
||||||
maxAge: self.cfg["asset-cache-ttl"]
|
maxAge: self.cfg["asset-cache-ttl"]
|
||||||
}
|
}
|
||||||
res.sendfile(req.params.thing, opts, function (err) {
|
res.sendfile(req.params.thing, opts, function (err) {
|
||||||
|
@ -231,15 +236,17 @@ var Server = {
|
||||||
|
|
||||||
Logger.syslog.log("Starting CyTube v" + VERSION);
|
Logger.syslog.log("Starting CyTube v" + VERSION);
|
||||||
|
|
||||||
fs.exists("chanlogs", function (exists) {
|
var chanlogpath = path.join(__dirname, "../chanlogs");
|
||||||
exists || fs.mkdir("chanlogs");
|
fs.exists(chanlogpath, function (exists) {
|
||||||
|
exists || fs.mkdir(chanlogpath);
|
||||||
});
|
});
|
||||||
|
|
||||||
fs.exists("chandump", function (exists) {
|
var chandumppath = path.join(__dirname, "../chandump");
|
||||||
exists || fs.mkdir("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();
|
Server.init();
|
||||||
if(!Server.cfg["debug"]) {
|
if(!Server.cfg["debug"]) {
|
||||||
process.on("uncaughtException", function (err) {
|
process.on("uncaughtException", function (err) {
|
2
run.sh
2
run.sh
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
while :
|
while :
|
||||||
do
|
do
|
||||||
node server.js
|
node lib/server.js
|
||||||
sleep 2
|
sleep 2
|
||||||
|
|
||||||
done
|
done
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
var Config = require("./config.js");
|
var Config = require("./lib/config.js");
|
||||||
var Database = require("./database.js");
|
var Database = require("./lib/database.js");
|
||||||
|
|
||||||
var updates = {
|
var updates = {
|
||||||
"2013-08-20-utf8fix": fixDBUnicode,
|
"2013-08-20-utf8fix": fixDBUnicode,
|
||||||
|
|
Loading…
Reference in New Issue