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: use cloudflare r2 for storing slide pdfs #1477

Merged
merged 8 commits into from
Nov 6, 2024
Merged

Conversation

danielroe
Copy link
Owner

@danielroe danielroe commented Nov 6, 2024

Summary by CodeRabbit

  • New Features

    • Introduced server-side event handler for generating signed URLs for Cloudflare R2 storage.
    • Enhanced cloud storage integration for slide files, allowing seamless uploads and retrieval from Cloudflare R2.
  • Improvements

    • Updated compatibility date for better alignment with future releases.
    • Adjusted security headers for improved application security.
  • Configuration Updates

    • Modified route rules for improved API handling and redirection.
    • Expanded experimental features including cookieStore, headNext, and viewTransition.
    • Broadened .gitignore entries to exclude additional development files and directories.

Copy link

coderabbitai bot commented Nov 6, 2024

Warning

Rate limit exceeded

@danielroe has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 6 minutes and 50 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 9d65653 and 9ba2a24.

Walkthrough

The changes in the pull request involve significant updates to the nuxt.config.ts file, enhancing configuration settings and introducing new properties. Key modifications include an updated compatibilityDate, the addition of a cloudflare configuration object, and redefined route rules. The .gitignore file has been expanded to exclude a wider range of files and directories. Additionally, new server-side functionality has been introduced in slides.ts for generating signed URLs for Cloudflare R2, alongside modifications in modules/slides.ts to shift from local to cloud-based file handling.

Changes

File Change Summary
nuxt.config.ts - Updated compatibilityDate from '2024-04-03' to '2024-09-19'.
- Added cloudflare object in runtimeConfig with s3Url, r2TokenId, and r2TokenKey.
- Redefined route rules for /api/hi, /feed.xml, /thumbnail/**, and /chat.
- Expanded experimental section to include cookieStore, headNext, and viewTransition.
- Updated security headers.
.gitignore - Added entries to ignore: .env.production, .cache, .next, .nuxt, .output, .data, dist, .vuepress/dist, .serverless, .idea, sw.*, .DS_Store, *.swp, .vercel, .unlighthouse, test-results, .partykit, .wrangler.
modules/runtime/server/slides.ts - Introduced a server-side event handler for generating signed URLs for Cloudflare R2.
- Implemented caching mechanism for responses.
modules/slides.ts - Updated to integrate Cloudflare R2 for file storage.
- Changed logic to check file existence using HeadObjectCommand.
- Added server handler for serving slides from the R2 bucket.

Sequence Diagram(s)

sequenceDiagram
    participant Client as Client
    participant Handler as Slides Event Handler
    participant S3 as Cloudflare R2
    participant Config as Runtime Config

    Client->>Handler: Request signed URL
    Handler->>Config: Retrieve configuration settings
    Handler->>S3: Check if object exists
    alt Object exists
        S3-->>Handler: Return object details
    else Object does not exist
        Handler->>S3: Upload file to R2
    end
    Handler-->>Client: Return signed URL
Loading

Poem

🐇 In the meadow of code, new paths we weave,
With Cloudflare's embrace, our dreams we achieve.
Signed URLs flutter, like leaves in the breeze,
As we dance with the clouds, our worries appease.
With each little change, our project takes flight,
In the garden of Nuxt, everything feels right! 🌼


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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

Copy link

vercel bot commented Nov 6, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
roe.dev ✅ Ready (Inspect) Visit Preview Nov 6, 2024 11:41pm

Copy link

cloudflare-workers-and-pages bot commented Nov 6, 2024

Deploying danielroe with  Cloudflare Pages  Cloudflare Pages

Latest commit: 9ba2a24
Status: ✅  Deploy successful!
Preview URL: https://b406aae0.danielroe.pages.dev
Branch Preview URL: https://build-cf-module.danielroe.pages.dev

View logs

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

🧹 Outside diff range and nitpick comments (2)
nuxt.config.ts (2)

Line range hint 307-316: Consider security implications of disabled COEP

Whilst the CSP changes for GitHub avatars are necessary, disabling the Cross-Origin Embedder Policy might have security implications. Consider:

  1. Using requireCorp instead of completely disabling COEP
  2. Adding a more restrictive CSP by specifying exact domains for image sources

Line range hint 251-279: Remove duplicate domain entries

The domains list contains a duplicate entry for 'conf.vuejs.de'. Consider:

  1. Removing the duplicate
  2. Adding a comment to indicate which domains are temporary (event-specific)
  3. Sorting the domains alphabetically for better maintenance
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between e23ed3a and 0671baa.

📒 Files selected for processing (1)
  • nuxt.config.ts (1 hunks)
🔇 Additional comments (3)
nuxt.config.ts (3)

Line range hint 297-300: LGTM: Well-configured analytics setup

Using a custom subdomain for Plausible analytics is a good practice for better privacy and tracking protection.


Line range hint 142-149: Verify stability of experimental features

Enabling multiple experimental features could affect production stability. Consider:

  1. Documenting why each experimental feature is needed
  2. Adding feature flags to disable them quickly if issues arise

Let's check for any known issues with these features:

#!/bin/bash
# Search for any reported issues with the experimental features
rg -i "cookieStore|headNext|viewTransition|typedPages" .github/issues

150-150: Verify compatibility date implications

The compatibility date has been set quite far in the future. This might introduce breaking changes or deprecations that could affect the application.

Let's check for any compatibility-related changes in the repository:

✅ Verification successful

Compatibility date setting is appropriate

The compatibility date of '2024-09-19' aligns with the project's modern dependencies, including Nuxt v3.14.159 and Vue 3.5.12. The configuration also shows a compatibility version of 4, which is the current standard. This forward-dated setting is actually beneficial for ensuring the application maintains consistent behaviour with current features.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for compatibility-related changes or issues
rg -i "compatibility|breaking.?changes?" README.md

Length of output: 126


Script:

#!/bin/bash
# Let's check the package.json for Nuxt version and dependencies
cat package.json

# Also check for any migration guides or compatibility notes in docs
fd -t f -e md . | xargs rg -i "compatibility|breaking.?changes?"

# Check for Nuxt configuration patterns
rg -i "compatibility" --type ts

Length of output: 3689

Copy link

socket-security bot commented Nov 6, 2024

New and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/@aws-sdk/[email protected] Transitive: environment, filesystem, network +93 8.02 MB amzn-oss, aws-sdk-bot, kuhe, ...2 more
npm/@aws-sdk/[email protected] Transitive: environment, filesystem, network +34 1.85 MB aws-sdk-bot

🚮 Removed packages: npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected]

View full report↗︎

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: 5

🧹 Outside diff range and nitpick comments (3)
modules/runtime/server/slides.ts (1)

10-18: Consider making bucket configuration more flexible.

The S3 client configuration could benefit from making the bucket name configurable through runtime config.

Consider moving the bucket name to the runtime config:

 const s3Client = new S3Client({
   endpoint: config.cloudflare.s3Url,
   region: 'auto',
   credentials: {
     accessKeyId: config.cloudflare.r2TokenId,
     secretAccessKey: config.cloudflare.r2TokenKey,
   },
 })
+const bucket = config.cloudflare.bucket || 'slides'
nuxt.config.ts (1)

126-126: Verify cache duration for thumbnails

The cache duration of one year for thumbnails is quite aggressive. Ensure you have a strategy in place for cache invalidation if thumbnails need updating.

Consider implementing a cache-busting mechanism, such as including a version or hash in the thumbnail URLs.

modules/slides.ts (1)

2-2: Remove unused import 'useNuxt'

The useNuxt function is imported from 'nuxt/kit' but is not utilised in the code. Removing unused imports helps to keep the codebase clean and maintainable.

Apply this diff to remove the unused import:

-import { addServerHandler, createResolver, defineNuxtModule, useNuxt, useRuntimeConfig } from 'nuxt/kit'
+import { addServerHandler, createResolver, defineNuxtModule, useRuntimeConfig } from 'nuxt/kit'
🧰 Tools
🪛 GitHub Check: test

[failure] 2-2:
'useNuxt' is defined but never used. Allowed unused vars must match /^_/u

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 0671baa and 9d65653.

⛔ Files ignored due to path filters (2)
  • package.json is excluded by !package.json, !**/package.json
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml, !pnpm-lock.yaml
📒 Files selected for processing (4)
  • .gitignore (2 hunks)
  • modules/runtime/server/slides.ts (1 hunks)
  • modules/slides.ts (1 hunks)
  • nuxt.config.ts (3 hunks)
🧰 Additional context used
🪛 GitHub Check: test
modules/slides.ts

[failure] 2-2:
'useNuxt' is defined but never used. Allowed unused vars must match /^_/u

🔇 Additional comments (6)
modules/runtime/server/slides.ts (1)

1-3: LGTM! Proper import declarations.

The imports are well-structured, using the recommended node: prefix for native modules and importing specific functions from AWS SDK packages.

.gitignore (2)

61-61: Good addition for security!

Adding .env.production to .gitignore is crucial for preventing production environment variables from being accidentally committed.


100-101: Appropriate exclusion for Wrangler files

The addition of .wrangler aligns with the PR's objective of integrating the Cloudflare module preset. This ensures that local Wrangler development settings and caches aren't tracked in version control.

nuxt.config.ts (2)

155-155: Verify compatibility date requirements

The compatibility date is set to '2024-09-19', which is a future date. Please confirm this is intentional and verify the specific Cloudflare Workers features that require this future compatibility date.

Let's check the Cloudflare Workers documentation for this compatibility date:

#!/bin/bash
# Search for any Cloudflare Workers-related configurations
rg -g '!node_modules' 'workers.*compatibility'

124-124: Review CORS configuration for API endpoint

The /api/hi endpoint has CORS enabled. Consider restricting the CORS configuration to specific origins rather than allowing all origins.

Let's check for any existing CORS configurations:

#!/bin/bash
# Search for CORS-related configurations
rg -g '!node_modules' -A 5 'cors:.*true' 
modules/slides.ts (1)

86-86: Ensure 'config.accountId' is defined in runtime configuration

In the code snippet for obtaining a Cloudflare R2 token, config.accountId is referenced but may not be defined in your runtime configuration. Please verify that config.accountId is set within useRuntimeConfig() to prevent potential issues.

Would you like assistance in updating the runtime configuration to include accountId?

modules/runtime/server/slides.ts Outdated Show resolved Hide resolved
modules/runtime/server/slides.ts Outdated Show resolved Hide resolved
modules/runtime/server/slides.ts Outdated Show resolved Hide resolved
nuxt.config.ts Show resolved Hide resolved
modules/slides.ts Outdated Show resolved Hide resolved
@danielroe danielroe changed the title chore: add wrangler.toml for cloudflare_module preset feat: use cloudflare r2 for storing slide pdfs Nov 6, 2024
@danielroe danielroe merged commit ec81eb1 into main Nov 6, 2024
12 checks passed
@danielroe danielroe deleted the build/cf-module branch November 6, 2024 23:48
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