itizawa 5 лет назад
Родитель
Сommit
2970f01169

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

@@ -71,11 +71,15 @@ module.exports = function(crowi) {
   };
   };
 
 
 
 
-  attachmentSchema.methods.isValidExternalUrl = function() {
-    if (this.externalUrlExpiredAt == null) {
-      return false;
+  attachmentSchema.methods.getValidTemporaryUrl = function() {
+    if (this.temporaryUrlExpiredAt == null) {
+      return null;
     }
     }
-    return this.externalUrlExpiredAt.getTime() > new Date().getTime();
+    // return null when expired url
+    if (this.temporaryUrlExpiredAt.getTime() < new Date().getTime()) {
+      return null;
+    }
+    return this.temporaryUrlCached;
   };
   };
 
 
   attachmentSchema.methods.cashTemporaryUrlByProvideSec = function(temporaryUrl, provideSec) {
   attachmentSchema.methods.cashTemporaryUrlByProvideSec = function(temporaryUrl, provideSec) {

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

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

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

@@ -59,8 +59,9 @@ module.exports = function(crowi) {
     if (!this.getIsUploadable()) {
     if (!this.getIsUploadable()) {
       throw new Error('GCS is not configured.');
       throw new Error('GCS is not configured.');
     }
     }
-    if (attachment.isValidExternalUrl()) {
-      return res.redirect(attachment.externalUrlCached);
+    const temporaryUrl = attachment.getValidTemporaryUrl();
+    if (temporaryUrl != null) {
+      return res.redirect(temporaryUrl);
     }
     }
 
 
     const gcs = getGcsInstance();
     const gcs = getGcsInstance();