Skip to content

Conversation

@mertmit
Copy link
Member

@mertmit mertmit commented Jul 23, 2024

Change Summary

  • Allow preview for types ['image', 'pdf', 'video', 'audio']
  • Redirect to download using an internal endpoint

Change type

  • feat: (new feature for the user, not a new feature for build script)

@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jul 23, 2024
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 23, 2024

Walkthrough

Walkthrough

The recent changes enhance attachment handling across the application by improving file download logic and HTTP response management. Key updates include more precise parameters for MIME types and file previews, streamlined signed URL generation, and clearer function naming. These modifications collectively create a more efficient and user-friendly file management system.

Changes

Files Change Summary
.../controllers/attachments-secure.controller.ts
.../controllers/attachments.controller.ts
.../controllers/public-datas.controller.ts
Enhanced HTTP response handling with new parameters for Content-Type and Content-Disposition. Introduced methods for downloading attachments and improved preview checks.
.../db/BaseModelSqlv2.ts
.../models/PresignedUrl.ts
Improved signed URL generation by adding preview, mimetype, and filename properties for better metadata management.
.../helpers/attachmentHelpers.ts Introduced isPreviewAllowed function to determine file preview eligibility based on MIME type and path.
.../modules/jobs/jobs/data-export/data-export.processor.ts
.../plugins/s3/S3.ts
Modified getSignedUrl method calls to incorporate preview and mimetype, enhancing clarity in URL generation.
.../services/attachments.service.ts Streamlined URL signing by incorporating preview and mimetype parameters, removing the redundant previewAvailable method.
.../components/cell/attachment/Modal.vue
.../components/cell/attachment/utils.ts
Renamed functions from generic file handling to attachment-specific terminology, enhancing code clarity.
.../components/cell/attachment/index.vue Introduced a new reactive variable, modalRendered, to improve modal rendering logic and enhance UI responsiveness.
.../composables/useAttachment.ts Updated fetch logic to include mode: 'no-cors', impacting cross-origin request handling.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@dosubot dosubot bot added the 🔦 Type: Feature New functionality is requested. label Jul 23, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Outside diff range, codebase verification and nitpick comments (3)
packages/nocodb/src/helpers/attachmentHelpers.ts (1)

5-19: Consider adding comments for clarity.

Adding comments to explain the logic can improve readability and maintainability.

+  // Destructure mimetype and path from args
  const { mimetype, path } = args;

  if (mimetype) {
+    // Check if the mimetype is in the list of previewable types
    return previewableMimeTypes.some((type) => mimetype.includes(type));
  } else if (path) {
+    // Extract the file extension from the path
    const ext = path.split('.').pop();
    if (ext) {
+      // Get the MIME type from the extension and check if it's previewable
      const mimeType = mime.getType(ext);
      return previewableMimeTypes.some((type) => mimeType?.includes(type));
    }
  }

+  // Return false if neither mimetype nor path is provided
  return false;
packages/nocodb/src/controllers/attachments-secure.controller.ts (1)

78-99: Consider logging the error in the catch block.

Logging the error can help with debugging and provide more context when an error occurs.

    } catch (e) {
+      console.error(`Error in fileReadv3: ${e.message}`, e);
      res.status(404).send('Not found');
    }
packages/nocodb/src/modules/jobs/jobs/data-export/data-export.processor.ts (1)

98-108: Consider adding comments for clarity.

Adding comments to explain the logic can improve readability and maintainability.

      // if url is not defined, it is local attachment
      if (!url) {
+        // Generate a signed URL for the local attachment
        url = await PresignedUrl.getSignedUrl({
          path: path.join(destPath.replace('nc/uploads/', '')),
          expireSeconds: 3 * 60 * 60, // 3 hours
          filename: `${model.title} (${getViewTitle(view)}).csv`,
          preview: false,
          mimetype: 'text/csv',
        });
      } else {
+        // Generate a signed URL for the external attachment
        url = await PresignedUrl.getSignedUrl({
          path: decodeURI(new URL(url).pathname),
          expireSeconds: 3 * 60 * 60, // 3 hours
          filename: `${model.title} (${getViewTitle(view)}).csv`,
          preview: false,
          mimetype: 'text/csv',
        });
      }
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f67b3ca and a2c2475.

Files selected for processing (8)
  • packages/nocodb/src/controllers/attachments-secure.controller.ts (1 hunks)
  • packages/nocodb/src/controllers/attachments.controller.ts (4 hunks)
  • packages/nocodb/src/db/BaseModelSqlv2.ts (3 hunks)
  • packages/nocodb/src/helpers/attachmentHelpers.ts (1 hunks)
  • packages/nocodb/src/models/PresignedUrl.ts (4 hunks)
  • packages/nocodb/src/modules/jobs/jobs/data-export/data-export.processor.ts (1 hunks)
  • packages/nocodb/src/plugins/s3/S3.ts (1 hunks)
  • packages/nocodb/src/services/attachments.service.ts (2 hunks)
Additional comments not posted (24)
packages/nocodb/src/controllers/attachments.controller.ts (4)

25-25: Import statement looks good.

The isPreviewAllowed helper function is correctly imported from ~/helpers/attachmentHelpers.


77-77: Usage of isPreviewAllowed looks good.

The function is correctly used to determine if a file can be previewed based on its mimetype and path.


114-114: Usage of isPreviewAllowed looks good.

The function is correctly used to determine if a file can be previewed based on its mimetype and path.


139-162: Handling of query parameters looks good.

The query parameters ResponseContentType and ResponseContentDisposition are correctly extracted and used to set the response headers.

packages/nocodb/src/models/PresignedUrl.ts (6)

6-6: Import statement looks good.

The isPreviewAllowed helper function is correctly imported from ~/helpers/attachmentHelpers.


95-96: Addition of preview and mimetype parameters looks good.

The parameters are correctly added to the getSignedUrl method, enhancing its flexibility.


102-106: Destructuring of preview and mimetype parameters looks good.

The destructuring is correctly implemented and aligns with the changes described in the summary.


108-110: Usage of isPreviewAllowed looks good.

The function is correctly used to set the preview variable based on the path and mimetype.


145-149: Addition of preview and mimetype parameters in storage adapter looks good.

The parameters are correctly added to the getSignedUrl method of the storage adapter, enhancing its flexibility.


161-183: Handling of ResponseContentDisposition and ResponseContentType headers looks good.

The headers are correctly set based on the preview and mimetype parameters.

packages/nocodb/src/plugins/s3/S3.ts (4)

110-118: Addition of options parameter looks good.

The parameter is correctly added to the getSignedUrl method, enhancing its flexibility.


119-120: Destructuring of filename, preview, and mimetype properties looks good.

The destructuring is correctly implemented and aligns with the changes described in the summary.


124-129: Handling of ResponseContentDisposition and ResponseContentType headers looks good.

The headers are correctly set based on the preview and mimetype properties.


Line range hint 161-183: Handling of ResponseContentDisposition and ResponseContentType headers in fallback URL generation looks good.

The headers are correctly set based on the preview and mimetype properties in the fallback URL generation.

packages/nocodb/src/services/attachments.service.ts (4)

92-93: Ensure the preview parameter is handled correctly in getSignedUrl.

The preview parameter is passed as true. Verify that the getSignedUrl method correctly handles this parameter to enable preview functionality.


93-93: Ensure the mimetype parameter is handled correctly in getSignedUrl.

The mimetype parameter is passed as the attachment's mimetype. Verify that the getSignedUrl method correctly handles this parameter to support different MIME types.


86-87: Ensure the preview parameter is handled correctly in getSignedUrl.

The preview parameter is passed as true. Verify that the getSignedUrl method correctly handles this parameter to enable preview functionality.

Verification successful

Ensure the preview parameter is handled correctly in getSignedUrl.

The preview parameter is correctly handled in the getSignedUrl method. The method includes the preview parameter in its options and processes it accordingly.

  • packages/nocodb/src/services/attachments.service.ts:
    • The getSignedUrl method includes the preview parameter in its options.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the `getSignedUrl` method correctly handles the `preview` parameter.

# Test: Search for the `getSignedUrl` method definition. Expect: The method should handle the `preview` parameter.
rg --type typescript -A 10 $'getSignedUrl'

Length of output: 76


Script:

#!/bin/bash
# Description: Verify that the `getSignedUrl` method correctly handles the `preview` parameter.

# Locate all TypeScript files and search for the `getSignedUrl` method definition within those files.
fd --extension ts --exec rg 'getSignedUrl' -A 10

Length of output: 5389


87-87: Ensure the mimetype parameter is handled correctly in getSignedUrl.

The mimetype parameter is passed as the attachment's mimetype. Verify that the getSignedUrl method correctly handles this parameter to support different MIME types.

Verification successful

Ensure the mimetype parameter is handled correctly in getSignedUrl.

The mimetype parameter is passed to the getSignedUrl method in multiple instances. The method definitions in both the PresignedUrl and S3 classes include handling for the mimetype parameter, ensuring it supports different MIME types.

  • PresignedUrl class:

    public static async getSignedUrl(
      param: {
        path: string;
        expireSeconds?: number;
        filename?: string;
        preview?: boolean;
        mimetype?: string;
      },
      ncMeta = Noco.ncMeta,
    ) {
      // Implementation details...
      if (typeof (storageAdapter as any).getSignedUrl === 'function') {
        tempUrl = await (storageAdapter as any).getSignedUrl(
          path,
          expiresInSeconds,
          {
            filename,
            preview,
            mimetype,
          },
        );
        // Additional implementation details...
      }
    }
  • S3 class:

    public async getSignedUrl(
      key,
      expiresInSeconds = 7200,
      options?: {
        filename?: string;
        preview?: boolean;
        mimetype?: string;
      },
    ) {
      const { filename, preview, mimetype } = options || {};
      // Implementation details...
      return getSignedUrl(this.s3Client, command, {
        expiresIn: expiresInSeconds,
      });
    }

Both implementations correctly handle the mimetype parameter, ensuring support for different MIME types.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the `getSignedUrl` method correctly handles the `mimetype` parameter.

# Test: Search for the `getSignedUrl` method definition. Expect: The method should handle the `mimetype` parameter.
rg --type typescript -A 10 $'getSignedUrl'

Length of output: 76


Script:

#!/bin/bash
# Description: Verify that the `getSignedUrl` method correctly handles the `mimetype` parameter.

# Find all TypeScript files and search for the `getSignedUrl` method definition.
fd --extension ts --exec rg 'getSignedUrl' -A 10

Length of output: 5389

packages/nocodb/src/db/BaseModelSqlv2.ts (6)

7215-7217: Ensure preview property is necessary.

The addition of the preview property to the PresignedUrl.getSignedUrl method enhances the functionality, but verify if this is required for all attachment types.


7216-7217: Check mimetype and filename properties.

The inclusion of mimetype and filename properties provides more context for the attachments. Ensure these properties are correctly populated and used downstream.


7226-7228: Ensure preview property is necessary.

The addition of the preview property to the PresignedUrl.getSignedUrl method enhances the functionality, but verify if this is required for all attachment types.


7227-7228: Check mimetype and filename properties.

The inclusion of mimetype and filename properties provides more context for the attachments. Ensure these properties are correctly populated and used downstream.


7238-7240: Ensure preview property is necessary.

The addition of the preview property to the PresignedUrl.getSignedUrl method enhances the functionality, but verify if this is required for all attachment types.


7239-7240: Check mimetype and filename properties.

The inclusion of mimetype and filename properties provides more context for the attachments. Ensure these properties are correctly populated and used downstream.

@o1lab o1lab force-pushed the nc-feat/preview-and-download branch from a2c2475 to 52bc217 Compare July 23, 2024 11:39
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a2c2475 and 52bc217.

