mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-20 15:36:16 -04:00
Merge branch 'master' of github.com:Pita/etherpad-lite into HEAD
This commit is contained in:
commit
7a10e1783a
11 changed files with 209 additions and 92 deletions
|
@ -145,7 +145,7 @@ exports.handleMessage = function(client, message)
|
|||
}
|
||||
if(!message.type)
|
||||
{
|
||||
throw "Message have no type attribute!";
|
||||
throw "Message has no type attribute!";
|
||||
}
|
||||
|
||||
//Check what type of message we get and delegate to the other methodes
|
||||
|
@ -163,6 +163,12 @@ exports.handleMessage = function(client, message)
|
|||
{
|
||||
handleUserInfoUpdate(client, message);
|
||||
}
|
||||
else if(message.type == "COLLABROOM" &&
|
||||
message.data.type == "CLIENT_MESSAGE" &&
|
||||
message.data.payload.type == "suggestUserName")
|
||||
{
|
||||
handleSuggestUserName(client, message);
|
||||
}
|
||||
//if the message type is unkown, throw an exception
|
||||
else
|
||||
{
|
||||
|
@ -170,6 +176,36 @@ exports.handleMessage = function(client, message)
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles a handleSuggestUserName, that means a user have suggest a userName for a other user
|
||||
* @param client the client that send this message
|
||||
* @param message the message from the client
|
||||
*/
|
||||
function handleSuggestUserName(client, message)
|
||||
{
|
||||
//check if all ok
|
||||
if(message.data.payload.newName == null)
|
||||
{
|
||||
throw "suggestUserName Message has no newName!";
|
||||
}
|
||||
if(message.data.payload.unnamedId == null)
|
||||
{
|
||||
throw "suggestUserName Message has no unnamedId!";
|
||||
}
|
||||
|
||||
var padId = session2pad[client.sessionId];
|
||||
|
||||
//search the author and send him this message
|
||||
for(var i in pad2sessions[padId])
|
||||
{
|
||||
if(sessioninfos[pad2sessions[padId][i]].author == message.data.payload.unnamedId)
|
||||
{
|
||||
socketio.clients[pad2sessions[padId][i]].send(message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles a USERINFO_UPDATE, that means that a user have changed his color or name. Anyway, we get both informations
|
||||
* @param client the client that send this message
|
||||
|
@ -180,7 +216,7 @@ function handleUserInfoUpdate(client, message)
|
|||
//check if all ok
|
||||
if(message.data.userInfo.colorId == null)
|
||||
{
|
||||
throw "USERINFO_UPDATE Message have no colorId!";
|
||||
throw "USERINFO_UPDATE Message has no colorId!";
|
||||
}
|
||||
|
||||
//Find out the author name of this session
|
||||
|
@ -202,7 +238,7 @@ function handleUserInfoUpdate(client, message)
|
|||
message.data.type = "USER_NEWINFO";
|
||||
|
||||
//Send the other clients on the pad the update message
|
||||
for(i in pad2sessions[padId])
|
||||
for(var i in pad2sessions[padId])
|
||||
{
|
||||
if(pad2sessions[padId][i] != client.id)
|
||||
{
|
||||
|
@ -228,15 +264,15 @@ function handleUserChanges(client, message)
|
|||
//check if all ok
|
||||
if(message.data.baseRev == null)
|
||||
{
|
||||
throw "USER_CHANGES Message have no baseRev!";
|
||||
throw "USER_CHANGES Message has no baseRev!";
|
||||
}
|
||||
if(message.data.apool == null)
|
||||
{
|
||||
throw "USER_CHANGES Message have no apool!";
|
||||
throw "USER_CHANGES Message has no apool!";
|
||||
}
|
||||
if(message.data.changeset == null)
|
||||
{
|
||||
throw "USER_CHANGES Message have no changeset!";
|
||||
throw "USER_CHANGES Message has no changeset!";
|
||||
}
|
||||
|
||||
//get all Vars we need
|
||||
|
@ -451,25 +487,26 @@ function handleClientReady(client, message)
|
|||
//check if all ok
|
||||
if(!message.token)
|
||||
{
|
||||
throw "CLIENT_READY Message have no token!";
|
||||
throw "CLIENT_READY Message has no token!";
|
||||
}
|
||||
if(!message.padId)
|
||||
{
|
||||
throw "CLIENT_READY Message have no padId!";
|
||||
throw "CLIENT_READY Message has no padId!";
|
||||
}
|
||||
if(!message.protocolVersion)
|
||||
{
|
||||
throw "CLIENT_READY Message have no protocolVersion!";
|
||||
throw "CLIENT_READY Message has no protocolVersion!";
|
||||
}
|
||||
if(message.protocolVersion != 2)
|
||||
{
|
||||
throw "CLIENT_READY Message have a unkown protocolVersion '" + message.protocolVersion + "'!";
|
||||
throw "CLIENT_READY Message has a unkown protocolVersion '" + message.protocolVersion + "'!";
|
||||
}
|
||||
|
||||
var author;
|
||||
var authorName;
|
||||
var authorColorId;
|
||||
var pad;
|
||||
var historicalAuthorData = {};
|
||||
|
||||
async.series([
|
||||
//get all authordata of this new user
|
||||
|
@ -511,6 +548,20 @@ function handleClientReady(client, message)
|
|||
});
|
||||
},
|
||||
function(callback)
|
||||
{
|
||||
var authors = pad.getAllAuthors();
|
||||
|
||||
//get all author data out of the database
|
||||
async.forEach(authors, function(authorId, callback)
|
||||
{
|
||||
authorManager.getAuthor(authorId, function(err, author)
|
||||
{
|
||||
historicalAuthorData[authorId] = author;
|
||||
callback(err);
|
||||
});
|
||||
}, callback);
|
||||
},
|
||||
function(callback)
|
||||
{
|
||||
//Check if this author is already on the pad, if yes, kick the other sessions!
|
||||
if(pad2sessions[message.padId])
|
||||
|
@ -556,7 +607,7 @@ function handleClientReady(client, message)
|
|||
"clientIp": (client.request && client.request.connection) ? client.request.connection.remoteAddress : "127.0.0.1",
|
||||
//"clientAgent": "Anonymous Agent",
|
||||
"padId": message.padId,
|
||||
"historicalAuthorData": {},
|
||||
"historicalAuthorData": historicalAuthorData,
|
||||
"apool": apool,
|
||||
"rev": pad.getHeadRevisionNumber(),
|
||||
"globalPadId": message.padId
|
||||
|
@ -570,7 +621,7 @@ function handleClientReady(client, message)
|
|||
"opts": {},
|
||||
"chatHistory": {
|
||||
"start": 0,
|
||||
"historicalAuthorData": {},
|
||||
"historicalAuthorData": historicalAuthorData,
|
||||
"end": 0,
|
||||
"lines": []
|
||||
},
|
||||
|
@ -592,16 +643,6 @@ function handleClientReady(client, message)
|
|||
clientVars.userName = authorName;
|
||||
}
|
||||
|
||||
//Add all authors that worked on this pad, to the historicalAuthorData on clientVars
|
||||
var allAuthors = pad.getAllAuthors();
|
||||
for(i in allAuthors)
|
||||
{
|
||||
clientVars.collab_client_vars.historicalAuthorData[allAuthors[i]] = {};
|
||||
if(authorName != null)
|
||||
clientVars.collab_client_vars.historicalAuthorData[allAuthors[i]].name = authorName;
|
||||
clientVars.collab_client_vars.historicalAuthorData[allAuthors[i]].colorId = authorColorId;
|
||||
}
|
||||
|
||||
//Send the clientVars to the Client
|
||||
client.json.send(clientVars);
|
||||
|
||||
|
|
|
@ -58,6 +58,12 @@ exports.setSocketIO = function(_socket)
|
|||
|
||||
client.on('message', function(message)
|
||||
{
|
||||
if(message.protocolVersion && message.protocolVersion != 2)
|
||||
{
|
||||
console.error("Protocolversion header is not correct:" + JSON.stringify(message));
|
||||
return;
|
||||
}
|
||||
|
||||
//route this message to the correct component, if possible
|
||||
if(message.component && components[message.component])
|
||||
{
|
||||
|
@ -71,7 +77,7 @@ exports.setSocketIO = function(_socket)
|
|||
}
|
||||
else
|
||||
{
|
||||
throw "Can't route the message:" + JSON.stringify(message);
|
||||
console.error("Can't route the message:" + JSON.stringify(message));
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ exports.padJS = function(req, res)
|
|||
{
|
||||
res.header("Content-Type","text/javascript");
|
||||
|
||||
var jsFiles = ["plugins.js", "undo-xpopup.js", "json2.js", "pad_utils.js", "pad_cookie.js", "pad_editor.js", "pad_editbar.js", "pad_docbar.js", "pad_modals.js", "ace.js", "collab_client.js", "pad_userlist.js", "pad_impexp.js", "pad_savedrevs.js", "pad_connectionstatus.js", "pad2.js"];
|
||||
var jsFiles = ["jquery.min.js", "plugins.js", "undo-xpopup.js", "json2.js", "pad_utils.js", "pad_cookie.js", "pad_editor.js", "pad_editbar.js", "pad_docbar.js", "pad_modals.js", "ace.js", "collab_client.js", "pad_userlist.js", "pad_impexp.js", "pad_savedrevs.js", "pad_connectionstatus.js", "pad2.js"];
|
||||
|
||||
//minifying is enabled
|
||||
if(settings.minify)
|
||||
|
@ -182,9 +182,9 @@ exports.padJS = function(req, res)
|
|||
{
|
||||
//put all javascript files in an array
|
||||
var values = [];
|
||||
for(var i in fileValues)
|
||||
for(var i in jsFiles)
|
||||
{
|
||||
values.push(fileValues[i]);
|
||||
values.push(fileValues[jsFiles[i]]);
|
||||
}
|
||||
|
||||
//minify all javascript files to one
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
require('joose');
|
||||
|
||||
var socketio = require('socket.io');
|
||||
var fs = require('fs');
|
||||
var settings = require('./settings');
|
||||
var socketIORouter = require("./SocketIORouter");
|
||||
var db = require('./db');
|
||||
|
@ -31,9 +32,24 @@ var express = require('express');
|
|||
var path = require('path');
|
||||
var minify = require('./minify');
|
||||
|
||||
var serverName = "Etherpad-Lite ( http://j.mp/ep-lite )";
|
||||
//try to get the git version
|
||||
var version = "";
|
||||
try
|
||||
{
|
||||
var ref = fs.readFileSync("../.git/HEAD", "utf-8");
|
||||
var refPath = "../.git/" + ref.substring(5, ref.indexOf("\n"));
|
||||
version = fs.readFileSync(refPath, "utf-8");
|
||||
version = version.substring(0, 8);
|
||||
}
|
||||
catch(e)
|
||||
{
|
||||
console.error("Can't get git version for server header\n" + e.message)
|
||||
}
|
||||
|
||||
var serverName = "Etherpad-Lite " + version + " (http://j.mp/ep-lite)";
|
||||
|
||||
//cache a week
|
||||
exports.maxAge = 1000*60*60*24*1;
|
||||
exports.maxAge = 1000*60*60*6;
|
||||
|
||||
async.waterfall([
|
||||
//initalize the database
|
||||
|
@ -77,16 +93,30 @@ async.waterfall([
|
|||
});
|
||||
|
||||
//serve pad.html under /p
|
||||
app.get('/p/:pad', function(req, res)
|
||||
app.get('/p/:pad', function(req, res, next)
|
||||
{
|
||||
//ensure the padname is valid and the url doesn't end with a /
|
||||
if(!isValidPadname(req.params.pad) || /\/$/.test(req.url))
|
||||
{
|
||||
next();
|
||||
return;
|
||||
}
|
||||
|
||||
res.header("Server", serverName);
|
||||
var filePath = path.normalize(__dirname + "/../static/pad.html");
|
||||
res.sendfile(filePath, { maxAge: exports.maxAge });
|
||||
});
|
||||
|
||||
//serve timeslider.html under /p/$padname/timeslider
|
||||
app.get('/p/:pad/timeslider', function(req, res)
|
||||
app.get('/p/:pad/timeslider', function(req, res, next)
|
||||
{
|
||||
//ensure the padname is valid and the url doesn't end with a /
|
||||
if(!isValidPadname(req.params.pad) || /\/$/.test(req.url))
|
||||
{
|
||||
next();
|
||||
return;
|
||||
}
|
||||
|
||||
res.header("Server", serverName);
|
||||
var filePath = path.normalize(__dirname + "/../static/timeslider.html");
|
||||
res.sendfile(filePath, { maxAge: exports.maxAge });
|
||||
|
@ -134,3 +164,12 @@ async.waterfall([
|
|||
callback(null);
|
||||
}
|
||||
]);
|
||||
|
||||
function isValidPadname(padname)
|
||||
{
|
||||
//ensure there is no dollar sign in the pad name
|
||||
if(padname.indexOf("$")!=-1)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue