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

docs: add callouts and examples for keygen in other languages #1035

Merged
merged 5 commits into from
Oct 29, 2024

Conversation

juliusmarminge
Copy link
Collaborator

@juliusmarminge juliusmarminge commented Oct 28, 2024

TODO

Summary by CodeRabbit

  • Documentation

    • Enhanced documentation for file uploads, including a new section on generating valid file keys using JavaScript SDK with examples in Python, PHP, and Go.
    • Added a note regarding potential latency when requesting file keys from the /v7/prepareUpload REST endpoint.
    • Improved document structure with tabs for different programming languages for easier navigation.
    • Clarified the server-side upload process and reinforced the importance of correct parameter handling.
  • Bug Fixes

    • Updated function signature for generateKey to improve clarity in the documentation.
  • Chores

    • Expanded syntax highlighting capabilities to include Go and PHP in code snippets.

Copy link

changeset-bot bot commented Oct 28, 2024

⚠️ No Changeset found

Latest commit: b7bfe56

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

vercel bot commented Oct 28, 2024

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

Name Status Preview Comments Updated (UTC)
docs-uploadthing ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 29, 2024 7:27pm
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
legacy-docs-uploadthing ⬜️ Ignored (Inspect) Visit Preview Oct 29, 2024 7:27pm

Copy link
Contributor

coderabbitai bot commented Oct 28, 2024

Warning

Rate limit exceeded

@juliusmarminge has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 11 minutes and 8 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

Files that changed from the base of the PR and between 8a3632c and b7bfe56.

Walkthrough

The changes primarily enhance the documentation for file uploads to UploadThing. A new section detailing the generation of valid file keys has been added, including code snippets in multiple programming languages. The documentation structure has been improved with tabs for easier navigation. Additionally, updates were made to the generateKey function syntax, and modifications were introduced to the rehypeShiki function to support syntax highlighting for Go and PHP. Overall, these changes aim to improve clarity and usability for developers.

Changes

File Path Change Summary
docs/src/app/(docs)/uploading-files/page.mdx Added a new section on generating valid file keys with code snippets in JavaScript, Python, PHP, and Go; modified generateKey function from arrow to standard function; clarified server-side upload process and added caution about parameter matching.
docs/src/mdx/rehype.js Updated rehypeShiki function to include "go" and "php" in the syntax highlighting capabilities.

Possibly related PRs

Suggested labels

examples

Poem

In the land of code where rabbits play,
New keys for uploads brighten the way.
With snippets in paws, we hop and we cheer,
For clearer docs bring us all near!
So let’s share our wisdom, both far and wide,
In the world of UploadThing, let’s take pride! 🐇✨


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
Contributor

github-actions bot commented Oct 28, 2024

📦 Bundle size comparison

Bundle Size (gzip) Visualization
Main 27.50KB See Treemap 📊
PR (20bf796) 27.50KB See Treemap 📊
Diff No change

@juliusmarminge juliusmarminge changed the title add callouts and examples for keygen in other languages docs: add callouts and examples for keygen in other languages Oct 28, 2024
@markflorkowski
Copy link
Collaborator

idk what other langs to include 😅 ruby?

I think ruby and Java are probably the two other big ones. I have had a surprising number of people ask about dotnet too, but I don't think there is really demand there

@juliusmarminge
Copy link
Collaborator Author

and Java

god do i have to install java on my system...

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 and nitpick comments (3)
docs/src/mdx/rehype.js (1)

40-41: LGTM! Consider adding Ruby support.

The addition of Go and PHP syntax highlighting support is correctly implemented. Since Ruby was mentioned as a potential addition in the PR objectives, consider adding "ruby" to the langs array if Ruby examples will be included in the documentation.

docs/src/app/(docs)/uploading-files/page.mdx (2)

Line range hint 140-154: Consider adding error handling for base64 encoding.

The JavaScript implementation should handle potential errors during base64 encoding.

 function generateKey(appId: string, fileSeed: string) {
   const alphabet = shuffle(defaultOptions.alphabet, appId);
 
   const encodedAppId = new SQIds({ alphabet, minLength: 12 }).encode([
     Math.abs(Hash.string(appId)),
   ]);
 
-  const encodedFileSeed = encodeBase64(fileSeed);
+  try {
+    const encodedFileSeed = encodeBase64(fileSeed);
+    return `${encodedAppId}${encodedFileSeed}`;
+  } catch (error) {
+    throw new Error(`Failed to encode file seed: ${error.message}`);
+  }
-  return `${encodedAppId}${encodedFileSeed}`;
 }