Files selected for processing (8)
  • packages/nocodb/src/controllers/attachments-secure.controller.ts (1 hunks)
  • packages/nocodb/src/controllers/attachments.controller.ts (4 hunks)
  • packages/nocodb/src/db/BaseModelSqlv2.ts (3 hunks)
  • packages/nocodb/src/helpers/attachmentHelpers.ts (1 hunks)
  • packages/nocodb/src/models/PresignedUrl.ts (5 hunks)
  • packages/nocodb/src/modules/jobs/jobs/data-export/data-export.processor.ts (1 hunks)
  • packages/nocodb/src/plugins/s3/S3.ts (1 hunks)
  • packages/nocodb/src/services/attachments.service.ts (2 hunks)
Files skipped from review as they are similar to previous changes (7)
  • packages/nocodb/src/controllers/attachments-secure.controller.ts
  • packages/nocodb/src/controllers/attachments.controller.ts
  • packages/nocodb/src/db/BaseModelSqlv2.ts
  • packages/nocodb/src/helpers/attachmentHelpers.ts
  • packages/nocodb/src/modules/jobs/jobs/data-export/data-export.processor.ts
  • packages/nocodb/src/plugins/s3/S3.ts
  • packages/nocodb/src/services/attachments.service.ts
Additional context used
Biome
packages/nocodb/src/models/PresignedUrl.ts

[error] 174-174: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)

Additional comments not posted (5)
packages/nocodb/src/models/PresignedUrl.ts (5)

6-6: LGTM!

The import statement for isPreviewAllowed appears correct.


95-96: LGTM!

The preview and mimetype parameters are correctly added to the getSignedUrl method.


102-108: LGTM!

The destructuring and handling of preview and mimetype parameters are correctly implemented.


127-139: LGTM!

The conditional logic for setting ResponseContentDisposition based on preview is correctly implemented.


141-143: LGTM!

The inclusion of mimetype in ResponseContentType is correctly implemented.

@o1lab o1lab force-pushed the nc-feat/preview-and-download branch from 52bc217 to 1bd898b Compare July 23, 2024 12:07
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 52bc217 and 1bd898b.

Files selected for processing (12)
  • packages/nc-gui/components/cell/attachment/Modal.vue (3 hunks)
  • packages/nc-gui/components/cell/attachment/index.vue (4 hunks)
  • packages/nc-gui/components/cell/attachment/utils.ts (6 hunks)
  • packages/nc-gui/composables/useAttachment.ts (1 hunks)
  • packages/nocodb/src/controllers/attachments-secure.controller.ts (1 hunks)
  • packages/nocodb/src/controllers/attachments.controller.ts (4 hunks)
  • packages/nocodb/src/db/BaseModelSqlv2.ts (3 hunks)
  • packages/nocodb/src/helpers/attachmentHelpers.ts (1 hunks)
  • packages/nocodb/src/models/PresignedUrl.ts (5 hunks)
  • packages/nocodb/src/modules/jobs/jobs/data-export/data-export.processor.ts (1 hunks)
  • packages/nocodb/src/plugins/s3/S3.ts (1 hunks)
  • packages/nocodb/src/services/attachments.service.ts (2 hunks)
Files skipped from review due to trivial changes (1)
  • packages/nc-gui/components/cell/attachment/Modal.vue
Files skipped from review as they are similar to previous changes (7)
  • packages/nocodb/src/controllers/attachments-secure.controller.ts
  • packages/nocodb/src/controllers/attachments.controller.ts
  • packages/nocodb/src/db/BaseModelSqlv2.ts
  • packages/nocodb/src/helpers/attachmentHelpers.ts
  • packages/nocodb/src/modules/jobs/jobs/data-export/data-export.processor.ts
  • packages/nocodb/src/plugins/s3/S3.ts
  • packages/nocodb/src/services/attachments.service.ts
Additional context used
Biome
packages/nocodb/src/models/PresignedUrl.ts

[error] 174-174: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)

Additional comments not posted (8)
packages/nc-gui/composables/useAttachment.ts (1)

23-23: Verify the necessity of mode: 'no-cors' in the fetch request.

Using mode: 'no-cors' allows cross-origin requests without requiring the server to explicitly allow them through CORS headers. This can have security implications and may affect the fetch response, as it restricts the response type to opaque. Ensure that this change is necessary and does not introduce security vulnerabilities.

packages/nocodb/src/models/PresignedUrl.ts (2)

95-96: LGTM! The new parameters enhance flexibility.

The introduction of preview and mimetype parameters in the constructor improves the flexibility of the PresignedUrl class, allowing for conditional handling of URL generation based on these parameters.


108-110: LGTM! The changes improve signed URL generation.

The logic for handling preview and mimetype parameters enhances the functionality of the signed URL generation process, allowing for better control over content types and preview options.

Also applies to: 127-143

packages/nc-gui/components/cell/attachment/index.vue (1)

47-47: LGTM! The changes improve control flow and resource management.

The introduction of the modalRendered variable enhances the control flow and resource management by ensuring that the modal is rendered only when necessary, preventing unnecessary rendering.

Also applies to: 128-128, 162-162, 357-357

packages/nc-gui/components/cell/attachment/utils.ts (4)

324-328: Ensure downloadFile function is implemented for bulk downloads.

The bulkDownloadAttachments function depends on the downloadFile function, which is currently a placeholder. Ensure downloadFile is implemented to avoid errors.


330-340: Verify URL construction and error handling in downloadAttachment.

Ensure that the downloadAttachment function correctly constructs the URL and handles errors appropriately.

Verification successful

Verify URL construction and error handling in downloadAttachment.

The downloadAttachment function correctly constructs the URL and handles errors appropriately. It checks for necessary values and displays an error message if any are missing.

  • packages/nc-gui/components/cell/attachment/utils.ts: URL construction and error handling in downloadAttachment.
  • packages/nc-gui/components/cell/attachment/Modal.vue: Usage of downloadAttachment.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the URL construction and error handling in the `downloadAttachment` function.

