From f0c4323dea7444ec6c81ffcbe7ce3a5bffa4b6cd Mon Sep 17 00:00:00 2001 From: "Sebastian.Just" Date: Fri, 5 Sep 2014 09:15:33 -0400 Subject: [PATCH 1/6] Avoid content diposition --- lib/uploadhandler.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/uploadhandler.js b/lib/uploadhandler.js index 3233e86..7bac7c0 100644 --- a/lib/uploadhandler.js +++ b/lib/uploadhandler.js @@ -27,7 +27,7 @@ module.exports = function (options) { this.res.set({ 'Pragma': 'no-cache', 'Cache-Control': 'no-store, no-cache, must-revalidate', - 'Content-Disposition': 'inline; filename="files.json"' + // 'Content-Disposition': 'inline; filename="files.json"' }); }; From 67520a21cddc5b3581ec8800086ba352f217057e Mon Sep 17 00:00:00 2001 From: "Sebastian.Just" Date: Fri, 5 Sep 2014 09:23:06 -0400 Subject: [PATCH 2/6] Undo --- lib/uploadhandler.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/uploadhandler.js b/lib/uploadhandler.js index 7bac7c0..3233e86 100644 --- a/lib/uploadhandler.js +++ b/lib/uploadhandler.js @@ -27,7 +27,7 @@ module.exports = function (options) { this.res.set({ 'Pragma': 'no-cache', 'Cache-Control': 'no-store, no-cache, must-revalidate', - // 'Content-Disposition': 'inline; filename="files.json"' + 'Content-Disposition': 'inline; filename="files.json"' }); }; From 56c640a1c799d2bea9da96d6ca13413f8fcb42b1 Mon Sep 17 00:00:00 2001 From: "Sebastian.Just" Date: Fri, 5 Sep 2014 09:48:44 -0400 Subject: [PATCH 3/6] Content dispostion as it causes a download box on IE8 --- lib/uploadhandler.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/uploadhandler.js b/lib/uploadhandler.js index 3233e86..7bac7c0 100644 --- a/lib/uploadhandler.js +++ b/lib/uploadhandler.js @@ -27,7 +27,7 @@ module.exports = function (options) { this.res.set({ 'Pragma': 'no-cache', 'Cache-Control': 'no-store, no-cache, must-revalidate', - 'Content-Disposition': 'inline; filename="files.json"' + // 'Content-Disposition': 'inline; filename="files.json"' }); }; From ffb0c0a699c50df2f73938d5e22d67466679f73d Mon Sep 17 00:00:00 2001 From: "Sebastian.Just" Date: Wed, 8 Oct 2014 14:25:12 -0400 Subject: [PATCH 4/6] Avoid concurrency issues while the same file-version is created for multiple requests resulting in an overwrite of the files by the last request. --- README.md | 1 + lib/fileinfo.js | 14 ++++++++++---- package.json | 1 + 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 204c7a3..a7bc554 100644 --- a/README.md +++ b/README.md @@ -253,6 +253,7 @@ Other options and their default values: targetDir: uploadDir, targetUrl: uploadUrl, ssl: false, + prefixUuid: false, // Prefix every created file with a UUID. Important if there are multiple node processes working on the same folder (iisnode for example) serving requests hostname: null, // in case your reverse proxy doesn't set Host header // eg 'google.com' maxPostSize: 11000000000, // 11 GB diff --git a/lib/fileinfo.js b/lib/fileinfo.js index 873bcd0..113934b 100644 --- a/lib/fileinfo.js +++ b/lib/fileinfo.js @@ -26,11 +26,17 @@ module.exports = function (options) { // Prevent directory traversal and creating hidden system files: this.name = require('path').basename(this.name).replace(/^\.+/, ''); // Prevent overwriting existing files: - while (fs.existsSync(options.baseDir() + '/' + this.name)) { - this.name = this.name.replace(/(?:(?: \(([\d]+)\))?(\.[^.]+))?$/, function (s, index, ext) { - return ' (' + ((parseInt(index, 10) || 0) + 1) + ')' + (ext || ''); - }); + if (options.prefixUuid) { + this.name = require('uuid').v1() + '_' + this.name; + } else { + while (fs.existsSync(options.baseDir() + '/' + this.name)) { + this.name = this.name.replace(/(?:(?: \(([\d]+)\))?(\.[^.]+))?$/, function (s, index, ext) { + return ' (' + ((parseInt(index, 10) || 0) + 1) + ')' + (ext || ''); + }); + } } + //Touch the file to be sure. Synchronous to have this done before the emit of 'begin' happens + fs.closeSync(fs.openSync(options.baseDir() + '/' + this.name, 'w')); }; FileInfo.prototype.setUrl = function (type, baseUrl) { diff --git a/package.json b/package.json index dc11e0c..298ee4d 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "imagemagick": ">=0.1.2", "lodash": ">= 0.9.2", "mkdirp": ">= 0.3.4", + "uuid": ">=2.0.1", "async": "*" }, "engines": { From 1c6633d502bd73a84e57290619269c0abb26672c Mon Sep 17 00:00:00 2001 From: "Sebastian.Just" Date: Thu, 9 Oct 2014 10:44:36 -0400 Subject: [PATCH 5/6] Create folder appropriatly --- lib/fileinfo.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/fileinfo.js b/lib/fileinfo.js index 113934b..814e7aa 100644 --- a/lib/fileinfo.js +++ b/lib/fileinfo.js @@ -1,4 +1,5 @@ var fs = require('fs'), + mkdirp = require('mkdirp'), _ = require('lodash'); module.exports = function (options) { @@ -36,7 +37,10 @@ module.exports = function (options) { } } //Touch the file to be sure. Synchronous to have this done before the emit of 'begin' happens - fs.closeSync(fs.openSync(options.baseDir() + '/' + this.name, 'w')); + mkdirp(options.baseDir(), function (err) { + if (err) {} + else {fs.closeSync(fs.openSync(options.baseDir() + '/' + this.name, 'w'));} + }); }; FileInfo.prototype.setUrl = function (type, baseUrl) { From 4221a19737a4822f19003effd885c1518f5f14dc Mon Sep 17 00:00:00 2001 From: "Sebastian.Just" Date: Thu, 9 Oct 2014 15:56:20 -0400 Subject: [PATCH 6/6] extract filename --- lib/fileinfo.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/fileinfo.js b/lib/fileinfo.js index 814e7aa..92b8945 100644 --- a/lib/fileinfo.js +++ b/lib/fileinfo.js @@ -37,9 +37,10 @@ module.exports = function (options) { } } //Touch the file to be sure. Synchronous to have this done before the emit of 'begin' happens + var touchFile = options.baseDir() + '/' + this.name; mkdirp(options.baseDir(), function (err) { if (err) {} - else {fs.closeSync(fs.openSync(options.baseDir() + '/' + this.name, 'w'));} + else {fs.closeSync(fs.openSync(touchFile, 'w'));} }); };