Przeglądaj źródła

create issueSignedUrl

itizawa 5 lat temu
rodzic
commit
c1b7f6b143
1 zmienionych plików z 18 dodań i 0 usunięć
  1. 18 0
      src/server/service/file-uploader/gcs.js

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

@@ -53,6 +53,24 @@ module.exports = function(crowi) {
       && this.configManager.getConfig('crowi', 'gcs:bucket') != null;
       && this.configManager.getConfig('crowi', 'gcs:bucket') != null;
   };
   };
 
 
+  lib.isReferSignedUrl = function() {
+    // TODO retrieve bool by getConfig
+    return true;
+  };
+
+  lib.issueSignedUrl = function(attachment) {
+    const gcs = getGcsInstance(this.getIsUploadable());
+    const myBucket = gcs.bucket(getGcsBucket());
+    const filePath = getFilePathOnStorage(attachment);
+    const file = myBucket.file(filePath);
+
+    return file.getSignedUrl({
+      action: 'read',
+      expires: Date.now() + 20 * 60 * 1000,
+    });
+
+  };
+
   lib.deleteFile = async function(attachment) {
   lib.deleteFile = async function(attachment) {
     const filePath = getFilePathOnStorage(attachment);
     const filePath = getFilePathOnStorage(attachment);
     return lib.deleteFileByFilePath(filePath);
     return lib.deleteFileByFilePath(filePath);