# Test: Search for the usage of `downloadAttachment`. Expect: Correct URL construction and error handling.
rg --type js --type ts 'downloadAttachment' -A 5

Length of output: 3743


38-38: Verify the usage of modalRendered.

Ensure that the modalRendered state variable is used correctly and consistently throughout the file.

Verification successful

Verify the lifecycle and usage of modalRendered in index.vue.

Ensure that modalRendered is used correctly within the lifecycle methods and other relevant parts of index.vue.


Verify the initialization and management of modalRendered in the component setup and lifecycle.

Ensure that modalRendered is correctly initialized and managed within the component's setup and lifecycle.


The usage of modalRendered is consistent and correct.

The modalRendered variable is properly initialized in the setup function and used correctly within the component.

  • modalRendered is imported from useProvideAttachmentCell.
  • It is used to control the rendering of the LazyCellAttachmentModal component.
  • The variable is set to true in specific conditions, ensuring correct behavior.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `modalRendered` in the codebase.

# Test: Search for the usage of `modalRendered`. Expect: Consistent and correct usage.
rg --type js --type ts 'modalRendered' -A 5

Length of output: 2865


Script:

#!/bin/bash
# Description: Verify the lifecycle and usage of `modalRendered` in `index.vue`.

# Test: Search for the lifecycle methods and other relevant parts where `modalRendered` is used.
rg 'modalRendered|mounted|created|beforeMount|beforeUpdate|updated|beforeDestroy|destroyed' packages/nc-gui/components/cell/attachment/index.vue -A 10

Length of output: 1293


Script:

#!/bin/bash
# Description: Verify the initialization and management of `modalRendered` in the component setup and lifecycle.

# Test: Search for the component setup and other relevant parts where `modalRendered` might be managed.
rg 'setup|modalRendered' packages/nc-gui/components/cell/attachment/index.vue -A 20

Length of output: 2831


13-15: Verify the usage of $api and baseURL.

Ensure that $api and baseURL are correctly initialized and used throughout the file for constructing URLs dynamically.

Verification successful

Verify the usage of $api and baseURL.

The $api and baseURL variables are used extensively in API calls and configurations throughout the codebase. Ensure that these variables are correctly initialized and consistently used in the following locations:

  • packages/nc-gui/components/cell/attachment/utils.ts
  • packages/nc-gui/components/smartsheet/details/Api.vue
  • packages/nc-gui/components/smartsheet/ApiSnippet.vue
  • packages/nc-gui/components/dlg/QuickImport.vue
  • packages/nc-gui/components/dlg/AirtableImport.vue
  • packages/nc-gui/composables/useApi/index.ts

Verify that the initialization and usage of these variables align with the expected configurations and API endpoints.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `$api` and `baseURL` in the codebase.

# Test: Search for the usage of `$api` and `baseURL`. Expect: Consistent and correct usage.
rg --type js --type ts '$api' -A 5
rg --type js --type ts 'baseURL' -A 5

Length of output: 315124

@o1lab o1lab force-pushed the nc-feat/preview-and-download branch from 1bd898b to 04b15b3 Compare July 23, 2024 12:37
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1bd898b and 04b15b3.

Files selected for processing (12)
  • packages/nc-gui/components/cell/attachment/Modal.vue (3 hunks)
  • packages/nc-gui/components/cell/attachment/index.vue (4 hunks)
  • packages/nc-gui/components/cell/attachment/utils.ts (6 hunks)
  • packages/nc-gui/composables/useAttachment.ts (1 hunks)
  • packages/nocodb/src/controllers/attachments-secure.controller.ts (3 hunks)
  • packages/nocodb/src/controllers/attachments.controller.ts (4 hunks)
  • packages/nocodb/src/db/BaseModelSqlv2.ts (3 hunks)
  • packages/nocodb/src/helpers/attachmentHelpers.ts (1 hunks)
  • packages/nocodb/src/models/PresignedUrl.ts (5 hunks)
  • packages/nocodb/src/modules/jobs/jobs/data-export/data-export.processor.ts (1 hunks)
  • packages/nocodb/src/plugins/s3/S3.ts (1 hunks)
  • packages/nocodb/src/services/attachments.service.ts (2 hunks)
Files skipped from review as they are similar to previous changes (10)
  • packages/nc-gui/components/cell/attachment/Modal.vue
  • packages/nc-gui/components/cell/attachment/index.vue
  • packages/nc-gui/components/cell/attachment/utils.ts
  • packages/nc-gui/composables/useAttachment.ts
  • packages/nocodb/src/controllers/attachments-secure.controller.ts
  • packages/nocodb/src/db/BaseModelSqlv2.ts
  • packages/nocodb/src/helpers/attachmentHelpers.ts
  • packages/nocodb/src/modules/jobs/jobs/data-export/data-export.processor.ts
  • packages/nocodb/src/plugins/s3/S3.ts
  • packages/nocodb/src/services/attachments.service.ts
Additional context used
Biome
packages/nocodb/src/models/PresignedUrl.ts

[error] 174-174: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)

Additional comments not posted (16)
packages/nocodb/src/models/PresignedUrl.ts (9)

6-6: Import statement approved.

The import statement for isPreviewAllowed is correct and necessary for the new functionality.


95-96: New parameters approved.

The addition of preview and mimetype parameters in the getSignedUrl method is appropriate for the new feature requirements.


102-106: Destructuring approved.

The destructuring of expireSeconds, filename, and mimetype parameters from the param object is necessary and correctly implemented.


108-110: Logic for determining preview approved.

The logic for determining the preview variable using the isPreviewAllowed function is correctly implemented.


123-148: Construction of pathParameters object approved.

The construction of the pathParameters object to include ResponseContentDisposition and ResponseContentType is correctly implemented and necessary for handling the content disposition and type in the URL.


141-143: Addition of ResponseContentType header approved.

The inclusion of the ResponseContentType header in the pathParameters object based on the mimetype parameter is correctly implemented.


