|
@@ -35,7 +35,7 @@ var fs = require('fs'),
|
35
|
35
|
@default
|
36
|
36
|
Path to the file where boards will be saved by default
|
37
|
37
|
*/
|
38
|
|
-var HISTORY_FILE = path.join(__dirname, "../server-data/history.txt");
|
|
38
|
+var HISTORY_DIR = path.join(__dirname, "../server-data/");
|
39
|
39
|
|
40
|
40
|
/** @constant
|
41
|
41
|
@type {Number}
|
|
@@ -44,6 +44,7 @@ var HISTORY_FILE = path.join(__dirname, "../server-data/history.txt");
|
44
|
44
|
*/
|
45
|
45
|
var SAVE_INTERVAL = 1000 * 2; //Save every 2 seconds of inactivity
|
46
|
46
|
|
|
47
|
+
|
47
|
48
|
/**
|
48
|
49
|
* Represents a board.
|
49
|
50
|
* @constructor
|
|
@@ -53,14 +54,14 @@ var BoardData = function(name) {
|
53
|
54
|
this.name = name;
|
54
|
55
|
this.board = {};
|
55
|
56
|
this.ready = false;
|
|
57
|
+ this.file = path.join(HISTORY_DIR, "board-" + encodeURIComponent(name) + ".json");
|
56
|
58
|
|
57
|
59
|
//Loads the file. This will emit the "ready" event
|
58
|
|
- this.load(HISTORY_FILE);
|
|
60
|
+ this.load(this.file);
|
59
|
61
|
|
60
|
62
|
this.on("ready", function(){
|
61
|
63
|
that.ready = true;
|
62
|
64
|
});
|
63
|
|
-
|
64
|
65
|
};
|
65
|
66
|
|
66
|
67
|
//Allows to use BoardData.emit() and BoardData.on()
|
|
@@ -157,10 +158,10 @@ BoardData.prototype.delaySave = function (file) {
|
157
|
158
|
};
|
158
|
159
|
|
159
|
160
|
/** Saves the data in the board to a file.
|
160
|
|
- * @param {string} [file=HISTORY_FILE] - Path to the file where the board data will be saved.
|
|
161
|
+ * @param {string} [file=this.file] - Path to the file where the board data will be saved.
|
161
|
162
|
*/
|
162
|
163
|
BoardData.prototype.save = function (file) {
|
163
|
|
- if (!file) file = HISTORY_FILE;
|
|
164
|
+ if (!file) file = this.file;
|
164
|
165
|
var board_txt = JSON.stringify(this.board);
|
165
|
166
|
var that = this;
|
166
|
167
|
fs.writeFile(file, board_txt, function (err) {
|