Explorar o código

create attachment.SECONDS_OF_CASH_EXPIRATION

itizawa %!s(int64=5) %!d(string=hai) anos
pai
achega
473fe47c3d

+ 4 - 0
src/server/models/attachment.js

@@ -13,6 +13,8 @@ const { addSeconds } = require('date-fns');
 const ObjectId = mongoose.Schema.Types.ObjectId;
 
 module.exports = function(crowi) {
+  const SECONDS_OF_CASH_EXPIRATION = 120;
+
   function generateFileHash(fileName) {
     const hash = require('crypto').createHash('md5');
     hash.update(`${fileName}_${Date.now()}`);
@@ -86,5 +88,7 @@ module.exports = function(crowi) {
     return this.save();
   };
 
+  attachmentSchema.statics.SECONDS_OF_CASH_EXPIRATION = SECONDS_OF_CASH_EXPIRATION;
+
   return mongoose.model('Attachment', attachmentSchema);
 };

+ 2 - 2
src/server/service/file-uploader/aws.js

@@ -88,12 +88,12 @@ module.exports = function(crowi) {
     const awsConfig = getAwsConfig();
     const filePath = getFilePathOnStorage(attachment);
 
-    // issue signed url for 30 seconds
+    // issue signed url for 120 seconds
     // https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#getSignedUrl-property
     const params = {
       Bucket: awsConfig.bucket,
       Key: filePath,
-      Expires: 30,
+      Expires: attachment.SECONDS_OF_CASH_EXPIRATION,
     };
     const signedUrl = s3.getSignedUrl('getObject', params);
 

+ 1 - 1
src/server/service/file-uploader/gcs.js

@@ -71,7 +71,7 @@ module.exports = function(crowi) {
     // https://cloud.google.com/storage/docs/access-control/signed-urls
     const signedUrl = await file.getSignedUrl({
       action: 'read',
-      expires: Date.now() + 30 * 1000,
+      expires: Date.now() + attachment.SECONDS_OF_CASH_EXPIRATION * 1000,
     });
 
     try {