127-139: Addition of ResponseContentDisposition header approved.

The inclusion of the ResponseContentDisposition header in the pathParameters object based on the preview and filename parameters is correctly implemented.


145-149: Construction of cachePath approved.

The construction of the cachePath by appending query parameters to the path is correctly implemented and necessary for caching the URL with the appropriate parameters.


Line range hint 223-241: New parameters in getSignedUrl calls approved.

The addition of preview and mimetype parameters in the getSignedUrl calls is appropriate for the new feature requirements.

packages/nocodb/src/controllers/attachments.controller.ts (7)

25-25: Import statement approved.

The import statement for isPreviewAllowed is correct and necessary for the new functionality.


Line range hint 86-90: Usage of isPreviewAllowed approved.

The usage of the isPreviewAllowed function to check if a file can be previewed is correctly implemented.


Line range hint 123-127: Usage of isPreviewAllowed approved.

The usage of the isPreviewAllowed function to check if a file can be previewed is correctly implemented.


148-156: New variables approved.

The addition of queryResponseContentType and queryResponseContentDisposition variables improves the flexibility of managing response headers.


163-164: Setting of Content-Type header approved.

Setting the Content-Type header based on the queryResponseContentType variable is correctly implemented.


167-169: Setting of Content-Disposition header approved.

Setting the Content-Disposition header based on the queryResponseContentDisposition variable is correctly implemented.


177-241: New method downloadAttachment approved.

The addition of the downloadAttachment method to the AttachmentsController class is correctly implemented and includes necessary guards for API rate limiting and access control.

@github-actions
Copy link
Contributor

github-actions bot commented Jul 23, 2024

Uffizzi Preview deployment-54519 was deleted.

@o1lab o1lab force-pushed the nc-feat/preview-and-download branch from 04b15b3 to 1bde1f0 Compare July 23, 2024 15:17
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 04b15b3 and 1bde1f0.

Files selected for processing (13)
  • packages/nc-gui/components/cell/attachment/Carousel.vue (2 hunks)
  • packages/nc-gui/components/cell/attachment/Modal.vue (3 hunks)
  • packages/nc-gui/components/cell/attachment/index.vue (4 hunks)
  • packages/nc-gui/components/cell/attachment/utils.ts (6 hunks)
  • packages/nc-gui/composables/useAttachment.ts (1 hunks)
  • packages/nocodb/src/controllers/attachments-secure.controller.ts (3 hunks)
  • packages/nocodb/src/controllers/attachments.controller.ts (4 hunks)
  • packages/nocodb/src/db/BaseModelSqlv2.ts (3 hunks)
  • packages/nocodb/src/helpers/attachmentHelpers.ts (1 hunks)
  • packages/nocodb/src/models/PresignedUrl.ts (5 hunks)
  • packages/nocodb/src/modules/jobs/jobs/data-export/data-export.processor.ts (1 hunks)
  • packages/nocodb/src/plugins/s3/S3.ts (1 hunks)
  • packages/nocodb/src/services/attachments.service.ts (2 hunks)
Files skipped from review due to trivial changes (1)
  • packages/nc-gui/components/cell/attachment/Carousel.vue
Files skipped from review as they are similar to previous changes (10)
  • packages/nc-gui/components/cell/attachment/Modal.vue
  • packages/nc-gui/components/cell/attachment/index.vue
  • packages/nc-gui/components/cell/attachment/utils.ts
  • packages/nocodb/src/controllers/attachments-secure.controller.ts
  • packages/nocodb/src/controllers/attachments.controller.ts
  • packages/nocodb/src/db/BaseModelSqlv2.ts
  • packages/nocodb/src/helpers/attachmentHelpers.ts
  • packages/nocodb/src/modules/jobs/jobs/data-export/data-export.processor.ts
  • packages/nocodb/src/plugins/s3/S3.ts
  • packages/nocodb/src/services/attachments.service.ts
Additional context used
Biome
packages/nocodb/src/models/PresignedUrl.ts

[error] 174-174: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)

Additional comments not posted (8)
packages/nc-gui/composables/useAttachment.ts (3)

Line range hint 3-12:
LGTM!

The function getPossibleAttachmentSrc is well-implemented.


23-23: Potential security issue with mode: 'no-cors'.

Using mode: 'no-cors' in the fetch request can lead to security issues and unexpected behavior. It is generally not recommended to use this mode unless absolutely necessary.

Please ensure that this change is necessary and does not introduce security vulnerabilities.


Line range hint 30-32:
LGTM!

The function openAttachment is well-implemented.

packages/nocodb/src/models/PresignedUrl.ts (5)

6-6: LGTM!

The import statement for isPreviewAllowed is correct.


95-96: LGTM!

The addition of preview and mimetype parameters enhances the functionality of the getSignedUrl method.


102-109: LGTM!

The destructuring of expireSeconds, filename, and mimetype parameters and the conditional handling of the preview variable are well-implemented.


123-148: LGTM!

The construction of pathParameters based on the preview and filename parameters is well-implemented.


151-151: LGTM!

The retrieval of the URL from the cache is well-implemented.

@o1lab o1lab force-pushed the nc-feat/preview-and-download branch from 1bde1f0 to 5783a56 Compare July 23, 2024 16:07
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1bde1f0 and 5783a56.

Files selected for processing (13)
  • packages/nc-gui/components/cell/attachment/Carousel.vue (2 hunks)
  • packages/nc-gui/components/cell/attachment/Modal.vue (3 hunks)
  • packages/nc-gui/components/cell/attachment/index.vue (4 hunks)
  • packages/nc-gui/components/cell/attachment/utils.ts (6 hunks)
  • packages/nc-gui/composables/useAttachment.ts (1 hunks)
  • packages/nocodb/src/controllers/attachments-secure.controller.ts (3 hunks)
  • packages/nocodb/src/controllers/attachments.controller.ts (4 hunks)
  • packages/nocodb/src/db/BaseModelSqlv2.ts (3 hunks)
  • packages/nocodb/src/helpers/attachmentHelpers.ts (1 hunks)
  • packages/nocodb/src/models/PresignedUrl.ts (5 hunks)
  • packages/nocodb/src/modules/jobs/jobs/data-export/data-export.processor.ts (1 hunks)
  • packages/nocodb/src/plugins/s3/S3.ts (1 hunks)
  • packages/nocodb/src/services/attachments.service.ts (2 hunks)