191-199: Add type hints for better code clarity in Python.

The Python implementation would benefit from complete type hints.

-def generate_key(file_seed: str, app_id: str) -> str:
+def generate_key(file_seed: str, app_id: str) -> str:
   alphabet = shuffle(constants.DEFAULT_ALPHABET, app_id)
 
-  encoded_app_id = Sqids(alphabet, min_length=12).encode(
+  encoded_app_id: str = Sqids(alphabet=alphabet, min_length=12).encode(
     [abs(hash_string(app_id))]
   )
 
   return encoded_app_id + file_seed
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between bb3054f and 8635312.

📒 Files selected for processing (2)
  • docs/src/app/(docs)/uploading-files/page.mdx (3 hunks)
  • docs/src/mdx/rehype.js (1 hunks)
🧰 Additional context used
🪛 LanguageTool
docs/src/app/(docs)/uploading-files/page.mdx

[style] ~106-~106: Try using a more formal synonym here to elevate your writing.
Context: ...se to generate valid file keys. We also plan on making this process easier in the future. <No...

(PLAN_ON_INTEND)


[duplication] ~116-~116: Possible typo: you repeated a word
Context: ...xtra latency to your uploads. <Tabs tabs={["JavaScript", "Python", "PHP", "Go"]}...

(ENGLISH_WORD_REPEAT_RULE)

🔇 Additional comments (2)
docs/src/app/(docs)/uploading-files/page.mdx (2)

116-116: LGTM! Tabs implementation is correct.

The tabs implementation properly follows MDX conventions and provides a good user experience for switching between language examples.

🧰 Tools
🪛 LanguageTool

[duplication] ~116-~116: Possible typo: you repeated a word
Context: ...xtra latency to your uploads. <Tabs tabs={["JavaScript", "Python", "PHP", "Go"]}...

(ENGLISH_WORD_REPEAT_RULE)


105-114: Consider rephrasing for clarity and formality.

Consider revising "we also plan on making" to "we intend to make" for a more formal tone.

Let's verify the referenced endpoint exists:

🧰 Tools
🪛 LanguageTool

[style] ~106-~106: Try using a more formal synonym here to elevate your writing.
Context: ...se to generate valid file keys. We also plan on making this process easier in the future. <No...

(PLAN_ON_INTEND)

docs/src/app/(docs)/uploading-files/page.mdx Outdated Show resolved Hide resolved
docs/src/app/(docs)/uploading-files/page.mdx Show resolved Hide resolved
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.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: 3

🧹 Outside diff range and nitpick comments (1)
docs/src/app/(docs)/uploading-files/page.mdx (1)

Line range hint 140-155: Add missing base64 encoding implementation.

The code mentions using base64 encoding for the file seed but doesn't show the implementation. Consider adding the encoding function for completeness:

function encodeBase64(str: string): string {
  return Buffer.from(str).toString('base64url')
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 8635312 and 8a3632c.

📒 Files selected for processing (1)
  • docs/src/app/(docs)/uploading-files/page.mdx (3 hunks)
🧰 Additional context used
🪛 LanguageTool
docs/src/app/(docs)/uploading-files/page.mdx

[style] ~106-~106: Try using a more formal synonym here to elevate your writing.
Context: ...se to generate valid file keys. We also plan on making this process easier in the future. <No...

(PLAN_ON_INTEND)


[duplication] ~116-~116: Possible typo: you repeated a word
Context: ...xtra latency to your uploads. <Tabs tabs={["JavaScript", "Python", "PHP", "Go"]}...

(ENGLISH_WORD_REPEAT_RULE)

🔇 Additional comments (1)
docs/src/app/(docs)/uploading-files/page.mdx (1)

105-114: LGTM! Clear and informative introduction.

The introduction effectively sets up the context for the code examples and provides a helpful note about the REST endpoint fallback option.

🧰 Tools
🪛 LanguageTool

[style] ~106-~106: Try using a more formal synonym here to elevate your writing.
Context: ...se to generate valid file keys. We also plan on making this process easier in the future. <No...

(PLAN_ON_INTEND)

docs/src/app/(docs)/uploading-files/page.mdx Outdated Show resolved Hide resolved
docs/src/app/(docs)/uploading-files/page.mdx Show resolved Hide resolved
docs/src/app/(docs)/uploading-files/page.mdx Show resolved Hide resolved
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants