mikedeboer / jsDAV

jsDAV allows you to easily add WebDAV support to a NodeJS application. jsDAV is meant to cover the entire standard, and attempts to allow integration using an easy to understand API.
http://www.mikedeboer.nl
MIT License
681 stars 159 forks source link

Passing multiple Trees as array to nodes to WebDAV Server instance? #146

Open joeherold opened 8 years ago

joeherold commented 8 years ago

Is it possible to add an array of multiple tree objects to the node attribute? Idea behind is a CMS business-logic, where in the backend an administrator may define multiple root folders out of a complete tree structure for separate users and groups what they have access to.

// import dependencies
var path = require("path");
var jsDAV = require("jsDAV/lib/jsdav");
var jsDAV_FS_Tree = require("jsDAV/lib/DAV/backends/fs/tree");
var jsDAV_Locks_Backend_FS = require("jsDAV/lib/DAV/plugins/locks/fs");

// file locks
var fileLocks = jsDAV_Locks_Backend_FS.new(__dirname + "/locks/files");

// create an array of trees here
var treeArray = [];
treeArray.push(jsDAV_FS_Tree.new(path.join(__dirname,"/path/to/root1")));
treeArray.push(jsDAV_FS_Tree.new(path.join(__dirname,"/path/to/another/root2")));
treeArray.push(jsDAV_FS_Tree.new(path.join(__dirname,"/path/also/to/another/root3")));

// passing the array... does this work?
jsDAV.createServer({
    node: treeArray, // IS THIS POSSIBLE?
    locksBackend: fileLocks
}, 8000);
joeherold commented 8 years ago

For the connected Client it should look something like this....

mountpoint (mounted drive in e.g. OSX finder)
     ----- root1
     ----- root2
     ----- root3
mikedeboer commented 8 years ago

This is not a tested code flow, but it should be possible: https://github.com/mikedeboer/jsDAV/blob/master/lib/DAV/server.js#L115

This uses https://github.com/mikedeboer/jsDAV/blob/master/lib/DAV/simpleCollection.js and that should work like you describe in your second comment.

If it doesn't work, please show me the terminal output and perhaps a screenshot of your client.

I'm curious :wink:

joeherold commented 8 years ago

Ok. I will try in about an hour. But when I look at your provided link at line 119 a question came up: Does a tree (iTree) implements the iNode features? Probably this will throw an error. But I will check it out. THX

https://github.com/mikedeboer/jsDAV/blob/master/lib/DAV/server.js#L119

joeherold commented 8 years ago

And one more thing I am interested in asking you: how did you solve that node does not react to all http methods. When you make an console.log of

Var http = require("http"); Console.log(http.METHODS);

There are missing plenty of methods you defined in the cors.js.

How did you resolve this? I don't understand it. 🤓

mikedeboer commented 8 years ago

I didn't solve it, NodeJS is just not interested in following standards properly.

joeherold commented 8 years ago

Ah. Ok. Lol. During a discussion I had with a sails.js developer about exact that topic a pull request for the http parser was opened to implement in node http parser directly.

https://github.com/nodejs/node/pull/5601

joeherold commented 8 years ago

But it could be resolved by creating a server based on "net" with a custom http parser instead of using "http" module. But this might be a lot of work...

Net reacts to all requests

dimitarkolev commented 8 years ago

@joeherold did you managed to find a solution for the multiple trees.

dimitarkolev commented 8 years ago

I found a solution. I hope it helps someone else:

        var jsDAV = require("jsDAV/lib/jsdav");
        var jsDAV_Locks_Backend_FS = require("jsDAV/lib/DAV/plugins/locks/fs");
        var jsDAV_FS_Directory = require("jsDAV/lib/DAV/backends/fs/directory")
        jsDAV.createServer({
            node: [jsDAV_FS_Directory.new('/folder1'), jsDAV_FS_Directory.new('/folder2')],
            locksBackend: jsDAV_Locks_Backend_FS.new(__dirname + "/locks/files"),
        }, 8000);
        return Promise.resolve();