refactor: restructure codebase and add REST API layer#3
Open
kennhung wants to merge 1 commit into
Open
Conversation
- Introduce config.ts to centralize all env var parsing/validation
- Introduce db.ts as a MongoDB connection factory with typed DbCollections
- Move all modules under src/modules/, merging confusingly-named
google-drive-check + google-drive-checker into modules/google-drive/
(handler.ts for Slack integration, checker.ts for pure Drive logic)
- Add SettingsStore (modules/settings/store.ts) for MongoDB-backed
runtime settings with in-memory cache
- Add REST API under /api/* (Express, Bearer token auth):
GET/ /api/messages (collection, limit, cursor pagination)
GET /api/messages/:id
GET /api/drive/jobs (status filter, cursor pagination)
GET /api/drive/jobs/:id
GET /api/settings
PATCH /api/settings (runtime feature flag control)
- Remove unused deps: args, async, nanoid; add express + @types/express
- Add clean script; build now removes dist/ before compiling
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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
src/modules/,解決google-drive-checkvsgoogle-drive-checker命名混淆問題,合併為modules/google-drive/handler.ts(Slack 整合)和checker.ts(純 Drive 邏輯)config.ts(集中所有 env var 解析)和db.ts(MongoDB 連線工廠),app.ts從 120 行縮到 90 行/api/*端點,Bearer token 驗證,支援查看 Slack 訊息、Drive 合規記錄,以及動態調整 Bot 設定New API Endpoints
All endpoints require
Authorization: Bearer <API_KEY>header./api/messages?collection=messages|changedMessages|deletedMessages&limit=50&before=<cursor>)/api/messages/:id/api/drive/jobs?status=pending|completed|error)/api/drive/jobs/:id/api/settings/api/settingsNew env vars required
API_KEY— Bearer token for API authenticationAPI_PORT— HTTP port (default:3000)Test plan
npm run buildpasses with no TypeScript errorscurl -H "Authorization: Bearer <key>" http://localhost:3000/api/messagesreturns message listcurl -H "Authorization: Bearer <key>" http://localhost:3000/api/drive/jobsreturns job listcurl -X PATCH -H "Authorization: Bearer <key>" -H "Content-Type: application/json" -d '{"useReactionCheck":false}' http://localhost:3000/api/settingsupdates settings🤖 Generated with Claude Code