Просмотр исходного кода

deactive content headers when the uploader implementation generates a temporaryUrl or processes a delegated response

Yuki Takei 2 лет назад
Родитель
Сommit
f29ef07ba7

+ 4 - 5
apps/app/src/server/service/file-uploader/aws.ts

@@ -190,7 +190,6 @@ class AwsFileUploader extends AbstractFileUploader {
       throw new Error('AWS is not configured.');
     }
 
-    const isDownload = opts?.download ?? false;
 
     const s3 = S3Factory();
     const awsConfig = getAwsConfig();
@@ -199,13 +198,13 @@ class AwsFileUploader extends AbstractFileUploader {
 
     // issue signed url (default: expires 120 seconds)
     // https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#getSignedUrl-property
-    const contentHeaders = new ContentHeaders(attachment, { inline: !isDownload });
-    const { contentType, contentDisposition } = contentHeaders;
+    // const isDownload = opts?.download ?? false;
+    // const contentHeaders = new ContentHeaders(attachment, { inline: !isDownload });
     const params: GetObjectCommandInput = {
       Bucket: awsConfig.bucket,
       Key: filePath,
-      ResponseContentType: contentType?.value.toString(),
-      ResponseContentDisposition: contentDisposition?.value.toString(),
+      // ResponseContentType: contentHeaders.contentType?.value.toString(),
+      // ResponseContentDisposition: contentHeaders.contentDisposition?.value.toString(),
     };
     const signedUrl = await getSignedUrl(s3, new GetObjectCommand(params), {
       expiresIn: lifetimeSecForTemporaryUrl,

+ 2 - 3
apps/app/src/server/service/file-uploader/azure.ts

@@ -171,8 +171,6 @@ class AzureFileUploader extends AbstractFileUploader {
       throw new Error('Azure Blob is not configured.');
     }
 
-    const isDownload = opts?.download ?? false;
-
     const containerClient = await getContainerClient();
     const filePath = getFilePathOnStorage(attachment);
     const blockBlobClient = await containerClient.getBlockBlobClient(filePath);
@@ -182,7 +180,8 @@ class AzureFileUploader extends AbstractFileUploader {
     const signedUrl = `${blockBlobClient.url}?${sasToken}`;
 
     // TODO: re-impl using generateSasUrl
-    const contentHeaders = new ContentHeaders(attachment, { inline: !isDownload });
+    // const isDownload = opts?.download ?? false;
+    // const contentHeaders = new ContentHeaders(attachment, { inline: !isDownload });
     // const signedUrl = blockBlobClient.generateSasUrl({
     //   contentType: contentHeaders.contentType?.value.toString(),
     //   contentDisposition: contentHeaders.contentDisposition?.value.toString(),

+ 4 - 5
apps/app/src/server/service/file-uploader/gcs.ts

@@ -137,8 +137,6 @@ class GcsFileUploader extends AbstractFileUploader {
       throw new Error('GCS is not configured.');
     }
 
-    const isDownload = opts?.download ?? false;
-
     const gcs = getGcsInstance();
     const myBucket = gcs.bucket(getGcsBucket());
     const filePath = getFilePathOnStorage(attachment);
@@ -147,12 +145,13 @@ class GcsFileUploader extends AbstractFileUploader {
 
     // issue signed url (default: expires 120 seconds)
     // https://cloud.google.com/storage/docs/access-control/signed-urls
-    const contentHeaders = new ContentHeaders(attachment, { inline: true });
+    // const isDownload = opts?.download ?? false;
+    // const contentHeaders = new ContentHeaders(attachment, { inline: !isDownload });
     const [signedUrl] = await file.getSignedUrl({
       action: 'read',
       expires: Date.now() + lifetimeSecForTemporaryUrl * 1000,
-      responseType: contentHeaders.contentType?.value.toString(),
-      responseDisposition: contentHeaders.contentDisposition?.value.toString(),
+      // responseType: contentHeaders.contentType?.value.toString(),
+      // responseDisposition: contentHeaders.contentDisposition?.value.toString(),
     });
 
     return {

+ 4 - 3
apps/app/src/server/service/file-uploader/local.ts

@@ -211,16 +211,17 @@ module.exports = function(crowi) {
    * @param {Response} res
    * @param {Response} attachment
    */
-  lib.respond = function(res, attachment) {
+  lib.respond = function(res, attachment, opts) {
     // Responce using internal redirect of nginx or Apache.
     const storagePath = getFilePathOnStorage(attachment);
     const relativePath = path.relative(crowi.publicDir, storagePath);
     const internalPathRoot = configManager.getConfig('crowi', 'fileUpload:local:internalRedirectPath');
     const internalPath = urljoin(internalPathRoot, relativePath);
 
-    const contentHeaders = new ContentHeaders(attachment, { inline: true });
+    // const isDownload = opts?.download ?? false;
+    // const contentHeaders = new ContentHeaders(attachment, { inline: !isDownload });
     applyHeaders(res, [
-      ...contentHeaders.toExpressHttpHeaders(),
+      // ...contentHeaders.toExpressHttpHeaders(),
       { field: 'X-Accel-Redirect', value: internalPath },
       { field: 'X-Sendfile', value: storagePath },
     ]);