提交 f5f1cf0d6f7f34276f1b8ab48ba284e0bef0ec3d

作者 Nick Baugh
1 个父辈 c4eac114

Added WIP, needs revised

  1 +
  2 +// # knox client
  3 +
  4 +var _ = require('underscore');
  5 +var util = require('util');
  6 +var knox = require('knox');
  7 +
  8 +exports = module.exports = function(settings) {
  9 +
  10 + if (!_.isObject(settings.knox))
  11 + throw new Error('Settings did not have a `knox` object');
  12 +
  13 + // bucket, key, and secret
  14 + _.each(['bucket', 'key', 'secret'], function(str) {
  15 + if (!_.isString(settings.knox[str]))
  16 + throw new Error(util.format('Settings did not have a `settings.knox.%s` string', str));
  17 + });
  18 +
  19 + return knox.createClient(settings.knox);
  20 +
  21 +};
  22 +
  23 +exports['@singleton'] = true;
  24 +exports['@require'] = [ 'igloo/settings' ];
  1 +
  2 +// # Amazon S3 Stream Upload
  3 +
  4 +var mergeDefaults = require('merge-defaults');
  5 +var _ = require('underscore');
  6 +var util = require('util');
  7 +var AWS = require('aws-sdk');
  8 +var s3UploadStream = require('s3-upload-stream');
  9 +
  10 +exports = module.exports = function(settings, logger) {
  11 +
  12 + if (!_.isObject(settings.aws))
  13 + throw new Error('Settings did not have an `aws` object');
  14 +
  15 + // accessKeyId, secretAccessKey, bucket
  16 + _.each([ 'accessKeyId', 'secretAccessKey', 'bucket' ], function(str) {
  17 + if (!_.isString(settings.aws[str]))
  18 + throw new Error(util.format('Settings did not have a `settings.aws.%s` string', str));
  19 + });
  20 +
  21 + AWS.config.update(settings.aws);
  22 + AWS.config.update({ logger: logger });
  23 +
  24 + function setHeaders(headers) {
  25 +
  26 + if (!_.isObject(headers))
  27 + headers = {};
  28 +
  29 + headers = mergeDefaults({
  30 + Bucket: settings.aws.bucket
  31 + }, headers);
  32 +
  33 + var s3Stream = s3UploadStream(new AWS.S3());
  34 +
  35 + var upload = s3Stream.upload(headers);
  36 +
  37 + return upload;
  38 +
  39 + }
  40 +
  41 + return setHeaders;
  42 +
  43 +};
  44 +
  45 +exports['@singleton'] = true;
  46 +exports['@require'] = [ 'igloo/settings', 'igloo/logger' ];
@@ -34,6 +34,7 @@ @@ -34,6 +34,7 @@
34 "connect-redis": "~2.0.0", 34 "connect-redis": "~2.0.0",
35 "email-templates": "^1.1.2", 35 "email-templates": "^1.1.2",
36 "express-session": "^1.2.1", 36 "express-session": "^1.2.1",
  37 + "knox": "^0.9.1",
37 "merge-defaults": "^0.1.0", 38 "merge-defaults": "^0.1.0",
38 "nodemailer": "^1.3.0", 39 "nodemailer": "^1.3.0",
39 "slack-winston": "^0.0.1", 40 "slack-winston": "^0.0.1",
注册登录 后发表评论