Merge pull request #381 from booo/master

remove joose as dependency
This commit is contained in:
Peter 'Pita' Martischka 2012-01-31 05:51:55 -08:00
commit be1bd1d12d
3 changed files with 415 additions and 457 deletions

View file

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

View file

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

View file

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