Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Implement upload and delete fuctionality to s3 for images and videos #28

Merged
merged 2 commits into from
Jul 8, 2024

Conversation

cp-dharti-r
Copy link
Collaborator

@cp-dharti-r cp-dharti-r commented Jul 8, 2024

Summary by CodeRabbit

  • New Features

    • Introduced AWS S3 for image and video upload across multiple admin pages.
    • Added support for address details in settings upsert operation.
    • Added sitemap.xml for better SEO.
  • Improvements

    • Conditionally render categories link in Sidebar for super-admins.
    • Refactored all image and video handling to use AWS S3, improving modularity and performance.
    • Replaced Swiper component with a styled div for menu items in the restaurant category page.
  • Chores

    • Updated environment variables example to include AWS S3 configuration.
    • Removed console log statements in custom scroll reset hook.
    • Commented out reactStrictMode and removed domains configuration in next.config files for admin and website projects.

Copy link

coderabbitai bot commented Jul 8, 2024

Walkthrough

The updates integrate AWS S3 for file uploads and deletions, replacing Supabase storage across multiple components in the admin section. Modifications were made to conditionally render UI elements based on user roles, and environmental variables were added for S3 configuration. Additionally, development settings were updated, and a sitemap was introduced for improved site structuring.

Changes

File/Path Change Summary
admin/components/Sidebar/index.tsx Conditionally renders a Link to /categories based on the role prop being "super-admin".
admin/next.config.mjs, website/next.config.mjs Comment out reactStrictMode: true and remove domains entry under images configuration.
admin/package.json Added dependencies for AWS SDK client S3 and S3 request presigner.
admin/pages/.../add/index.tsx Refactored to use uploadFileTos3 for image uploads to S3.
admin/pages/.../edit/[id].tsx Replaced Supabase operations with uploadFileTos3 and deleteFileFroms3 for handling file operations.
admin/pages/categories/index.tsx, .../dishes/index.tsx, .../restaurants/index.tsx, .../settings/index.tsx Updated file deletion logic to use deleteFileFroms3 and adjusted query formats.
admin/utils/image.ts Added uploadFileTos3 and deleteFileFroms3 functions, and updated file extension handling logic.
admin/.env.example Added new environment variables for AWS S3 bucket configuration.
website/hooks/useScrollReset.tsx Removed console log statements.
website/pages/category/restaurant.tsx Replaced Swiper component with a styled div for rendering menu items.
website/public/sitemap.xml Added a new sitemap XML file containing URLs and last modification dates.

Sequence Diagram(s)

sequenceDiagram
    participant Admin as Admin UI
    participant S3 as AWS S3
    participant Config as Config Files

    Admin->>Admin: User initiates image upload

    Admin->>S3: uploadFileTos3(file)
    S3-->>Admin: S3 URL

    Admin->>S3: deleteFileFroms3(filePath)
    S3-->>Admin: Deletion confirmation

    Admin->>Config: Load AWS S3 configurations

    Admin-->>Admin: Display S3-hosted image
Loading

Poem

Upon the web, a bunny hops,
Now files fly to AWS from crops 🌾,
S3’s embrace, a storage space,
Supabase set aside with grace,
Admin tables nicely at your stops,
With next gentle hops, non-stop!

- CodeRabbit 🐇


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 Configration 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.

Copy link

@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: 25

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 59c64cc and fd64123.

Files ignored due to path filters (2)
  • admin/public/logo.ico is excluded by !**/*.ico
  • website/public/logo.ico is excluded by !**/*.ico
Files selected for processing (22)
  • admin/components/Sidebar/index.tsx (2 hunks)
  • admin/next.config.mjs (1 hunks)
  • admin/package.json (1 hunks)
  • admin/pages/categories/add/index.tsx (2 hunks)
  • admin/pages/categories/edit/[id].tsx (2 hunks)
  • admin/pages/categories/index.tsx (2 hunks)
  • admin/pages/dishes/add/index.tsx (2 hunks)
  • admin/pages/dishes/edit/[id].tsx (3 hunks)
  • admin/pages/dishes/index.tsx (4 hunks)
  • admin/pages/menus/add/index.tsx (2 hunks)
  • admin/pages/menus/edit/[id].tsx (2 hunks)
  • admin/pages/menus/index.tsx (2 hunks)
  • admin/pages/profile/index.tsx (2 hunks)
  • admin/pages/restaurants/add/index.tsx (2 hunks)
  • admin/pages/restaurants/edit/[id].tsx (3 hunks)
  • admin/pages/restaurants/index.tsx (3 hunks)
  • admin/pages/settings/index.tsx (8 hunks)
  • admin/utils/image.ts (2 hunks)
  • website/hooks/useScrollReset.tsx (1 hunks)
  • website/next.config.mjs (1 hunks)
  • website/pages/category/restaurant.tsx (2 hunks)
  • website/public/sitemap.xml (1 hunks)
