Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ npm-debug.log
.idea
node_modules
providers-private.json

!intl/
intl/*
!intl/en/
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
// This file is licensed under the Artistic License 2.0.
// License text available at https://opensource.org/licenses/Artistic-2.0

var SG = require('strong-globalize');
SG.SetRootDir(__dirname);

var StorageConnector = require('./lib/storage-connector');
StorageConnector.StorageService = require('./lib/storage-service');

Expand Down
10 changes: 10 additions & 0 deletions intl/en/messages.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"2eb418c4dc7f7a3e989bb71a8f5388d7": "{{FileSystemProvider}}: Path does not exist: {0}",
"6af59b6408b92f4c6b13a2c9b06379f2": "{{FileSystemProvider}}: Invalid name: {0}",
"95065f7f9499f75f49e3714aa4e2031d": "{{FileSystemProvider}}: Invalid name: ",
"c9fb0aba850059a14f4ed5e045e4ec3e": "Invalid name: {0}",
"f589fe721f4e6fa112d1f66081ed29ac": "{{FileSystemProvider}}: Invalid directory: {0}",
"45c1c136e750c62179d75a1c99151281": "{{maxFileSize}} exceeded, received {0} bytes of field data (max is {1})",
"78f6f36e8300e15cff778496fb1dd178": "{{contentType}} \"{0}\" is not allowed (Must be in [{1}])",
"b8a9e184534171cf66caf58d29ad76f5": "{{maxFieldsSize}} exceeded, received {0} bytes of field data"
}
15 changes: 9 additions & 6 deletions lib/providers/filesystem/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
// This file is licensed under the Artistic License 2.0.
// License text available at https://opensource.org/licenses/Artistic-2.0

// Globalization
var g = require('strong-globalize')();

/**
* File system based on storage provider
*/
Expand All @@ -27,21 +30,21 @@ function FileSystemProvider(options) {
this.root = options.root;
var exists = fs.existsSync(this.root);
if (!exists) {
throw new Error('FileSystemProvider: Path does not exist: ' + this.root);
throw new Error(g.f('{{FileSystemProvider}}: Path does not exist: %s', this.root));
}
Copy link
Copy Markdown
Contributor

@0candy 0candy Jul 26, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should add brackets {{FileSystemProvider}} for strings that don't need to be translated.

var stat = fs.statSync(this.root);
if (!stat.isDirectory()) {
throw new Error('FileSystemProvider: Invalid directory: ' + this.root);
throw new Error(g.f('{{FileSystemProvider}}: Invalid directory: %s', this.root));
}
}

var namePattern = new RegExp('[^' + path.sep + '/]+');

function validateName(name, cb) {
if (!name) {
cb && process.nextTick(cb.bind(null, new Error('Invalid name: ' + name)));
cb && process.nextTick(cb.bind(null, new Error(g.f('Invalid name: %s', name))));
if (!cb) {
console.error('FileSystemProvider: Invalid name: ', name);
console.error(g.f('{{FileSystemProvider}}: Invalid name: %s', name));
}
return false;
}
Expand All @@ -50,9 +53,9 @@ function validateName(name, cb) {
return true;
} else {
cb && process.nextTick(cb.bind(null,
new Error('FileSystemProvider: Invalid name: ' + name)));
new Error(g.f('{{FileSystemProvider}}: Invalid name: %s', name))));
if (!cb) {
console.error('FileSystemProvider: Invalid name: ', name);
console.error(g.f('{{FileSystemProvider}}: Invalid name: ', name));
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

return false;
}
Expand Down
9 changes: 6 additions & 3 deletions lib/storage-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
// This file is licensed under the Artistic License 2.0.
// License text available at https://opensource.org/licenses/Artistic-2.0

// Globalization
var g = require('strong-globalize')();

var IncomingForm = require('formidable');
var StringDecoder = require('string_decoder').StringDecoder;
var path = require('path');
Expand Down Expand Up @@ -43,7 +46,7 @@ exports.upload = function(provider, req, res, options, cb) {
part.on('data', function(buffer) {
self._fieldsSize += buffer.length;
if (self._fieldsSize > self.maxFieldsSize) {
self._error(new Error('maxFieldsSize exceeded, received ' + self._fieldsSize + ' bytes of field data'));
self._error(new Error(g.f('{{maxFieldsSize}} exceeded, received %s bytes of field data', self._fieldsSize)));
return;
}
value += decoder.write(buffer);
Expand Down Expand Up @@ -88,7 +91,7 @@ exports.upload = function(provider, req, res, options, cb) {
}
if (Array.isArray(allowedContentTypes) && allowedContentTypes.length !== 0) {
if (allowedContentTypes.indexOf(file.type) === -1) {
self._error(new Error('contentType "' + file.type + '" is not allowed (Must be in [' + allowedContentTypes.join(', ') + '])'));
self._error(new Error(g.f('{{contentType}} "%s" is not allowed (Must be in [%s])', file.type, allowedContentTypes.join(', '))));
return;
}
}
Expand Down Expand Up @@ -155,7 +158,7 @@ exports.upload = function(provider, req, res, options, cb) {
// We are missing some way to tell the provider to cancel upload/multipart upload of the current file.
// - s3-upload-stream doesn't provide a way to do this in it's public interface
// - We could call provider.delete file but it would not delete multipart data
self._error(new Error('maxFileSize exceeded, received ' + fileSize + ' bytes of field data (max is ' + maxFileSize + ')'));
self._error(new Error(g.f('{{maxFileSize}} exceeded, received %s bytes of field data (max is %s)', fileSize, maxFileSize)));
return;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should add brackets {{maxFileSize}}

}
});
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
"test": "./node_modules/.bin/mocha --timeout 30000 test/*test.js"
},
"dependencies": {
"pkgcloud": "^1.1.0",
"async": "^0.9.0",
"formidable": "^1.0.16"
"formidable": "^1.0.16",
"pkgcloud": "^1.1.0",
"strong-globalize": "^2.6.2"
},
"devDependencies": {
"express": "^4.11.0",
Expand Down