itizawa 5 лет назад
Родитель
Сommit
3edf4620f8

+ 2 - 2
src/server/models/attachment.js

@@ -68,11 +68,11 @@ module.exports = function(crowi) {
   };
 
 
-  attachmentSchema.methods.isExpiredExternalUrl = function() {
+  attachmentSchema.methods.isValidExternalUrl = function() {
     if (this.externalUrlExpiredAt == null) {
       return false;
     }
-    return this.externalUrlExpiredAt.getTime() < new Date().getTime();
+    return this.externalUrlExpiredAt.getTime() > new Date().getTime();
   };
 
   return mongoose.model('Attachment', attachmentSchema);

+ 3 - 0
src/server/service/file-uploader/aws.js

@@ -80,6 +80,9 @@ module.exports = function(crowi) {
     if (!this.getIsUploadable()) {
       throw new Error('AWS is not configured.');
     }
+    if (attachment.isValidExternalUrl()) {
+      return res.redirect(attachment.externalUrlCached);
+    }
 
     const s3 = S3Factory();
     const awsConfig = getAwsConfig();

+ 3 - 0
src/server/service/file-uploader/gcs.js

@@ -58,6 +58,9 @@ module.exports = function(crowi) {
     if (!this.getIsUploadable()) {
       throw new Error('GCS is not configured.');
     }
+    if (attachment.isValidExternalUrl()) {
+      return res.redirect(attachment.externalUrlCached);
+    }
 
     const gcs = getGcsInstance();
     const myBucket = gcs.bucket(getGcsBucket());