refactor(worker): extract videos routes into videos.ts#39
Conversation
index.ts crossed the 500-line guideline (542) so the trending/list/get/ upload/delete handlers move to a dedicated videos.ts module, mirroring the existing pattern (channels.ts, comments.ts, dmca.ts, etc.). Pure extraction — no behavioural changes. index.ts is now 142 lines and just wires sub-apps; videos.ts owns all /api/videos/* routes plus the upload-meta zod schema that was previously inline. https://claude.ai/code/session_01YJvfCwicKZAbyhnj6W6GfY
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
Disabled knowledge base sources:
WalkthroughThis change refactors the video API implementation by extracting inlined route handlers from the main worker into a dedicated Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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.
Code Review
This pull request refactors the codebase by modularizing video-related logic, moving routes, schemas, and types from src/workers/index.ts into a new dedicated file, src/workers/videos.ts. This change improves the maintainability and organization of the main worker entry point. Review feedback highlights opportunities to further improve the code by centralizing duplicated type and interface definitions (such as SessionUser and AnalyticsEngineDataset) and using safeParse for session metadata to prevent unhandled exceptions during JSON parsing.
| interface AnalyticsEngineDataset { | ||
| writeDataPoint(point: { blobs?: string[]; doubles?: number[]; indexes?: string[] }): void; | ||
| } |
There was a problem hiding this comment.
The AnalyticsEngineDataset interface is duplicated here and in src/workers/analytics.ts. To improve maintainability and follow the DRY (Don't Repeat Yourself) principle, consider moving shared interfaces and types to a common file (e.g., src/workers/types.ts) or exporting them from their primary source.
| ANALYTICS?: AnalyticsEngineDataset; | ||
| } | ||
|
|
||
| type SessionUser = { id: string; email: string; name: string } | null; |
| return c.json({ error: 'Missing upload session. Start with chunkIndex=0.' }, 400); | ||
| } | ||
|
|
||
| const uploadMeta = uploadMetaPersistedSchema.parse(JSON.parse(uploadMetaJson)); |
There was a problem hiding this comment.
Using .parse() directly on JSON.parse() results can throw unhandled exceptions if the stored session metadata is corrupted or has an unexpected schema. For consistency with how other inputs are handled in this file (e.g., query parameters and form data), consider using safeParse and providing a structured error response.
| const uploadMeta = uploadMetaPersistedSchema.parse(JSON.parse(uploadMetaJson)); | |
| const uploadMetaParsed = uploadMetaPersistedSchema.safeParse(JSON.parse(uploadMetaJson)); | |
| if (!uploadMetaParsed.success) { | |
| return c.json({ error: 'Invalid upload session metadata' }, 400); | |
| } | |
| const uploadMeta = uploadMetaParsed.data; |
Summary
src/workers/index.tshad grown to 542 lines (over the 500-line guideline). The trending/list/get/upload/delete handlers move to a newsrc/workers/videos.ts, mirroring the existing modular pattern (channels.ts,comments.ts,dmca.ts,moderation.ts, ...).uploadMetaPersistedSchema) instead of an inline object, but the validation rules are identical.index.tsis 142 lines and only wires sub-apps + middleware + the queue/scheduled handlers;videos.tsis 413 lines and owns all/api/videos/*routes.Test plan
npm run lint— 0 warnings, 0 errorsnpm run type-check— cleannpm test— 17 files / 129 tests passingnpm run build— cleanhttps://claude.ai/code/session_01YJvfCwicKZAbyhnj6W6GfY
Generated by Claude Code
Summary by CodeRabbit