Merge pull request #139 from strongloop/globalization

Add Globalization.
This commit is contained in:
Richard Pringle 2016-08-05 15:14:50 -04:00 committed by GitHub
commit eb4e4b202b
6 changed files with 35 additions and 11 deletions

4
.gitignore vendored
View File

@ -15,3 +15,7 @@ npm-debug.log
.idea .idea
node_modules node_modules
providers-private.json providers-private.json
!intl/
intl/*
!intl/en/

View File

@ -3,6 +3,9 @@
// This file is licensed under the Artistic License 2.0. // This file is licensed under the Artistic License 2.0.
// License text available at https://opensource.org/licenses/Artistic-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'); var StorageConnector = require('./lib/storage-connector');
StorageConnector.StorageService = require('./lib/storage-service'); StorageConnector.StorageService = require('./lib/storage-service');

10
intl/en/messages.json Normal file
View File

@ -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"
}

View File

@ -3,6 +3,9 @@
// This file is licensed under the Artistic License 2.0. // This file is licensed under the Artistic License 2.0.
// License text available at https://opensource.org/licenses/Artistic-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 * File system based on storage provider
*/ */
@ -27,11 +30,11 @@ function FileSystemProvider(options) {
this.root = options.root; this.root = options.root;
var exists = fs.existsSync(this.root); var exists = fs.existsSync(this.root);
if (!exists) { 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));
} }
var stat = fs.statSync(this.root); var stat = fs.statSync(this.root);
if (!stat.isDirectory()) { if (!stat.isDirectory()) {
throw new Error('FileSystemProvider: Invalid directory: ' + this.root); throw new Error(g.f('{{FileSystemProvider}}: Invalid directory: %s', this.root));
} }
} }
@ -39,9 +42,9 @@ var namePattern = new RegExp('[^' + path.sep + '/]+');
function validateName(name, cb) { function validateName(name, cb) {
if (!name) { 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) { if (!cb) {
console.error('FileSystemProvider: Invalid name: ', name); console.error(g.f('{{FileSystemProvider}}: Invalid name: %s', name));
} }
return false; return false;
} }
@ -50,9 +53,9 @@ function validateName(name, cb) {
return true; return true;
} else { } else {
cb && process.nextTick(cb.bind(null, cb && process.nextTick(cb.bind(null,
new Error('FileSystemProvider: Invalid name: ' + name))); new Error(g.f('{{FileSystemProvider}}: Invalid name: %s', name))));
if (!cb) { if (!cb) {
console.error('FileSystemProvider: Invalid name: ', name); console.error(g.f('{{FileSystemProvider}}: Invalid name: ', name));
} }
return false; return false;
} }

View File

@ -3,6 +3,9 @@
// This file is licensed under the Artistic License 2.0. // This file is licensed under the Artistic License 2.0.
// License text available at https://opensource.org/licenses/Artistic-2.0 // License text available at https://opensource.org/licenses/Artistic-2.0
// Globalization
var g = require('strong-globalize')();
var IncomingForm = require('formidable'); var IncomingForm = require('formidable');
var StringDecoder = require('string_decoder').StringDecoder; var StringDecoder = require('string_decoder').StringDecoder;
var path = require('path'); var path = require('path');
@ -43,7 +46,7 @@ exports.upload = function(provider, req, res, options, cb) {
part.on('data', function(buffer) { part.on('data', function(buffer) {
self._fieldsSize += buffer.length; self._fieldsSize += buffer.length;
if (self._fieldsSize > self.maxFieldsSize) { 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; return;
} }
value += decoder.write(buffer); value += decoder.write(buffer);
@ -88,7 +91,7 @@ exports.upload = function(provider, req, res, options, cb) {
} }
if (Array.isArray(allowedContentTypes) && allowedContentTypes.length !== 0) { if (Array.isArray(allowedContentTypes) && allowedContentTypes.length !== 0) {
if (allowedContentTypes.indexOf(file.type) === -1) { 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; return;
} }
} }
@ -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. // 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 // - 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 // - 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; return;
} }
}); });

View File

@ -7,9 +7,10 @@
"test": "./node_modules/.bin/mocha --timeout 30000 test/*test.js" "test": "./node_modules/.bin/mocha --timeout 30000 test/*test.js"
}, },
"dependencies": { "dependencies": {
"pkgcloud": "^1.1.0",
"async": "^0.9.0", "async": "^0.9.0",
"formidable": "^1.0.16" "formidable": "^1.0.16",
"pkgcloud": "^1.1.0",
"strong-globalize": "^2.6.2"
}, },
"devDependencies": { "devDependencies": {
"express": "^4.11.0", "express": "^4.11.0",