Add comment system with Turso/libSQL backend#17
Open
cbcruk wants to merge 2 commits into
Open
Conversation
블루스카이 대신 직접 만든 코멘트 기능. 정적 GH Pages 사이트가 Vercel 서버리스 API(/api/comments)를 CORS로 호출하고, libSQL(Turso)에 익명+이름 코멘트를 저장한다. - src/lib/comments.ts: libSQL 클라이언트 + 조회/작성 + 검증/레이트리밋/IP 해시 - src/pages/api/comments.ts: GET(목록)/POST(작성)/OPTIONS, 허니팟 - src/components/Comments/: React 아일랜드(SWR), client:visible로 메모 하단 삽입 - scripts/init-comments.mjs, moderate-comments.mjs: 초기화/직접 모더레이션 - 스팸 방어: 허니팟 + IP 레이트리밋(60초당 3) + status(approved/hidden/spam) - vite 8.1.0 고정: libsql 추가 시 tailwind가 vite5로 재바인딩되는 문제 방지 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MFFjbY1BjD6UEUj3ko7N7N
|
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
작성 즉시 노출 → 승인 후 노출로 변경. 익명 코멘트의 스팸/노출 통제 강화.
- 스키마 기본값 approved → pending, CHECK에 pending 추가
- POST 응답을 {status:'pending'}으로, 폼은 "승인 후 표시" 안내
- Comments 아일랜드: 낙관적 삽입 제거, 승인 안내 문구 추가
- moderate: `pending` 큐 조회 추가, `list`는 대기 건 우선 정렬
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MFFjbY1BjD6UEUj3ko7N7N
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements a full-featured comment system for memos using Turso (libSQL) as the backend database. Comments are managed through a Vercel serverless API endpoint with client-side React components for display and submission.
Key Changes
Backend (
src/lib/comments.ts): Core comment service with Turso/libSQL integrationgetComments()- Fetch approved comments for a memocreateComment()- Validate and insert new comments with IP-based rate limitinghashIp()- SHA256 hashing for IP anonymization (no raw IPs stored)API Route (
src/pages/api/comments.ts): Astro serverless endpointmemoIdvercel.jsonReact Components (
src/components/Comments/):Comments.tsx- Main container with SWR data fetching and optimistic updatesCommentForm.tsx- Form with validation, honeypot field, and pending stateCommentList.tsx- Display comments with UTC→local time conversionCommentPrimitive.tsx- Styled components usingreact-twcComments.types.ts- Shared types and API client functionsDatabase Setup:
scripts/init-comments.mjs- Create comment table with indexesscripts/moderate-comments.mjs- CLI tool for moderation (list/hide/spam/approve/delete)Configuration:
.env.example- Document required env vars (TURSO_DATABASE_URL, TURSO_AUTH_TOKEN, COMMENT_IP_SALT)tsconfig.json- Add@lib/*path aliaspackage.json- Add@libsql/clientdependencyvercel.json- Add CORS headers for API routes.gitignore- Exclude localcomments.db*filesIntegration: Wire Comments component into memo detail page (
src/pages/memo/[id].astro)Implementation Details
website) + IP-based rate limiting + approval-required statusfile:comments.dbwhen env vars not sethttps://claude.ai/code/session_01MFFjbY1BjD6UEUj3ko7N7N