Reformat code
This commit is contained in:
parent
5db8da8c23
commit
70f5d6dc35
|
@ -38,7 +38,6 @@ rs.getContainers(function (err, containers) {
|
|||
client.removeFile(container, file, function (err) { });
|
||||
*/
|
||||
|
||||
|
||||
var s3 = StorageService({
|
||||
provider: 'amazon',
|
||||
key: 'your-amazon-key',
|
||||
|
@ -60,13 +59,11 @@ s3.getContainers(function (err, containers) {
|
|||
});
|
||||
});
|
||||
|
||||
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var stream = s3.uploadStream('con1','test.jpg');
|
||||
var stream = s3.uploadStream('con1', 'test.jpg');
|
||||
var input = fs.createReadStream(path.join(__dirname, 'test.jpg')).pipe(stream);
|
||||
|
||||
|
||||
var local = StorageService({
|
||||
provider: 'filesystem',
|
||||
root: path.join(__dirname, 'storage')
|
||||
|
|
|
@ -14,11 +14,11 @@ app.configure(function () {
|
|||
});
|
||||
|
||||
var handler = new StorageService(
|
||||
{
|
||||
{
|
||||
provider: 'amazon',
|
||||
key: 'your-amazon-key',
|
||||
keyId: 'your-amazon-key-id'
|
||||
});
|
||||
});
|
||||
|
||||
app.get('/', function (req, res, next) {
|
||||
res.setHeader('Content-Type', 'text/html');
|
||||
|
|
|
@ -11,16 +11,18 @@ exports.initialize = function (dataSource, callback) {
|
|||
dataSource.connector = connector;
|
||||
dataSource.connector.dataSource = dataSource;
|
||||
|
||||
connector.DataAccessObject = function() {};
|
||||
connector.DataAccessObject = function () {
|
||||
};
|
||||
for (var m in StorageService.prototype) {
|
||||
var method = StorageService.prototype[m];
|
||||
if ('function' === typeof method) {
|
||||
connector.DataAccessObject[m] = method.bind(connector);
|
||||
for(var k in method) {
|
||||
for (var k in method) {
|
||||
connector.DataAccessObject[m][k] = method[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
connector.define = function(model, properties, settings) {};
|
||||
connector.define = function (model, properties, settings) {
|
||||
};
|
||||
};
|
||||
|
|
|
@ -31,7 +31,7 @@ exports.upload = function (provider, req, res, container, cb) {
|
|||
|
||||
part.on('end', function () {
|
||||
var values = fields[part.name];
|
||||
if(values === undefined) {
|
||||
if (values === undefined) {
|
||||
values = [value];
|
||||
fields[part.name] = values;
|
||||
} else {
|
||||
|
@ -53,7 +53,7 @@ exports.upload = function (provider, req, res, container, cb) {
|
|||
self.emit('fileBegin', part.name, file);
|
||||
|
||||
var headers = {};
|
||||
if('content-type' in part.headers) {
|
||||
if ('content-type' in part.headers) {
|
||||
headers['content-type'] = part.headers['content-type'];
|
||||
}
|
||||
var writer = provider.upload({container: container, remote: part.filename});
|
||||
|
@ -61,7 +61,7 @@ exports.upload = function (provider, req, res, container, cb) {
|
|||
var endFunc = function () {
|
||||
self._flushing--;
|
||||
var values = files[part.name];
|
||||
if(values === undefined) {
|
||||
if (values === undefined) {
|
||||
values = [file];
|
||||
files[part.name] = values;
|
||||
} else {
|
||||
|
@ -88,14 +88,14 @@ exports.upload = function (provider, req, res, container, cb) {
|
|||
*/
|
||||
|
||||
part.pipe(writer, { end: false });
|
||||
part.on("end", function() {
|
||||
part.on("end", function () {
|
||||
writer.end();
|
||||
endFunc();
|
||||
});
|
||||
};
|
||||
|
||||
form.parse(req, function (err, _fields, _files) {
|
||||
if(err) {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
}
|
||||
cb && cb(err, {files: files, fields: fields});
|
||||
|
@ -111,13 +111,13 @@ exports.upload = function (provider, req, res, container, cb) {
|
|||
* @param {String} file The file name
|
||||
* @param {Function} cb The callback
|
||||
*/
|
||||
exports.download = function(provider, req, res, container, file, cb) {
|
||||
exports.download = function (provider, req, res, container, file, cb) {
|
||||
var reader = provider.download({
|
||||
container: container || req && req.params.container,
|
||||
remote: file || req && req.params.file
|
||||
});
|
||||
reader.pipe(res);
|
||||
reader.on('error', function(err) {
|
||||
reader.on('error', function (err) {
|
||||
res.send(500, { error: err });
|
||||
});
|
||||
}
|
||||
|
|
|
@ -79,7 +79,7 @@ describe('Storage service', function () {
|
|||
});
|
||||
|
||||
it('should download a file', function (done) {
|
||||
var reader = storageService.downloadStream('c1','f1.txt');
|
||||
var reader = storageService.downloadStream('c1', 'f1.txt');
|
||||
reader.pipe(fs.createWriteStream(path.join(__dirname, 'files/f1_downloaded.txt')));
|
||||
reader.on('end', done);
|
||||
reader.on('error', done);
|
||||
|
|
Loading…
Reference in New Issue