Files skipped from review due to trivial changes (5)
  • admin/next.config.mjs
  • admin/package.json
  • website/hooks/useScrollReset.tsx
  • website/next.config.mjs
  • website/public/sitemap.xml
Additional context used
Biome
admin/pages/restaurants/edit/[id].tsx

[error] 87-87: Shouldn't redeclare 'i'. Consider to delete it or rename it.

'i' is defined here:

(lint/suspicious/noRedeclare)

admin/pages/dishes/edit/[id].tsx

[error] 126-126: Shouldn't redeclare 'i'. Consider to delete it or rename it.

'i' is defined here:

(lint/suspicious/noRedeclare)


[error] 169-169: Shouldn't redeclare 'i'. Consider to delete it or rename it.

'i' is defined here:

(lint/suspicious/noRedeclare)

admin/pages/settings/index.tsx

[error] 183-183: Shouldn't redeclare 'i'. Consider to delete it or rename it.

'i' is defined here:

(lint/suspicious/noRedeclare)


[error] 337-337: This variable is used before its declaration.

The variable is declared here:

(lint/correctness/noInvalidUseBeforeDeclaration)


[error] 338-338: Shouldn't redeclare 'i'. Consider to delete it or rename it.

'i' is defined here:

(lint/suspicious/noRedeclare)


[error] 394-394: Shouldn't redeclare 'i'. Consider to delete it or rename it.

'i' is defined here:

(lint/suspicious/noRedeclare)

Additional comments not posted (23)
admin/utils/image.ts (1)

10-16: Ensure AWS credentials are securely managed.

The AWS credentials are being accessed from environment variables. Ensure that these environment variables are securely managed and not exposed in the client-side code.

website/pages/category/restaurant.tsx (1)

Line range hint 81-136: Ensure the new div element maintains functionality.

The Swiper component has been replaced with a div element for rendering menu items. Ensure that the new div element maintains the intended functionality, such as scrolling and layout.

admin/pages/categories/add/index.tsx (1)

Line range hint 13-62: Ensure proper error handling for file upload.

The uploadFileTos3 function is used for uploading images. Ensure that any errors thrown by this function are properly handled to provide feedback to the user.

admin/pages/categories/edit/[id].tsx (1)

12-13: Ensure proper error handling for file upload and deletion.

The uploadFileTos3 and deleteFileFroms3 functions are used for handling images. Ensure that any errors thrown by these functions are properly handled to provide feedback to the user.

admin/pages/restaurants/index.tsx (2)

29-29: Consistent String Usage

The change from single quotes to double quotes for the order method argument improves consistency. Good job!


77-77: S3 Deletion Logic

The function correctly deletes images from S3 before deleting the restaurant record. This ensures no orphaned images remain in S3. Good implementation!

admin/pages/menus/add/index.tsx (1)

69-75: Image Upload to S3

The image upload logic is correctly implemented, converting the image to WebP format and uploading it to S3. The image URL construction is also handled properly. Good job!

admin/pages/menus/edit/[id].tsx (1)

84-92: Image Upload and Deletion in S3

The function correctly handles the uploading of new images and deletion of old images from S3. The image URL construction is also handled properly. Good job!

admin/pages/categories/index.tsx (2)

Line range hint 29-29: Consistent String Usage

The change from single quotes to double quotes for the order method argument improves consistency. Good job!


78-78: S3 Deletion Logic

The function correctly deletes images from S3 before deleting the category record. This ensures no orphaned images remain in S3. Good implementation!

admin/pages/menus/index.tsx (1)

10-10: Import statement looks good.

The import deleteFileFroms3 is necessary and correctly used in the file.

admin/pages/restaurants/edit/[id].tsx (1)

13-14: Import statements look good.

The imports deleteFileFroms3 and uploadFileTos3 are necessary and correctly used in the file.

admin/pages/dishes/index.tsx (2)

8-8: Import statement looks good.

The import deleteFileFroms3 is necessary and correctly used in the file.


41-42: Ensure the select query is fetching the required data.

The select query now includes additional fields (id, name, images, video, video_thumbnail, price, menus(*)). Ensure these fields are required and correctly used in the file.