Files skipped from review as they are similar to previous changes (11)
  • packages/nc-gui/components/cell/attachment/Carousel.vue
  • packages/nc-gui/components/cell/attachment/Modal.vue
  • packages/nc-gui/components/cell/attachment/index.vue
  • packages/nc-gui/components/cell/attachment/utils.ts
  • packages/nc-gui/composables/useAttachment.ts
  • packages/nocodb/src/controllers/attachments-secure.controller.ts
  • packages/nocodb/src/db/BaseModelSqlv2.ts
  • packages/nocodb/src/helpers/attachmentHelpers.ts
  • packages/nocodb/src/modules/jobs/jobs/data-export/data-export.processor.ts
  • packages/nocodb/src/plugins/s3/S3.ts
  • packages/nocodb/src/services/attachments.service.ts
Additional context used
Biome
packages/nocodb/src/models/PresignedUrl.ts

[error] 174-174: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)

Additional comments not posted (10)
packages/nocodb/src/models/PresignedUrl.ts (5)

6-6: Import statement looks good.

The isPreviewAllowed function is imported correctly.


95-96: New parameters added to getSignedUrl method.

The new parameters preview and mimetype are correctly added to the method signature.


102-106: Destructuring of new parameters looks good.

The new parameters preview and mimetype are correctly destructured from the param object.


108-110: Logic for determining preview variable looks good.

The preview variable is correctly determined using the isPreviewAllowed function.


127-143: Usage of preview and mimetype in pathParameters looks good.

The preview and mimetype parameters are correctly used to set ResponseContentDisposition and ResponseContentType in pathParameters.

packages/nocodb/src/controllers/attachments.controller.ts (5)

25-25: Import statement looks good.

The isPreviewAllowed function is imported correctly.


86-86: Usage of isPreviewAllowed in fileRead method looks good.

The isPreviewAllowed function is correctly used to determine if a file can be previewed.


123-123: Usage of isPreviewAllowed in fileReadv2 method looks good.

The isPreviewAllowed function is correctly used to determine if a file can be previewed.


148-170: Handling of query parameters in fileReadv3 method looks good.

The new variables queryResponseContentType and queryResponseContentDisposition are correctly introduced to handle query parameters.


177-242: New method downloadAttachment looks good.

The new method downloadAttachment is correctly implemented and follows best practices.

@o1lab o1lab force-pushed the nc-feat/preview-and-download branch from 5783a56 to 0922c5c Compare July 23, 2024 16:48
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 8

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 5783a56 and 0922c5c.

Files selected for processing (15)
  • packages/nc-gui/components/cell/attachment/Carousel.vue (2 hunks)
  • packages/nc-gui/components/cell/attachment/Modal.vue (3 hunks)
  • packages/nc-gui/components/cell/attachment/index.vue (4 hunks)
  • packages/nc-gui/components/cell/attachment/utils.ts (6 hunks)
  • packages/nc-gui/composables/useAttachment.ts (1 hunks)
  • packages/nocodb/src/controllers/attachments-secure.controller.ts (3 hunks)
  • packages/nocodb/src/controllers/attachments.controller.ts (4 hunks)
  • packages/nocodb/src/controllers/public-datas.controller.ts (3 hunks)
  • packages/nocodb/src/db/BaseModelSqlv2.ts (3 hunks)
  • packages/nocodb/src/helpers/attachmentHelpers.ts (1 hunks)
  • packages/nocodb/src/models/PresignedUrl.ts (5 hunks)
  • packages/nocodb/src/modules/jobs/jobs/data-export/data-export.processor.ts (1 hunks)
  • packages/nocodb/src/plugins/s3/S3.ts (1 hunks)
  • packages/nocodb/src/services/attachments.service.ts (2 hunks)
  • packages/nocodb/src/services/public-datas.service.ts (1 hunks)
Files skipped from review as they are similar to previous changes (11)
  • packages/nc-gui/components/cell/attachment/Carousel.vue
  • packages/nc-gui/components/cell/attachment/Modal.vue
  • packages/nc-gui/components/cell/attachment/index.vue
  • packages/nc-gui/components/cell/attachment/utils.ts
  • packages/nocodb/src/controllers/attachments-secure.controller.ts
  • packages/nocodb/src/controllers/attachments.controller.ts
  • packages/nocodb/src/db/BaseModelSqlv2.ts
  • packages/nocodb/src/helpers/attachmentHelpers.ts
  • packages/nocodb/src/modules/jobs/jobs/data-export/data-export.processor.ts
  • packages/nocodb/src/plugins/s3/S3.ts
  • packages/nocodb/src/services/attachments.service.ts
Additional context used
Biome
packages/nocodb/src/models/PresignedUrl.ts

[error] 174-174: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)

Additional comments not posted (9)
packages/nc-gui/composables/useAttachment.ts (1)

23-23: Verify the impact of using mode: 'no-cors' in the fetch request.

Adding mode: 'no-cors' can lead to unexpected behavior by allowing cross-origin requests without requiring the server to explicitly permit them. Ensure this change does not introduce security vulnerabilities or unintended side effects.

packages/nocodb/src/models/PresignedUrl.ts (5)

95-96: New parameters preview and mimetype added.

The preview parameter allows conditional handling of URL generation based on whether previews are permitted. The mimetype parameter specifies the content type of the response.


102-106: Destructuring new parameters in getSignedUrl.

The destructuring of expireSeconds, filename, and the new parameters mimetype and preview from the param object enhances readability and maintainability.


108-110: Conditional handling of preview parameter.

