-
Notifications
You must be signed in to change notification settings - Fork 343
fix(content-sharing): Fix create shared link bug #4443
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
Conversation
WalkthroughThis PR adds a Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Hook as useSharingService
participant FileAPI
participant Service as SharingService
participant Server
Client->>Hook: request sharing service (item, sharedLink?)
Hook->>FileAPI: getFileAPI(...) (if item present)
FileAPI-->>Hook: itemApiInstance
Hook->>Service: createSharingService({ api: itemApiInstance, hasSharedLink: !!sharedLink?.url, options... })
Service-->>Hook: SharingService instance
Client->>Service: e.g., updateSharedLink / deleteSharedLink / changeAccess
alt hasSharedLink == true
Service->>Server: perform API call
Server-->>Service: success
else hasSharedLink == false
Service-->>Client: reject 404 "Shared link not found"
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 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. Comment |
There was a problem hiding this 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
🤖 Fix all issues with AI agents
In `@src/elements/content-sharing/sharingService.ts`:
- Around line 22-23: Make hasSharedLink required on CreateSharingServiceArgs
(change hasSharedLink?: boolean to hasSharedLink: boolean) so callers like
useSharingService and any future call sites must pass the flag, and update those
callers accordingly; also extract the repeated Object.assign(new Error('Shared
link not found'), { status: 404 }) into a single helper (e.g.,
createSharedLinkNotFoundError or SHARED_LINK_NOT_FOUND_ERROR) and use that
helper in the four guarded methods changeSharedLinkAccess,
changeSharedLinkPermission, updateSharedLink, and deleteSharedLink to remove
duplication.
🧹 Nitpick comments (2)
src/elements/content-sharing/sharingService.ts (1)
39-42: Consider extracting the repeated 404 rejection into a helper.The same
Promise.reject(Object.assign(new Error('Shared link not found'), { status: 404 }))pattern is duplicated in four methods. A small helper would reduce repetition and ensure consistency if the error shape ever changes.Suggested helper
+const rejectSharedLinkNotFound = () => + Promise.reject(Object.assign(new Error('Shared link not found'), { status: 404 })); + const changeSharedLinkAccess = async (access: string): Promise<void> => { if (!hasSharedLink) { - return Promise.reject(Object.assign(new Error('Shared link not found'), { status: 404 })); + return rejectSharedLinkNotFound(); }Then reuse in the other three guards.
src/elements/content-sharing/hooks/useSharingService.ts (1)
72-78:hasSharedLink: !!sharedLink?.urlis a sound heuristic but worth a brief comment.Using the presence of
urlas the canonical indicator of an existing shared link is reasonable — an object without a URL hasn't been persisted server-side yet. A short inline comment would help future maintainers understand whyurl(rather than just the object's truthiness) is the criteria.
1ac27c6 to
672161f
Compare
tjuanitas
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👏
Merge Queue StatusRule:
This pull request spent 7 seconds in the queue, with no time running CI. Required conditions to merge
|
Summary
Issue
Solution
Test plan
Summary by CodeRabbit
Bug Fixes
Behavioral Changes
Tests