itizawa 5 лет назад
Родитель
Сommit
f4becfa934
2 измененных файлов с 4 добавлено и 8 удалено
  1. 0 5
      src/server/routes/attachment.js
  2. 4 3
      src/server/service/file-uploader/gcs.js

+ 0 - 5
src/server/routes/attachment.js

@@ -201,11 +201,6 @@ module.exports = function(crowi, app) {
       return fileUploadService.respond(res, attachment);
     }
 
-    if (fileUploadService.isReferSignedUrl()) {
-      const signedUrl = await fileUploadService.issueSignedUrl(attachment);
-      return res.redirect(signedUrl);
-    }
-
     let fileStream;
     try {
       fileStream = await fileUploadService.findDeliveryFile(attachment);

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

@@ -53,12 +53,12 @@ module.exports = function(crowi) {
       && this.configManager.getConfig('crowi', 'gcs:bucket') != null;
   };
 
-  lib.isReferSignedUrl = function() {
+  lib.canRespond = function() {
     // TODO retrieve bool by getConfig
     return true;
   };
 
-  lib.issueSignedUrl = function(attachment) {
+  lib.respond = async function(res, attachment) {
     const gcs = getGcsInstance(this.getIsUploadable());
     const myBucket = gcs.bucket(getGcsBucket());
     const filePath = getFilePathOnStorage(attachment);
@@ -66,11 +66,12 @@ module.exports = function(crowi) {
 
     // issue signed url for 30 seconds
     // https://cloud.google.com/storage/docs/access-control/signed-urls
-    return file.getSignedUrl({
+    const signedUrl = await file.getSignedUrl({
       action: 'read',
       expires: Date.now() + 30 * 1000,
     });
 
+    return res.redirect(signedUrl);
   };
 
   lib.deleteFile = async function(attachment) {