Skip to content

Commit f0365f2

Browse files
committed
Used the 'autoLoad' method to load the content in the 'customWebResource' example
1 parent fcb22cf commit f0365f2

File tree

1 file changed

+20
-36
lines changed

1 file changed

+20
-36
lines changed

examples/customWebResource/index.js

Lines changed: 20 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const webFsManager = require('./js/fsManager.js'),
22
webFile = require('./js/resource.js'),
3-
webdav = require('webdav-server'),
3+
webdav = require('../../lib/index.js'),
44
zlib = require('zlib'),
55
fs = require('fs');
66

@@ -9,49 +9,33 @@ const server = new webdav.WebDAVServer({
99
autoSave: {
1010
treeFilePath: './data.json',
1111
tempTreeFilePath: './data.tmp.json'
12+
},
13+
autoLoad: {
14+
treeFilePath: './data.json',
15+
fsManagers: [
16+
new webdav.RootFSManager(),
17+
new webFsManager.WebFSManager(),
18+
new webdav.VirtualFSManager()
19+
]
1220
}
1321
});
1422

15-
fs.readFile('./data.json', (e, data) => {
23+
server.autoLoad((e) => {
1624
if(e)
1725
{
18-
defaultLoad();
19-
return;
20-
}
21-
22-
zlib.gunzip(data, (e, data) => {
23-
if(e)
24-
{
25-
defaultLoad();
26-
return;
27-
}
28-
data = JSON.parse(data.toString());
29-
30-
server.load(data, [
31-
new webdav.RootFSManager(),
32-
new webFsManager.WebFSManager(),
33-
new webdav.VirtualFSManager()
26+
server.addResourceTree([
27+
new webFile.WebFile('http://unlicense.org/UNLICENSE', 'license.txt'),
28+
new webFile.WebFile('https://github.com/OpenMarshal/npm-WebDAV-Server', 'webdav-server-github.html'),
29+
new webFile.WebFile('http://www.stuffedcupcakes.com/wp-content/uploads/2013/05/Chocolate-Overload.jpg', 'chocolate.jpg')
3430
], (e) => {
35-
if(e)
36-
defaultLoad();
37-
else
38-
run();
39-
})
40-
})
41-
})
42-
43-
function defaultLoad()
44-
{
45-
server.addResourceTree([
46-
new webFile.WebFile('http://unlicense.org/UNLICENSE', 'license.txt'),
47-
new webFile.WebFile('https://github.com/OpenMarshal/npm-WebDAV-Server', 'webdav-server-github.html'),
48-
new webFile.WebFile('http://www.stuffedcupcakes.com/wp-content/uploads/2013/05/Chocolate-Overload.jpg', 'chocolate.jpg')
49-
], (e) => {
50-
if(e) throw e;
31+
if(e) throw e;
5132

33+
run();
34+
});
35+
}
36+
else
5237
run();
53-
});
54-
}
38+
})
5539

5640
function run()
5741
{

0 commit comments

Comments
 (0)