Refactor the notification handling logic to use a unified `topic` based payload structure. This change replaces the flat `NotificationData` interface with a typed `topic` and `data` separation, enabling stricter type checking for different notification types (e.g., `SERVER_PUSH`). Key changes: - Updated `NotificationData` type to include `topic` and `data` fields, referencing `TopicPayload`. - Modified `sw.js` to parse incoming `MessagePayload` using `fromMessagePayload`, ensuring the topic is `SERVER_PUSH` before extracting `title` and `options`. - Renamed internal types in `utils/common.ts` to `ServerSendTopicPayload` and `Topics` for clarity. - Updated `firebase-admin.ts` to wrap data in a `payload` JSON string before sending to Firebase Cloud Messaging, and added logic to clean up unregistered tokens. - Added backward compatibility support for older clients by sending a secondary legacy-formatted message when a `SERVER_PUSH` topic is detected. - Moved `NOTIFICATION_TOKEN_KEY` constant to `utils/constants.ts` and updated related hooks to use it for consistency. - Updated `logger.ts` to comment out file logging during development/testing to reduce disk I/O. This refactor improves type safety, reduces code duplication in payload handling, and ensures better compatibility between the web client and the service worker. |
||
|---|---|---|
| __test__ | ||
| .vscode | ||
| assets | ||
| prisma | ||
| src | ||
| .env.example | ||
| .gitignore | ||
| bun-env.d.ts | ||
| bun.lock | ||
| bunfig.toml | ||
| docker-compose.yml | ||
| dockerfile | ||
| package.json | ||
| prisma.config.ts | ||
| README.md | ||
| tsconfig.json | ||
My-Kaiqiuwang
To install dependencies:
bun install
To start a development server:
bun dev
To run for production:
bun start
This project was created using bun init in bun v1.2.21. Bun is a fast all-in-one JavaScript runtime.
Database
Prisma
设计阶段
bun --env-file=.env.development prisma db push
开发阶段, 生成代码
bun --env-file=.env.development prisma generate
在开发环境生成 migration 文件
bun --env-file=.env.development prisma migrate dev --name=<name>
同步到测试环境,跑测试用例用(如果需要的话)
bun --env-file=.env.test prisma migrate deploy