The preview variable is determined using the isPreviewAllowed function, which checks if previews can be generated for the specified path and mimetype. This ensures that previews are only allowed when permitted.


127-139: Conditional construction of ResponseContentDisposition.

The ResponseContentDisposition is set to inline when preview is true; otherwise, it defaults to attachment. The filename is conditionally appended to the disposition string based on the presence of the filename parameter.


141-143: Inclusion of mimetype in ResponseContentType.

If the mimetype is provided, it is included in the ResponseContentType of the URL parameters. This enhances the flexibility of the signed URL generation process.

packages/nocodb/src/controllers/public-datas.controller.ts (2)

25-27: New dependency AttachmentsService added to the constructor.

The new dependency allows the controller to handle attachment-related functionalities, expanding its responsibilities.


201-237: New method downloadPublicAttachment added.

The method handles downloading attachments associated with a public shared view. It validates the existence of the specified column and record, and retrieves the attachment using the attachmentsService.

packages/nocodb/src/services/public-datas.service.ts (1)

786-787: LGTM!

The function correctly returns the retrieved row data.

Comment on lines +751 to +753
const view = await View.getByUUID(context, sharedViewUuid);

if (!view) NcError.viewNotFound(sharedViewUuid);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handle potential null return from getByUUID.

The getByUUID method might return null if the view is not found. Ensure that NcError.viewNotFound is called correctly.

const view = await View.getByUUID(context, sharedViewUuid);

if (!view) {
  throw NcError.viewNotFound(sharedViewUuid);
}

@o1lab o1lab force-pushed the nc-feat/preview-and-download branch from 0922c5c to 057f1aa Compare July 23, 2024 17:16
@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Jul 23, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Outside diff range, codebase verification and nitpick comments (1)
packages/nc-gui/composables/useSharedView.ts (1)

369-369: Document the new function in the export statement.

Ensure that the new function fetchSharedViewAttachment is properly documented in the module's documentation.

  return {
    sharedView,
    loadSharedView,
    meta,
    nestedFilters,
    fetchSharedViewData,
    fetchSharedViewActiveDate,
    fetchSharedCalendarViewData,
    fetchSharedViewGroupedData,
    fetchAggregatedData,
    fetchBulkAggregatedData,
    fetchSharedViewAttachment,
    paginationData,
    sorts,
    exportFile,
    formColumns,
    allowCSVDownload,
  }
+ /**
+  * Fetches an attachment for a shared view.
+  * @param {string} columnId - The ID of the column.
+  * @param {string} rowId - The ID of the row.
+  * @param {string} urlOrPath - The URL or path of the attachment.
+  * @returns {Promise<any>} - The attachment data.
+  */
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 0922c5c and 057f1aa.

Files ignored due to path filters (1)
  • packages/nocodb/src/schema/swagger.json is excluded by !**/*.json
Files selected for processing (16)
  • packages/nc-gui/components/cell/attachment/Carousel.vue (2 hunks)
  • packages/nc-gui/components/cell/attachment/Modal.vue (3 hunks)
  • packages/nc-gui/components/cell/attachment/index.vue (4 hunks)
  • packages/nc-gui/components/cell/attachment/utils.ts (6 hunks)
  • packages/nc-gui/composables/useAttachment.ts (1 hunks)
  • packages/nc-gui/composables/useSharedView.ts (2 hunks)
  • packages/nocodb/src/controllers/attachments-secure.controller.ts (3 hunks)
  • packages/nocodb/src/controllers/attachments.controller.ts (4 hunks)
  • packages/nocodb/src/controllers/public-datas.controller.ts (3 hunks)
  • packages/nocodb/src/db/BaseModelSqlv2.ts (3 hunks)
  • packages/nocodb/src/helpers/attachmentHelpers.ts (1 hunks)
  • packages/nocodb/src/models/PresignedUrl.ts (5 hunks)
  • packages/nocodb/src/modules/jobs/jobs/data-export/data-export.processor.ts (1 hunks)
  • packages/nocodb/src/plugins/s3/S3.ts (1 hunks)
  • packages/nocodb/src/services/attachments.service.ts (2 hunks)
  • packages/nocodb/src/services/public-datas.service.ts (1 hunks)
Files skipped from review as they are similar to previous changes (12)
  • packages/nc-gui/components/cell/attachment/Carousel.vue
  • packages/nc-gui/components/cell/attachment/Modal.vue
  • packages/nc-gui/components/cell/attachment/index.vue
  • packages/nc-gui/components/cell/attachment/utils.ts
  • packages/nocodb/src/controllers/attachments-secure.controller.ts
  • packages/nocodb/src/controllers/attachments.controller.ts
  • packages/nocodb/src/controllers/public-datas.controller.ts
  • packages/nocodb/src/db/BaseModelSqlv2.ts
  • packages/nocodb/src/helpers/attachmentHelpers.ts
  • packages/nocodb/src/modules/jobs/jobs/data-export/data-export.processor.ts
  • packages/nocodb/src/plugins/s3/S3.ts
  • packages/nocodb/src/services/public-datas.service.ts
Additional context used
Biome
packages/nocodb/src/models/PresignedUrl.ts

[error] 174-174: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)

Additional comments not posted (7)
packages/nc-gui/composables/useAttachment.ts (1)

23-23: Caution: Using mode: 'no-cors' can lead to security issues and unexpected behavior.

The mode: 'no-cors' option in the fetch request allows cross-origin requests without requiring the server to explicitly allow them through CORS headers. This could lead to security issues or unexpected behavior, as the response will be opaque and you won't be able to read the response body or headers.

Consider revisiting the need for mode: 'no-cors' and ensure it aligns with the security policies of your application.

packages/nocodb/src/models/PresignedUrl.ts (3)

95-96: Ensure proper validation for new parameters.

The new preview and mimetype parameters should be validated to ensure they meet the expected criteria. This helps prevent potential issues with invalid or unexpected values.

Also applies to: 102-110


127-143: Ensure consistent handling of ResponseContentDisposition and ResponseContentType.

The logic for setting ResponseContentDisposition and ResponseContentType should be consistent and clear. Ensure that these headers are correctly set based on the preview and mimetype parameters.


172-175: Avoid using this in a static context.

Using this in a static context can be confusing. Use the class name instead.

- await this.add({
+ await PresignedUrl.add({
Tools
Biome

[error] 174-174: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)

packages/nocodb/src/services/attachments.service.ts (3)

86-87: Ensure proper handling of preview and mimetype parameters.

The new preview and mimetype parameters should be handled consistently and validated to ensure they meet the expected criteria.

Also applies to: 92-93


219-259: Ensure proper handling of preview and mimetype parameters.

The new preview and mimetype parameters should be handled consistently and validated to ensure they meet the expected criteria.


241-259: Ensure consistent handling of preview and mimetype parameters.

The logic for generating signed URLs and handling the new preview and mimetype parameters should be consistent and clear.

@mertmit mertmit force-pushed the nc-feat/preview-and-download branch from 057f1aa to a61d878 Compare July 24, 2024 13:53
Signed-off-by: mertmit <mertmit99@gmail.com>
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Outside diff range, codebase verification and nitpick comments (1)
packages/nocodb/src/models/PresignedUrl.ts (1)

112-114: Simplify the preview assignment.

The assignment of preview can be simplified by directly using the result of isPreviewAllowed.

- const preview = param.preview
-   ? isPreviewAllowed({ path, mimetype })
-   : false;
+ const preview = isPreviewAllowed({ path, mimetype });
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 057f1aa and 72ea72c.

Files ignored due to path filters (1)
  • packages/nocodb/src/schema/swagger.json is excluded by !**/*.json
