Merge branch 'master' of github.com:Pita/etherpad-lite

This commit is contained in:
John McLear 2012-01-31 14:16:01 +00:00
commit dfa106df03
4 changed files with 415 additions and 458 deletions

View file

@ -2,8 +2,6 @@
* The pad object, defined with joose * The pad object, defined with joose
*/ */
require('joose');
var ERR = require("async-stacktrace"); var ERR = require("async-stacktrace");
var Changeset = require("../utils/Changeset"); var Changeset = require("../utils/Changeset");
var AttributePoolFactory = require("../utils/AttributePoolFactory"); var AttributePoolFactory = require("../utils/AttributePoolFactory");
@ -22,60 +20,36 @@ var crypto = require("crypto");
*/ */
exports.cleanText = function (txt) { exports.cleanText = function (txt) {
return txt.replace(/\r\n/g,'\n').replace(/\r/g,'\n').replace(/\t/g, ' ').replace(/\xa0/g, ' '); return txt.replace(/\r\n/g,'\n').replace(/\r/g,'\n').replace(/\t/g, ' ').replace(/\xa0/g, ' ');
} };
Class('Pad', {
// these are the properties var Pad = function Pad(id) {
has : {
atext : { this.atext = Changeset.makeAText("\n");
is : 'rw', // readwrite this.pool = AttributePoolFactory.createAttributePool();
init : function() { return Changeset.makeAText("\n"); } // first value this.head = -1;
}, // atext this.chatHead = -1;
this.publicStatus = false;
this.passwordHash = null;
this.id = id;
pool : { };
is: 'rw',
init : function() { return AttributePoolFactory.createAttributePool(); },
getterName : 'apool' // legacy
}, // pool
head : { exports.Pad = Pad;
is : 'rw',
init : -1,
getterName : 'getHeadRevisionNumber'
}, // head
chatHead : { Pad.prototype.apool = function apool() {
is: 'rw', return this.pool;
init: -1 };
}, // chatHead
publicStatus : { Pad.prototype.getHeadRevisionNumber = function getHeadRevisionNumber() {
is: 'rw', return this.head;
init: false, };
getterName : 'getPublicStatus'
}, //publicStatus
passwordHash : { Pad.prototype.getPublicStatus = function getPublicStatus() {
is: 'rw', return this.publicStatus;
init: null };
}, // passwordHash
id : { is : 'r' } Pad.prototype.appendRevision = function appendRevision(aChangeset, author) {
},
methods : {
BUILD : function (id)
{
return {
'id' : id,
}
},
appendRevision : function(aChangeset, author)
{
if(!author) if(!author)
author = ''; author = '';
@ -106,25 +80,21 @@ Class('Pad', {
chatHead: this.chatHead, chatHead: this.chatHead,
publicStatus: this.publicStatus, publicStatus: this.publicStatus,
passwordHash: this.passwordHash}); passwordHash: this.passwordHash});
}, //appendRevision };
getRevisionChangeset : function(revNum, callback) Pad.prototype.getRevisionChangeset = function getRevisionChangeset(revNum, callback) {
{
db.getSub("pad:"+this.id+":revs:"+revNum, ["changeset"], callback); db.getSub("pad:"+this.id+":revs:"+revNum, ["changeset"], callback);
}, // getRevisionChangeset };
getRevisionAuthor : function(revNum, callback) Pad.prototype.getRevisionAuthor = function getRevisionAuthor(revNum, callback) {
{
db.getSub("pad:"+this.id+":revs:"+revNum, ["meta", "author"], callback); db.getSub("pad:"+this.id+":revs:"+revNum, ["meta", "author"], callback);
}, // getRevisionAuthor };
getRevisionDate : function(revNum, callback) Pad.prototype.getRevisionDate = function getRevisionDate(revNum, callback) {
{
db.getSub("pad:"+this.id+":revs:"+revNum, ["meta", "timestamp"], callback); db.getSub("pad:"+this.id+":revs:"+revNum, ["meta", "timestamp"], callback);
}, // getRevisionAuthor };
getAllAuthors : function() Pad.prototype.getAllAuthors = function getAllAuthors() {
{
var authors = []; var authors = [];
for(key in this.pool.numToAttrib) for(key in this.pool.numToAttrib)
@ -136,10 +106,9 @@ Class('Pad', {
} }
return authors; return authors;
}, };
getInternalRevisionAText : function(targetRev, callback) Pad.prototype.getInternalRevisionAText = function getInternalRevisionAText(targetRev, callback) {
{
var _this = this; var _this = this;
var keyRev = this.getKeyRevisionNumber(targetRev); var keyRev = this.getKeyRevisionNumber(targetRev);
@ -205,20 +174,17 @@ Class('Pad', {
if(ERR(err, callback)) return; if(ERR(err, callback)) return;
callback(null, atext); callback(null, atext);
}); });
}, };
getKeyRevisionNumber : function(revNum) Pad.prototype.getKeyRevisionNumber = function getKeyRevisionNumber(revNum) {
{
return Math.floor(revNum / 100) * 100; return Math.floor(revNum / 100) * 100;
}, };
text : function() Pad.prototype.text = function text() {
{
return this.atext.text; return this.atext.text;
}, };
setText : function(newText) Pad.prototype.setText = function setText(newText) {
{
//clean the new text //clean the new text
newText = exports.cleanText(newText); newText = exports.cleanText(newText);
@ -229,19 +195,17 @@ Class('Pad', {
//append the changeset //append the changeset
this.appendRevision(changeset); this.appendRevision(changeset);
}, };
appendChatMessage: function(text, userId, time) Pad.prototype.appendChatMessage = function appendChatMessage(text, userId, time) {
{
this.chatHead++; this.chatHead++;
//save the chat entry in the database //save the chat entry in the database
db.set("pad:"+this.id+":chat:"+this.chatHead, {"text": text, "userId": userId, "time": time}); db.set("pad:"+this.id+":chat:"+this.chatHead, {"text": text, "userId": userId, "time": time});
//save the new chat head //save the new chat head
db.setSub("pad:"+this.id, ["chatHead"], this.chatHead); db.setSub("pad:"+this.id, ["chatHead"], this.chatHead);
}, };
getChatMessage: function(entryNum, callback) Pad.prototype.getChatMessage = function getChatMessage(entryNum, callback) {
{
var _this = this; var _this = this;
var entry; var entry;
@ -279,10 +243,9 @@ Class('Pad', {
if(ERR(err, callback)) return; if(ERR(err, callback)) return;
callback(null, entry); callback(null, entry);
}); });
}, };
getLastChatMessages: function(count, callback) Pad.prototype.getLastChatMessages = function getLastChatMessages(count, callback) {
{
//return an empty array if there are no chat messages //return an empty array if there are no chat messages
if(this.chatHead == -1) if(this.chatHead == -1)
{ {
@ -340,10 +303,9 @@ Class('Pad', {
callback(null, cleanedEntries); callback(null, cleanedEntries);
}); });
}, };
init : function (text, callback) Pad.prototype.init = function init(text, callback) {
{
var _this = this; var _this = this;
//replace text with default text if text isn't set //replace text with default text if text isn't set
@ -392,9 +354,9 @@ Class('Pad', {
callback(null); callback(null);
}); });
}, };
remove: function(callback)
{ Pad.prototype.remove = function remove(callback) {
var padID = this.id; var padID = this.id;
var _this = this; var _this = this;
@ -483,29 +445,26 @@ Class('Pad', {
{ {
if(ERR(err, callback)) return; if(ERR(err, callback)) return;
callback(); callback();
}) });
}, };
//set in db //set in db
setPublicStatus: function(publicStatus) Pad.prototype.setPublicStatus = function setPublicStatus(publicStatus) {
{
this.publicStatus = publicStatus; this.publicStatus = publicStatus;
db.setSub("pad:"+this.id, ["publicStatus"], this.publicStatus); db.setSub("pad:"+this.id, ["publicStatus"], this.publicStatus);
}, };
setPassword: function(password)
{ Pad.prototype.setPassword = function setPassword(password) {
this.passwordHash = password == null ? null : hash(password, generateSalt()); this.passwordHash = password == null ? null : hash(password, generateSalt());
db.setSub("pad:"+this.id, ["passwordHash"], this.passwordHash); db.setSub("pad:"+this.id, ["passwordHash"], this.passwordHash);
}, };
isCorrectPassword: function(password)
{ Pad.prototype.isCorrectPassword = function isCorrectPassword(password) {
return compare(this.passwordHash, password) return compare(this.passwordHash, password);
}, };
isPasswordProtected: function()
{ Pad.prototype.isPasswordProtected = function isPasswordProtected() {
return this.passwordHash != null; return this.passwordHash != null;
} };
}, // methods
});
/* Crypto helper methods */ /* Crypto helper methods */

