Comparing version 0.1.2 to 0.1.3
@@ -29,11 +29,2 @@ // fileserver | ||
}); | ||
app.setModifyOut = function(func) { | ||
if (typeof func !== 'function') { | ||
throw new Error('should be function'); | ||
} | ||
modifyOut = func; | ||
}; | ||
app.unsetModifyOut = function(func) { | ||
modifyOut = null; | ||
}; | ||
return app; | ||
@@ -80,3 +71,3 @@ }; | ||
for (var i = files.length - 1; i >= 0; i--) { | ||
files[i] = formatOutData(files[i]); | ||
files[i] = formatOutData(req, files[i]); | ||
} | ||
@@ -159,3 +150,3 @@ res.json(files); | ||
fileDriver.move(dirPath, req.body.newPath, options, | ||
sendCode(200, req, res, next, formatOutData(dirPath))); | ||
sendCode(200, req, res, next, formatOutData(req, dirPath))); | ||
return; | ||
@@ -167,3 +158,3 @@ } | ||
fileDriver.mkdir(dirPath, mode, | ||
sendCode(201, req, res, next, formatOutData(dirPath))); | ||
sendCode(201, req, res, next, formatOutData(req, dirPath))); | ||
} else { | ||
@@ -174,3 +165,3 @@ options.encoding = req.body.encoding || 'utf8'; | ||
fileDriver.writeFile(dirPath, data, options, | ||
sendCode(201, req, res, next, formatOutData(dirPath))); | ||
sendCode(201, req, res, next, formatOutData(req, dirPath))); | ||
} | ||
@@ -202,3 +193,3 @@ }; | ||
fileDriver.mkdir(dirPath, mode, | ||
sendCode(201, req, res, next, formatOutData(dirPath))); | ||
sendCode(201, req, res, next, formatOutData(req, dirPath))); | ||
} else { | ||
@@ -209,3 +200,3 @@ options.encoding = req.body.encoding || 'utf8'; | ||
fileDriver.writeFile(dirPath, data, options, | ||
sendCode(201, req, res, next, formatOutData(dirPath))); | ||
sendCode(201, req, res, next, formatOutData(req, dirPath))); | ||
} | ||
@@ -228,9 +219,9 @@ }; | ||
if (err && err.code === 'ENOENT') { | ||
sendCode(404, req, res, next, formatOutData(dirPath))(null); | ||
sendCode(404, req, res, next, formatOutData(req, dirPath))(null); | ||
} else if (err && err.code === 'EPERM') { | ||
sendCode(403, req, res, next, formatOutData(dirPath))(null); | ||
sendCode(403, req, res, next, formatOutData(req, dirPath))(null); | ||
} else if (err && err.code === 'ENOTDIR') { | ||
sendCode(400, req, res, next, formatOutData(dirPath))(null); | ||
sendCode(400, req, res, next, formatOutData(req, dirPath))(null); | ||
} else { | ||
sendCode(200, req, res, next, formatOutData(dirPath))(err); | ||
sendCode(200, req, res, next, formatOutData(req, dirPath))(err); | ||
} | ||
@@ -251,9 +242,9 @@ }); | ||
if (err && err.code === 'ENOENT') { | ||
sendCode(404, req, res, next, formatOutData(dirPath))(null); | ||
sendCode(404, req, res, next, formatOutData(req, dirPath))(null); | ||
} else if (err && err.code === 'EPERM') { | ||
sendCode(403, req, res, next, formatOutData(dirPath))(null); | ||
sendCode(403, req, res, next, formatOutData(req, dirPath))(null); | ||
} else if (err && err.code === 'EISDIR') { | ||
sendCode(400, req, res, next, formatOutData(dirPath))(null); | ||
sendCode(400, req, res, next, formatOutData(req, dirPath))(null); | ||
} else { | ||
sendCode(200, req, res, next, formatOutData(dirPath))(err); | ||
sendCode(200, req, res, next, formatOutData(req, dirPath))(err); | ||
} | ||
@@ -266,6 +257,6 @@ }); | ||
// formats out data based on client spec. | ||
var formatOutData = function (filepath) { | ||
var formatOutData = function (req, filepath) { | ||
var out = filepath; | ||
if (modifyOut) { | ||
out = modifyOut(out); | ||
if (typeof req.modifyOut === 'function') { | ||
out = req.modifyOut(out); | ||
} | ||
@@ -272,0 +263,0 @@ return out; |
{ | ||
"name": "rest-fs", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "restful fileserver", | ||
@@ -5,0 +5,0 @@ "main": "fileserver.js", |
@@ -31,2 +31,4 @@ rest-fs | ||
To use programmatically, pass in the app into restfs and it will add the routes. | ||
you can attach a function to modifyOut to manipulate file output. | ||
the function has one argument which is the full filepath and should return path to return | ||
@@ -40,3 +42,3 @@ API | ||
list contents of directory | ||
*optional*<br> | ||
@@ -50,3 +52,3 @@ ?recursive = list recursively default false | ||
"name" : "file1", // name of dir or file | ||
"path" : "/path/to/file", // path to dir or file | ||
"path" : "/path/to/file", // path to dir or file | ||
"dir" : false // true if directory | ||
@@ -62,3 +64,3 @@ }, | ||
if dir, redirect to dir path | ||
*optional*<br> | ||
@@ -88,3 +90,3 @@ ?encoding = default utf8 | ||
"name" : "file1", // name of dir or file | ||
"path" : "/path/to/file", // path to dir or file | ||
"path" : "/path/to/file", // path to dir or file | ||
"dir" : false // true if directory | ||
@@ -95,3 +97,3 @@ } | ||
PUT /path/to/file | ||
----------------- | ||
----------------- | ||
creates file | ||
@@ -107,3 +109,3 @@ | ||
"name" : "file1", // name of dir or file | ||
"path" : "/path/to/file", // path to dir or file | ||
"path" : "/path/to/file", // path to dir or file | ||
"dir" : false // true if directory | ||
@@ -114,7 +116,7 @@ } | ||
DEL /path/to/dir/ | ||
----------------- | ||
----------------- | ||
deletes folder<br> | ||
if file returns error | ||
returns: | ||
returns: | ||
``` | ||
@@ -125,9 +127,9 @@ {} | ||
DEL /path/to/file | ||
----------------- | ||
----------------- | ||
deletes file<br> | ||
if folder returns error | ||
returns: | ||
returns: | ||
``` | ||
{} | ||
``` |
@@ -428,10 +428,15 @@ var Lab = require('lab'); | ||
Lab.test('test setModifyOut', function (done) { | ||
server.setModifyOut(function (file) { | ||
return 'anand'; | ||
var server2 = express(); | ||
server2.use(function(req, res, next) { | ||
req.modifyOut = function (file) { | ||
return 'anand'; | ||
}; | ||
next(); | ||
}); | ||
supertest(server) | ||
var restfs = require('../fileserver.js'); | ||
restfs(server2); | ||
supertest(server2) | ||
.get(dir2) | ||
.expect(200) | ||
.end(function(err, res){ | ||
server.unsetModifyOut(); | ||
if (err) { | ||
@@ -438,0 +443,0 @@ return done(err); |
@@ -18,9 +18,2 @@ var Lab = require('lab'); | ||
}); | ||
Lab.test('test invalid setModifyOut', function (done) { | ||
try { | ||
server.setModifyOut("fake"); | ||
} catch (err) { | ||
done(); | ||
} | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
57056
126
1595