Files selected for processing (16)
  • packages/nc-gui/components/cell/attachment/Carousel.vue (2 hunks)
  • packages/nc-gui/components/cell/attachment/Modal.vue (3 hunks)
  • packages/nc-gui/components/cell/attachment/index.vue (4 hunks)
  • packages/nc-gui/components/cell/attachment/utils.ts (6 hunks)
  • packages/nc-gui/composables/useAttachment.ts (1 hunks)
  • packages/nc-gui/composables/useSharedView.ts (2 hunks)
  • packages/nocodb/src/controllers/attachments-secure.controller.ts (3 hunks)
  • packages/nocodb/src/controllers/attachments.controller.ts (4 hunks)
  • packages/nocodb/src/controllers/public-datas.controller.ts (3 hunks)
  • packages/nocodb/src/db/BaseModelSqlv2.ts (2 hunks)
  • packages/nocodb/src/helpers/attachmentHelpers.ts (1 hunks)
  • packages/nocodb/src/models/PresignedUrl.ts (6 hunks)
  • packages/nocodb/src/modules/jobs/jobs/data-export/data-export.processor.ts (1 hunks)
  • packages/nocodb/src/plugins/s3/S3.ts (1 hunks)
  • packages/nocodb/src/services/attachments.service.ts (2 hunks)
  • packages/nocodb/src/services/public-datas.service.ts (1 hunks)
Files skipped from review due to trivial changes (2)
  • packages/nc-gui/components/cell/attachment/Modal.vue
  • packages/nocodb/src/helpers/attachmentHelpers.ts
Files skipped from review as they are similar to previous changes (11)
  • packages/nc-gui/components/cell/attachment/Carousel.vue
  • packages/nc-gui/components/cell/attachment/index.vue
  • packages/nc-gui/components/cell/attachment/utils.ts
  • packages/nc-gui/composables/useSharedView.ts
  • packages/nocodb/src/controllers/attachments-secure.controller.ts
  • packages/nocodb/src/controllers/attachments.controller.ts
  • packages/nocodb/src/db/BaseModelSqlv2.ts
  • packages/nocodb/src/modules/jobs/jobs/data-export/data-export.processor.ts
  • packages/nocodb/src/plugins/s3/S3.ts
  • packages/nocodb/src/services/attachments.service.ts
  • packages/nocodb/src/services/public-datas.service.ts
Additional context used
Biome
packages/nocodb/src/models/PresignedUrl.ts

[error] 178-178: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)

Additional comments not posted (6)
packages/nc-gui/composables/useAttachment.ts (1)

23-23: Verify the necessity of mode: 'no-cors'.

Using mode: 'no-cors' can bypass CORS restrictions but might lead to security vulnerabilities. Ensure that this is necessary and that the implications are well-understood.

packages/nocodb/src/models/PresignedUrl.ts (2)

6-6: Ensure isPreviewAllowed is imported correctly.

Verify that the isPreviewAllowed function is correctly implemented and imported from ~/helpers/attachmentHelpers.


95-96: Review new parameters in getSignedUrl method.

The new preview and mimetype parameters should be validated to ensure they are used correctly within the method.

packages/nocodb/src/controllers/public-datas.controller.ts (3)

18-18: Ensure AttachmentsService is imported correctly.

Verify that the AttachmentsService is correctly implemented and imported from ~/services/attachments.service.


26-26: Verify the integration of AttachmentsService.

Ensure that the integration of AttachmentsService in the constructor does not introduce any issues and that it is used correctly throughout the class.


200-237: Review new route for downloading attachments.

The new route for downloading attachments should be thoroughly tested to ensure it handles all edge cases and potential errors correctly.

filename,
pathParameters,
);
await this.add({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid using this in a static context.

Using this in a static context can be confusing. Use the class name instead.

- await this.add({
+ await PresignedUrl.add({
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
await this.add({
await PresignedUrl.add({
Tools
Biome

[error] 178-178: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Jul 24, 2024
@DarkPhoenix2704 DarkPhoenix2704 merged commit 1605e09 into develop Jul 24, 2024
@DarkPhoenix2704 DarkPhoenix2704 deleted the nc-feat/preview-and-download branch July 24, 2024 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer size:XL This PR changes 500-999 lines, ignoring generated files. 🔦 Type: Feature New functionality is requested.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants