Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
putStream: function(handler, type, callback) {
var path = this.path;
// is it a chunked upload?
var size = handler.httpRequest.headers["x-file-size"];
if (size && size !== "undefined") {
var parts = Util.splitPath(this.path);
if (!handler.httpRequest.headers["x-file-name"])
handler.httpRequest.headers["x-file-name"] = parts[1];
handler.server.tree.getNodeForPath(parts[0], function(err, parent) {
if (err)
return callback(err);
parent.writeFileChunk(handler, type, callback);
});
}
else {
this.vfs.mkfile(path, {}, function(err, meta) {
if (err) {
if (err.code == "EACCES")
err = new Exc.Forbidden("Permission denied to write file:" + path);
return callback(err);
}
copy: function(source, destination, callback) {
var self = this;
source = this.getRealPath(source);
destination = this.getRealPath(destination);
if (!this.insideSandbox(destination)) {
return callback(new Exc.Forbidden("You are not allowed to copy to " +
this.stripSandbox(destination)));
}
// first check if source exists
this.vfs.stat(source, {}, function(err, stat) {
if (err || stat.err)
return callback(err);
// if destination exists try to delete it
self.vfs.rmdir(destination, { recursive: true }, function(err) {
// ignore error because destination may not exists
self.vfs.execFile("cp", {args: ["-R", source, destination]}, callback);
});
});
},
this.vfs.stat(path, {}, function(err, stat) {
console.log("stat", err, stat);
if (err || !stat) {
return callback(new Exc.FileNotFound("File at location "
+ self.path + " not found"));
}
self.$stat = stat;
callback(null, stat);
});
},
var Filewatch = module.exports = function(options) {
var self = this;
var plugin = jsDAV_ServerPlugin.extend({
initialize: function(handler) {
jsDAV_ServerPlugin.new(this, handler);
handler.addEventListener("afterWriteContent", function(e, uri) {
self.emit("afterWrite", {
file: "/" + uri
});
e.next();
});
handler.addEventListener("afterDelete", function(e, uri) {
self.emit("afterDelete", {
file: "/" + uri
});
e.next();
initialize: function(handler) {
jsDAV_ServerPlugin.new(this, handler);
handler.addEventListener("afterWriteContent", function(e, uri) {
self.emit("afterWrite", {
file: "/" + uri
});
e.next();
});
handler.addEventListener("afterDelete", function(e, uri) {
self.emit("afterDelete", {
file: "/" + uri
});
e.next();
});
handler.addEventListener("afterMove", function(e, uri) {
this._stat(path, function(err, stat) {
if (err)
return callback(new Exc.FileNotFound("File at location " + path + " not found"));
callback(null, stat.mime == "inode/directory"
? new jsDAV_FS_Directory(self.vfs, path, stat)
: new jsDAV_FS_File(self.vfs, path, stat)
);
});
},
this.vfs.stat(path, {}, function(err, stat) {
if (err)
return callback(new Exc.FileNotFound("File at location " + path + " not found"));
callback(null, stat.mime == "inode/directory"
? jsDAV_FS_Directory.new(self.vfs, path, stat)
: jsDAV_FS_File.new(self.vfs, path, stat)
);
});
},
getName: function() {
return Util.splitPath(this.path)[1];
},
setName: function(name, callback) {
var parentPath = Util.splitPath(this.path)[0];
var newName = Util.splitPath(name)[1];
var newPath = parentPath + "/" + newName;
var self = this;
this.vfs.rename(newPath, {from: this.path}, function(err) {
if (err)
return callback(err);
self.path = newPath;
callback();
});
},
var jsDAV_ServerPlugin = require("@pylonide/jsdav/lib/DAV/plugin");
var util = require("util");
var Permission = module.exports = jsDAV_ServerPlugin.extend({
/**
* Plugin name
*
* @var String
*/
name: "permission",
initialize: function(handler) {
jsDAV_ServerPlugin.new(this, handler);
this.handler = handler;
handler.addEventListener("beforeMethod", this.checkPermission.bind(this));
},
READ_METHODS: {
"OPTIONS":1,