Verification successful

The select query is fetching the required data.

The fields id, name, images, video, video_thumbnail, price, menus are all used within the admin/pages/dishes/index.tsx file, confirming their necessity.

  • id: Used in multiple places for identification and operations.
  • name: Displayed in the UI.
  • images: Used for displaying images and handling image deletion.
  • video: Used for displaying videos and handling video deletion.
  • video_thumbnail: Used for displaying video thumbnails and handling their deletion.
  • price: Displayed in the UI.
  • menus: Referenced and displayed in the UI.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the selected fields in the codebase.

# Test: Search for the usage of the selected fields. Expect: Only relevant occurances.
rg --type javascript --pattern $'id, name, images, video, video_thumbnail, price, menus(*)'

Length of output: 504


Script:

#!/bin/bash
# Description: Verify the usage of the selected fields in the codebase.

# Test: Search for the usage of the selected fields. Expect: Only relevant occurrences.
rg 'id' --type js
rg 'name' --type js
rg 'images' --type js
rg 'video' --type js
rg 'video_thumbnail' --type js
rg 'price' --type js
rg 'menus' --type js

Length of output: 153


Script:

#!/bin/bash
# Description: Verify the usage of the selected fields in the admin/pages/dishes/index.tsx file.

# Test: Search for the usage of the selected fields in the specific file.
rg 'id' admin/pages/dishes/index.tsx
rg 'name' admin/pages/dishes/index.tsx
rg 'images' admin/pages/dishes/index.tsx
rg 'video' admin/pages/dishes/index.tsx
rg 'video_thumbnail' admin/pages/dishes/index.tsx
rg 'price' admin/pages/dishes/index.tsx
rg 'menus' admin/pages/dishes/index.tsx

Length of output: 3534

admin/pages/restaurants/add/index.tsx (1)

14-14: Import statement looks good.

The import uploadFileTos3 is necessary and correctly used in the file.

admin/pages/profile/index.tsx (3)

10-11: LGTM! Import changes are appropriate.

The import statements for deleteFileFroms3 and uploadFileTos3 are correct and align with the PR objectives.


94-100: LGTM! File upload logic is correct.

The logic for uploading the file to S3 using uploadFileTos3 is correct.


103-103: LGTM! File deletion logic is correct.

The logic for deleting the previous file from S3 using deleteFileFroms3 is correct.

admin/pages/dishes/add/index.tsx (4)

15-15: LGTM! Import changes are appropriate.

The import statement for uploadFileTos3 is correct and aligns with the PR objectives.


99-100: LGTM! File upload logic for images is correct.

The logic for uploading images to S3 using uploadFileTos3 is correct.


116-117: LGTM! File upload logic for video thumbnails is correct.

The logic for uploading video thumbnails to S3 using uploadFileTos3 is correct.


118-124: LGTM! File upload logic for videos is correct.

The logic for uploading videos to S3 using uploadFileTos3 is correct.

admin/components/Sidebar/index.tsx (1)

131-176: LGTM! Ensure proper testing for conditional rendering.

The conditional rendering logic for the /categories link based on the role prop looks good. Ensure that this change is properly tested to verify that the link is only visible to users with the "super-admin" role.

admin/utils/image.ts Outdated Show resolved Hide resolved
admin/utils/image.ts Outdated Show resolved Hide resolved
admin/pages/settings/index.tsx Show resolved Hide resolved
admin/pages/settings/index.tsx Show resolved Hide resolved
admin/pages/settings/index.tsx Show resolved Hide resolved
admin/pages/menus/index.tsx Show resolved Hide resolved
admin/pages/restaurants/edit/[id].tsx Show resolved Hide resolved
admin/pages/restaurants/edit/[id].tsx Show resolved Hide resolved
admin/pages/dishes/index.tsx Show resolved Hide resolved
admin/pages/restaurants/add/index.tsx Show resolved Hide resolved
Copy link

@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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between fd64123 and c10b3fb.

Files selected for processing (2)
  • admin/.env.example (1 hunks)
  • admin/utils/image.ts (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • admin/utils/image.ts
Additional comments not posted (1)
admin/.env.example (1)

9-11: Ensure Security Best Practices for Environment Variables

The new environment variables for AWS S3 bucket access include sensitive information like access keys. Ensure that these variables are not exposed in the client-side code and are securely managed.

Confirm that these environment variables are only used server-side and are not exposed to the client.

@cp-dharti-r cp-dharti-r merged commit 7e2a0d0 into main Jul 8, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant