-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed the 'Custom Web Resource' example
- Loading branch information
1 parent
666b6b3
commit d9b3761
Showing
3 changed files
with
58 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,61 @@ | ||
const webFile = require('./js/resource.js'), | ||
webdav = require('webdav-server'); | ||
const webFsManager = require('./js/fsManager.js'), | ||
webFile = require('./js/resource.js'), | ||
webdav = require('webdav-server'), | ||
zlib = require('zlib'), | ||
fs = require('fs'); | ||
|
||
const server = new webdav.WebDAVServer({ | ||
port: 1900 | ||
port: 1900, | ||
autoSave: { | ||
treeFilePath: './data.json', | ||
tempTreeFilePath: './data.tmp.json' | ||
} | ||
}); | ||
|
||
server.addResourceTree([ | ||
new webFile.WebFile('http://unlicense.org/UNLICENSE', 'license.txt'), | ||
new webFile.WebFile('https://github.com/OpenMarshal/npm-WebDAV-Server', 'webdav-server-github.html'), | ||
new webFile.WebFile('http://www.stuffedcupcakes.com/wp-content/uploads/2013/05/Chocolate-Overload.jpg', 'chocolate.jpg') | ||
], (e) => { | ||
if(e) throw e; | ||
fs.readFile('./data.json', (e, data) => { | ||
if(e) | ||
{ | ||
defaultLoad(); | ||
return; | ||
} | ||
|
||
zlib.gunzip(data, (e, data) => { | ||
if(e) | ||
{ | ||
defaultLoad(); | ||
return; | ||
} | ||
data = JSON.parse(data.toString()); | ||
|
||
server.load(data, [ | ||
new webdav.RootFSManager(), | ||
new webFsManager.WebFSManager(), | ||
new webdav.VirtualFSManager() | ||
], (e) => { | ||
if(e) | ||
defaultLoad(); | ||
else | ||
run(); | ||
}) | ||
}) | ||
}) | ||
|
||
function defaultLoad() | ||
{ | ||
server.addResourceTree([ | ||
new webFile.WebFile('http://unlicense.org/UNLICENSE', 'license.txt'), | ||
new webFile.WebFile('https://github.com/OpenMarshal/npm-WebDAV-Server', 'webdav-server-github.html'), | ||
new webFile.WebFile('http://www.stuffedcupcakes.com/wp-content/uploads/2013/05/Chocolate-Overload.jpg', 'chocolate.jpg') | ||
], (e) => { | ||
if(e) throw e; | ||
|
||
run(); | ||
}); | ||
} | ||
|
||
function run() | ||
{ | ||
server.start((s) => { | ||
console.log('Server started on port ' + s.address().port + '.'); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,4 +31,6 @@ module.exports.WebFSManager = function() | |
{ | ||
throw webdav.Errors.InvalidOperation; | ||
} | ||
|
||
return fsManager; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters