-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.js
66 lines (57 loc) · 2.04 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Extend index for folder support. It will redirect to urlencoded path names.
var fs = require('fs');
var settings = require('ep_etherpad-lite/node/utils/Settings');
var padManager = require("ep_etherpad-lite/node/db/PadManager");
var padMessageHandler = require("ep_etherpad-lite/node/handler/PadMessageHandler");
// abs - absolute part of the files path - the project path
var abs = '/tmp/';
if (settings.ep_codepad) {
if (settings.ep_codepad.project_path) {
abs = settings.ep_codepad.project_path;
}
}
var err_msg = {};
//var padManager = require("../ep_etherpad-lite/node/db/PadManager");
exports.padCreate = function(hook, context) {
// get the full path
var path = abs + '/' + context.pad.id;
try {
//fs.exists(path, function(exists) {
// if (exists) {
fs.readFile(path, {
encoding: 'utf-8'
}, function(err, data) {
if (!err) {
console.log("CODEPAD - INIT PAD - read: " + path);
// load file to pad
context.pad.setText(data);
// update client(s)
padManager.getPad(context.pad.id, null, function(error, value) {
if (error) throw error;
padMessageHandler.updatePadClients(value, function() {});
});
} else {
console.log("CODEPAD ERR - INIT PAD FAILED to read: " + path);
var cb = function() {};
err_msg = {
type: 'COLLABROOM',
data: {
type: "CUSTOM",
payload: {
padId: context.pad.id,
from: "fs",
errors: err
}
}
};
padMessageHandler.handleCustomObjectMessage(err_msg, undefined, cb);
//throw err;
}
});
//}
//});
} catch (e) {
console.log(" PadCreate error: " + e);
}
};
//EOF