View file

@ -20,7 +20,7 @@
var ERR = require("async-stacktrace"); var ERR = require("async-stacktrace");
var customError = require("../utils/customError"); var customError = require("../utils/customError");
require("../db/Pad"); var Pad = require("../db/Pad").Pad;
var db = require("./DB").db; var db = require("./DB").db;
/** /**

View file

@ -326,7 +326,6 @@ function compressJS(values)
var complete = values.join("\n"); var complete = values.join("\n");
var ast = jsp.parse(complete); // parse code and get the initial AST var ast = jsp.parse(complete); // parse code and get the initial AST
ast = pro.ast_mangle(ast); // get a new AST with mangled names ast = pro.ast_mangle(ast); // get a new AST with mangled names
ast = pro.ast_squeeze(ast); // get an AST with compression optimizations
return pro.gen_code(ast); // compressed code here return pro.gen_code(ast); // compressed code here
} }

View file

@ -14,7 +14,6 @@
"socket.io" : "0.8.7", "socket.io" : "0.8.7",
"ueberDB" : "0.1.3", "ueberDB" : "0.1.3",
"async" : "0.1.15", "async" : "0.1.15",
"joose" : "3.50.0",
"express" : "2.5.0", "express" : "2.5.0",
"clean-css" : "0.2.4", "clean-css" : "0.2.4",
"uglify-js" : "1.1.1", "uglify-js" : "1.1.1",