├── lib ├── refresh.js └── simplexml.js ├── capture.gz ├── LICENSE ├── capture.log ├── provider.js ├── README.markdown └── test.js /lib/refresh.js: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /capture.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/creationix/refresh/HEAD/capture.gz -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2022 Tim Caswell 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | 9 | -------------------------------------------------------------------------------- /capture.log: -------------------------------------------------------------------------------- 1 | tim@TimBook:~$ mount_webdav -i http://127.0.0.1:8080/ webdav 2 | Username: admin 3 | Password: 4 | tim@TimBook:~$ cd webdav/ 5 | tim@TimBook:~/webdav$ ls 6 | README.md* _user/ dev/ index.html* sling-logo.png* sling.css* templates/ 7 | _group/ apps/ devwidgets/ sites/ sling-test/ system/ var/ 8 | tim@TimBook:~/webdav$ touch TEST_FILE 9 | tim@TimBook:~/webdav$ vi TEST_FILE 10 | tim@TimBook:~/webdav$ ls 11 | README.md* _group/ apps/ devwidgets/ sites/ sling-test/ system/ var/ 12 | TEST_FILE* _user/ dev/ index.html* sling-logo.png* sling.css* templates/ 13 | tim@TimBook:~/webdav$ ls -lh 14 | total 70 15 | -rwx------ 1 tim staff 812B Feb 23 09:35 README.md* 16 | -rwx------ 1 tim staff 13B Feb 23 15:04 TEST_FILE* 17 | drwx------ 1 tim staff 2.0K Feb 23 15:06 _group/ 18 | drwx------ 1 tim staff 2.0K Feb 23 15:06 _user/ 19 | drwx------ 1 tim staff 2.0K Feb 23 15:06 apps/ 20 | drwx------ 1 tim staff 2.0K Feb 23 15:06 dev/ 21 | drwx------ 1 tim staff 2.0K Feb 23 15:06 devwidgets/ 22 | -rwx------ 1 tim staff 3.0K Feb 23 09:34 index.html* 23 | drwx------ 1 tim staff 2.0K Feb 23 15:06 sites/ 24 | -rwx------ 1 tim staff 6.1K Feb 23 09:34 sling-logo.png* 25 | drwx------ 1 tim staff 2.0K Feb 23 15:06 sling-test/ 26 | -rwx------ 1 tim staff 3.2K Feb 23 09:34 sling.css* 27 | drwx------ 1 tim staff 2.0K Feb 23 15:06 system/ 28 | drwx------ 1 tim staff 2.0K Feb 23 15:06 templates/ 29 | drwx------ 1 tim staff 2.0K Feb 23 15:06 var/ 30 | tim@TimBook:~/webdav$ mv TEST_FILE TEST_FILE2 31 | tim@TimBook:~/webdav$ rm TEST_FILE 32 | rm: TEST_FILE: No such file or directory 33 | tim@TimBook:~/webdav$ rm TEST_FILE2 34 | tim@TimBook:~/webdav$ cd .. 35 | tim@TimBook:~$ umount webdav 36 | -------------------------------------------------------------------------------- /provider.js: -------------------------------------------------------------------------------- 1 | var data = []; 2 | 3 | function find(path) { 4 | if (path === '/' || path === '') { 5 | return data; 6 | } 7 | return path.replace(/[^a-z\/]/g, '').split('/').reduce(function (data, name) { 8 | if (name === "") return data; 9 | return data[name]; 10 | }, data); 11 | } 12 | 13 | module.exports = { 14 | getProp: function (path, name) { 15 | var obj = find(path); 16 | if (name === "getlastmodified") { 17 | return (new Date()).toUTCString(); 18 | } 19 | if (name === "resourcetype") { 20 | return "container"; 21 | } 22 | if (obj.hasOwnProperty(name)) { 23 | return obj[name]; 24 | } 25 | }, 26 | get: function (path) { 27 | var pos = path.lastIndexOf('/'); 28 | var name = path.substr(pos + 1); 29 | path = path.substr(0, pos); 30 | var parent = find(path); 31 | if (parent && parent.hasOwnProperty(name)) { 32 | return parent[name]; 33 | } 34 | }, 35 | put: function (path, contents) { 36 | var pos = path.lastIndexOf('/'); 37 | var name = path.substr(pos + 1); 38 | path = path.substr(0, pos); 39 | var parent = find(path); 40 | if (parent && !parent.hasOwnProperty(name)) { 41 | parent[name] = contents; 42 | return parent[name]; 43 | } 44 | }, 45 | makeCol: function (path) { 46 | path = path.substr(0, path.length - 1); 47 | var pos = path.lastIndexOf('/'); 48 | var name = path.substr(pos + 1); 49 | path = path.substr(0, pos); 50 | var parent = find(path); 51 | if (parent && !parent.hasOwnProperty(name)) { 52 | parent[name] = []; 53 | return parent[name]; 54 | } 55 | }, 56 | del: function (path) { 57 | path = path.substr(0, path.length - 1); 58 | var pos = path.lastIndexOf('/'); 59 | var name = path.substr(pos + 1); 60 | path = path.substr(0, pos); 61 | var parent = find(path); 62 | if (parent && parent.hasOwnProperty(name)) { 63 | delete parent[name]; 64 | return true; 65 | } 66 | }, 67 | data: data 68 | } 69 | 70 | -------------------------------------------------------------------------------- /README.markdown: -------------------------------------------------------------------------------- 1 | # Refresh REST/Webdav for node 2 | 3 | This project will be a module that exposes ANY data source as HTTP. The goals are as follows: 4 | 5 | - Implement GET/PUT/POST/DELETE as typically done in web apps 6 | - Implement enough of WebDav to enable mounting read/write in Finder 7 | - Further implement WebDav for other clients as time allows and need arises. 8 | 9 | The main goal is to make a simple resource provider for web-apps and other http clients. This will work with, but not be tied to [node-persistence][] 10 | 11 | ## RESTful Web Service HTTP methods 12 | 13 |
| Resource | 16 |GET | 17 |PUT | 18 |POST | 19 |DELETE | 20 |
|---|---|---|---|---|
Collection URI, such as http://example.com/resources/ |
23 |
24 | List the members of the collection, complete with their member URIs for further navigation. For example, list all the cars for sale. | 25 |Meaning defined as "replace the entire collection with another collection". | 26 |Create a new entry in the collection where the ID is assigned automatically by the collection. The ID created is usually included as part of the data returned by this operation. | 27 |Meaning defined as "delete the entire collection". | 28 |
Element URI, such as http://example.com/resources/7HOU57Y |
31 |
32 | Retrieve a representation of the addressed member of the collection expressed in an appropriate MIME type | 33 |Update the addressed member of the collection or create it with the specified ID. | 34 |Treats the addressed member as a collection in its own right and creates a new subordinate of it. | 35 |Delete the addressed member of the collection. | 36 | 37 |