Procházet zdrojové kódy

Allow overriding the s3 endpoint domain for use with Google Cloud Storage, updated the public URL for files to load through Fastly instead of directly from S3

Michael Strickland před 7 roky
rodič
revize
505621dc6e
1 změnil soubory, kde provedl 7 přidání a 5 odebrání
  1. 7 5
      lib/transports/s3/remote.js

+ 7 - 5
lib/transports/s3/remote.js Zobrazit soubor

@@ -3,7 +3,10 @@ var AWS = require("aws-sdk"),
3 3
 
4 4
 module.exports = function(bucket, storagePath) {
5 5
 
6
-  var s3 = new AWS.S3({ params: { Bucket: bucket } });
6
+  var s3 = new AWS.S3({
7
+    params: { Bucket: bucket },
8
+    endpoint: process.env.S3_ENDPOINT || 's3.amazonaws.com'
9
+  });
7 10
 
8 11
   // Test credentials
9 12
   s3.headBucket({}, function(err){ if (err) { throw err; } });
@@ -12,12 +15,11 @@ module.exports = function(bucket, storagePath) {
12 15
 
13 16
     var params = {
14 17
       Key: storagePath + key,
15
-      Body: fs.createReadStream(source),
16
-      ACL: "public-read"
18
+      Body: fs.createReadStream(source)
17 19
     };
18 20
 
19 21
     // gzipping results in inconsistent file size :(
20
-    s3.upload(params, cb);
22
+    s3.putObject(params, cb);
21 23
 
22 24
   }
23 25
 
@@ -71,7 +73,7 @@ module.exports = function(bucket, storagePath) {
71 73
 
72 74
   // TODO make this more configurable
73 75
   function getURL(id) {
74
-    return "https://s3.amazonaws.com/" + bucket + "/" + storagePath + "video/" + id + ".mp4";
76
+    return "https://" + bucket + "/" + storagePath + "video/" + id + ".mp4";
75 77
   }
76 78
 
77 79
   return {