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
dirWatcher = require('./DirectoryWatchServer')
var path = require("path");
function getDirContentsOfRequest(reqthenDo) {
    var baseDir = process.env.WORKSPACE_LK,
        // FIXME we assume that the Lively root is the base of the host /
        reqDir = path.join(baseDir, req.url);
    dirWatcher.getWatchedFiles(dir, function(err, watchState) {
        if (err) { thenDo(err, null); return; }
        var files = Object.keys(watchState)
            .filter(function(p) { return path.dirname(p) === dir; })
            .reduce(function(fileMap, fileName) {
                fileMap[fileName] = watchState[fileName]; }, {});
        thenDo(null, files);
    });
}
// see stat(2)
function isDirectory(stat) { return !!(stat.mode & 0040000); }
function convertFileStatsToDirInfos(fileStatsthenDo) {
    var infos = Object.keys(fileStats).map(function(fn) {
        return {
            name: fn,
            isDirectory: isDirectory(fileStats[fn]),
            lastModfied: fileStats[fn].mtime
        }
    });
    thenDo(null, infos);
}
function getDirInfosForRequest(reqthenDo) {
    getDirContentsOfRequest(req, function(err, namesAndStats) {
        if (err) { thenDo(err, null); return; }
        convertFileStatsToDirInfos(namesAndStats, thenDo);
    })
}
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
function findDirectoryListRoute(appthenDo) {
    var found = app.routes.get.reduce(function(found, ea) {
        if (found) return found;
        if (ea.callbacks.some(function(ea) { return !!ea.isLivelyDirectoryRoute; })) 
return ea;
        return null;
    }, null);
    thenDo(null, found);
}
function removeExistingDirectoryListRoute(appthenDo) {
    findDirectoryListRoute(app, function(err, route) {
        if (route) {
            var i = app.routes.get.indexOf(route);
X
ServerWorkspace -- http://lively-web.org/nodejs/NodeJSEvalServer/
X

Menu