summaryrefslogtreecommitdiff
path: root/lib/models/revision.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/models/revision.js')
-rw-r--r--lib/models/revision.js43
1 files changed, 33 insertions, 10 deletions
diff --git a/lib/models/revision.js b/lib/models/revision.js
index 8b8eba94..c7360fed 100644
--- a/lib/models/revision.js
+++ b/lib/models/revision.js
@@ -2,7 +2,6 @@
// external modules
var Sequelize = require("sequelize");
-var LZString = require('lz-string');
var async = require('async');
var moment = require('moment');
var childProcess = require('child_process');
@@ -60,19 +59,43 @@ module.exports = function (sequelize, DataTypes) {
defaultValue: Sequelize.UUIDV4
},
patch: {
- type: DataTypes.TEXT
+ type: DataTypes.TEXT,
+ get: function () {
+ return sequelize.processData(this.getDataValue('patch'), "");
+ },
+ set: function (value) {
+ this.setDataValue('patch', sequelize.stripNullByte(value));
+ }
},
lastContent: {
- type: DataTypes.TEXT
+ type: DataTypes.TEXT,
+ get: function () {
+ return sequelize.processData(this.getDataValue('lastContent'), "");
+ },
+ set: function (value) {
+ this.setDataValue('lastContent', sequelize.stripNullByte(value));
+ }
},
content: {
- type: DataTypes.TEXT
+ type: DataTypes.TEXT,
+ get: function () {
+ return sequelize.processData(this.getDataValue('content'), "");
+ },
+ set: function (value) {
+ this.setDataValue('content', sequelize.stripNullByte(value));
+ }
},
length: {
type: DataTypes.INTEGER
},
authorship: {
- type: DataTypes.TEXT
+ type: DataTypes.TEXT,
+ get: function () {
+ return sequelize.processData(this.getDataValue('authorship'), [], JSON.parse);
+ },
+ set: function (value) {
+ this.setDataValue('authorship', value ? JSON.stringify(value) : value);
+ }
}
}, {
classMethods: {
@@ -214,7 +237,7 @@ module.exports = function (sequelize, DataTypes) {
Revision.create({
noteId: note.id,
lastContent: note.content,
- length: LZString.decompressFromBase64(note.content).length,
+ length: note.content.length,
authorship: note.authorship
}).then(function (revision) {
Revision.finishSaveNoteRevision(note, revision, callback);
@@ -223,8 +246,8 @@ module.exports = function (sequelize, DataTypes) {
});
} else {
var latestRevision = revisions[0];
- var lastContent = LZString.decompressFromBase64(latestRevision.content || latestRevision.lastContent);
- var content = LZString.decompressFromBase64(note.content);
+ var lastContent = latestRevision.content || latestRevision.lastContent;
+ var content = note.content;
sendDmpWorker({
msg: 'create patch',
lastDoc: lastContent,
@@ -244,9 +267,9 @@ module.exports = function (sequelize, DataTypes) {
} else {
Revision.create({
noteId: note.id,
- patch: LZString.compressToBase64(patch),
+ patch: patch,
content: note.content,
- length: LZString.decompressFromBase64(note.content).length,
+ length: note.content.length,
authorship: note.authorship
}).then(function (revision) {
// clear last revision content to reduce db size