Conversation
waterbro-8
left a comment
There was a problem hiding this comment.
The like-identity work for #72 is the right direction, but this PR currently ships two other threads and cannot merge as-is.
-
Drop the #65 overlap. These files are the i18n/timeAgo/version-timestamp change from #65, not like identity:
src/lib/dt.ts,src/__tests__/lib/dt.test.tsmessages/en.json,messages/zh-cn.jsonstar-list.tsx,trash.tsx,content-home.tsxsrc/app/api/doc-version/route.ts,version-dialog.tsx
Same class of problem as #67. Please rebase onto current
mainand keep only PubDocLike / viewer-id / thumb-up routes /thumb-up-button.tsx/ the like CHANGELOG line. -
Coordinate with #70. #70 already rewrites unlike + rollback on
thumb-up-button/ decrease route. After stripping #65, rebase onto (or wait for) #70 so the identity table is additive rather than a conflicting rewrite of the same files.
I cannot push your fork. After a like-only push I can re-review.
ea81652 to
404c97d
Compare
waterbro-8
left a comment
There was a problem hiding this comment.
Re-review: the #65 i18n/timeAgo/version-timestamp files are gone. Remaining change is PubDocLike + viewer cookie + idempotent like/unlike, which is the right #72 design. CI is green.
Still overlaps #70 on thumb-up-button / decrease route — land this as the like-identity successor and drop or rebase #70 rather than merging both. I cannot satisfy CODEOWNERS myself.
Bindy-lbb
left a comment
There was a problem hiding this comment.
CODEOWNERS Review: Approved
Summary of Changes
- Schema & Migration: Adds
PubDocLikewith(viewerId, pubDocId)compound unique index and proper foreign key cascade onpubDocId. - Identity Resolution: Adds
resolveViewerIdcleanly falling back from authenticated session to HTTP-only cookie-backed UUID. - Endpoint Idempotency:
GET /api/pub/thumb-up/[publishId]: Fetches current like status and total count.PATCH /api/pub/thumb-up/[publishId]: Atomic increment + record creation in$transaction.PATCH /api/pub/thumb-up-decrease/[publishId]: Idempotent like cancellation clamped at 0.
- Client Component: Smooth transition in
ThumbUpButtonfromlocalStorageto server-backed state with optimistic UI and error recovery. - Scope: Cleanly decoupled from PR #65 i18n/timestamp changes as requested during earlier review cycles.
All CI checks are green. Approved for merge.
|
#65 已合入 |
404c97d to
7d348fd
Compare
Bindy-lbb
left a comment
There was a problem hiding this comment.
LGTM. Server-side like identity is well-designed: PubDocLike table with (viewerId, pubDocId) unique constraint, cookie-based anonymous viewer fallback with httpOnly/sameSite/secure flags, authenticated users get user: prefix. Like/unlike idempotency is correct — duplicate like is a no-op returning current state, cancel only decrements if the viewer actually holds a like. The transaction in the like path ensures atomicity between count increment and like record creation. ThumbUpButton properly migrated from localStorage to API-based state. Migration SQL is clean with appropriate index on pubDocId and CASCADE delete.
Summary
PubDocLiketable with(viewerId, pubDocId)unique constraint to track likes per viewer server-sideviewer_idhttpOnly cookie) for unauthenticated visitors;user:<id>for authenticated userslocalStorageinThumbUpButtonwith server-side state fetched via newGETendpointChanges
prisma/schema.prismaPubDocLikemodel +likesrelation onPubDocprisma/migrations/...PubDocLiketablesrc/lib/viewer-id.tsresolveViewerId()helper (auth session → cookie fallback)src/app/api/pub/thumb-up/[publishId]/route.tsGET, rewritePATCHfor idempotent increasesrc/app/api/pub/thumb-up-decrease/[publishId]/route.tsPATCHto delete viewer's like and decrementsrc/components/thumb-up-button.tsxlocalStoragewith API-based stateCHANGELOG.md[Unreleased]Test plan
npx prisma migrate devapplies the migration successfullynpm run buildpassesCloses #72