Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix uploader, add deleter and bump version

  • Loading branch information...
commit d543c8ca1791633f859c79a84422cc75898bc6f8 1 parent 7555731
@creationix authored
Showing with 32 additions and 3 deletions.
  1. +23 −0 deleter.js
  2. +1 −1  package.json
  3. +8 −2 uploader.js
View
23 deleter.js
@@ -0,0 +1,23 @@
+var Url = require('url');
+var FS = require('fs');
+var Path = require('path');
+
+module.exports = function deleter(mount, root) {
+ return function (req, res, next) {
+ if (req.method !== "DELETE") return next();
+ if (!req.uri) { req.uri = Url.parse(req.url); }
+ var path = unescape(req.uri.pathname).replace(/\.\.+/g, '.');
+ if (!path || path.substr(0, mount.length) !== mount) {
+ return next();
+ }
+ path = Path.join(root, path.substr(mount.length));
+ FS.unlink(path, function (err) {
+ if (err) {
+ if (err.code == "ENOENT") return next();
+ return next(err);
+ }
+ res.writeHead(200, {});
+ res.end();
+ });
+ };
+}
View
2  package.json
@@ -2,7 +2,7 @@
"name": "creationix",
"description": "Creationix is a meta package for my personal packages",
"tags": ["stack", "creationix", "meta", "sandbox"],
- "version": "0.2.2",
+ "version": "0.2.3",
"author": "Tim Caswell <tim@creationix.com>",
"repository": {
"type": "git",
View
10 uploader.js
@@ -1,11 +1,17 @@
var FS = require('fs'),
- Url = require('url');
+ Url = require('url'),
+ Path = require('path');
module.exports = function setup(mount, root) {
return function handle(req, res, next) {
if (req.method !== "PUT") return next();
if (!req.uri) { req.uri = Url.parse(req.url); }
- var stream = FS.createWriteStream(req.uri.pathname);
+ var path = unescape(req.uri.pathname).replace(/\.\.+/g, '.');
+ if (!path || path.substr(0, mount.length) !== mount) {
+ return next();
+ }
+ path = Path.join(root, path.substr(mount.length));
+ var stream = FS.createWriteStream(path);
stream.on('error', next);
req.pipe(stream);
req.on('end', function () {
Please sign in to comment.
Something went wrong with that request. Please try again.