Skip to content

Add back username handling#6

Open
reynaldichernando wants to merge 2 commits intoJavaScript-Mastery-Pro:mainfrom
reynaldichernando:username
Open

Add back username handling#6
reynaldichernando wants to merge 2 commits intoJavaScript-Mastery-Pro:mainfrom
reynaldichernando:username

Conversation

@reynaldichernando
Copy link
Contributor

@reynaldichernando reynaldichernando commented Feb 11, 2026

  • ensure username update on save
image

Summary by CodeRabbit

  • New Features

    • Public projects now show the username of the sharer for clearer attribution across listings and individual project views.
    • Username lookups are cached to improve load performance when browsing shared projects.
  • Chores

    • Clearing public projects also removes cached usernames and returns cleared-username info in the response.

@vercel
Copy link

vercel bot commented Feb 11, 2026

@reynaldichernando is attempting to deploy a commit to the JS Mastery Pro Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link

coderabbitai bot commented Feb 11, 2026

📝 Walkthrough

Walkthrough

Adds USER_PREFIX and resolveUsername helper to fetch/cache usernames in KV. For public projects, list/get/save flows now resolve ownerId → username and attach it as sharedBy; save caches usernames; clear deletes USER_PREFIX entries and returns clearedUsernames.

Changes

Cohort / File(s) Summary
Username resolution & caching
lib/puter.worker.js
Added USER_PREFIX constant and resolveUsername(mePuter, userId) helper to read/write usernames in KV. GET /api/projects/list and GET /api/projects/get (public scope) resolve ownerId → username and annotate items with sharedBy. POST /api/projects/save caches username after user lookup. POST /api/projects/clear deletes USER_PREFIX entries and returns clearedUsernames.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant Client as Client
    participant API as "API (/api/projects/*)"
    participant Worker as "puter.worker.js"
    participant KV as "KV Store"

    rect rgba(200,200,255,0.5)
    Client->>API: request /api/projects/list (public)
    API->>Worker: forward request
    Worker->>KV: fetch public items (ownerId list)
    Worker->>KV: batch get USER_PREFIX+ownerId -> username(s)
    KV-->>Worker: usernames (or miss)
    Worker->>KV: on miss, fetch user info and KV.put(USER_PREFIX+id, username)
    Worker-->>API: annotated items with sharedBy
    end

    API-->>Client: response with items (+ sharedBy, clearedUsernames when clearing)
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

Possibly related PRs

  • Refactor workers #4: Modifies the same lib/puter.worker.js file with similar sharedBy username resolution logic, though using a different approach to caching and helper implementation.

Suggested reviewers

  • sujatagunale

Poem

🐰 I hopped through keys with a curious twitch,
I found usernames, cached them quick!
List, get, save — I leave a trail,
Cleared the hops when caches fail. 🥕✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Add back username handling' accurately reflects the main changes: adding username resolution and caching logic throughout the API endpoints.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

No actionable comments were generated in the recent review. 🎉

🧹 Recent nitpick comments
lib/puter.worker.js (1)

57-61: Consider adding a try/catch for resilience.

If mePuter.kv.get throws (e.g., transient KV error), this propagates up and — in the /list endpoint — fails the entire Promise.all, taking down the whole response. A defensive try/catch returning null would gracefully degrade (missing username) instead of failing the request.

🛡️ Proposed defensive wrapper
 const resolveUsername = async (mePuter, userId) => {
   if (!userId) return null;
-  const userRecord = await mePuter.kv.get(`${USER_PREFIX}${userId}`);
-  return userRecord?.username || null;
+  try {
+    const userRecord = await mePuter.kv.get(`${USER_PREFIX}${userId}`);
+    return userRecord?.username || null;
+  } catch {
+    return null;
+  }
 };

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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