修复 #37 bug#38
Merged
Merged
Conversation
主要改动: - Worker: 提取 rateLimit 到独立模块,简化更新逻辑(删除 user/ai 分支) - 扩展: 使用 AbortController 替代 Promise.race 实现可取消超时 - 修复: 点击切换广告段 active 状态也标记为用户修正 - 修复: createSkipButton 重复调用问题 - 删除: enableCloudCache/cloudCacheWorkerUrl 相关代码(强制开启云端缓存) - 测试: 修复多个测试用例描述和 NaN/Infinity 校验 文档更新: - CLAUDE.md: 修正 KV key 格式,简化云端缓存描述 - Worker README.md: 删除过时的配置步骤
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
There was a problem hiding this comment.
Pull request overview
该 PR 主要围绕 Worker 云端缓存服务与扩展侧云端交互做一致性调整,并尝试修复 #37 所涉及的相关逻辑问题(包括限流、云端写入逻辑与请求超时处理)。
Changes:
- 将 Worker 的 rate limit 逻辑抽离为独立模块
worker/src/rateLimit.ts,并在 Worker 入口复用该模块的限流配置与清理逻辑。 - 调整 Worker
POST /api/cache的更新策略为“基于已有记录覆盖字段”,并更新相关校验与测试。 - 扩展侧:简化云端缓存保存接口(去掉 accuracy override 参数)、补充用户交互“视为修正”的标记、并用
AbortController实现云端请求超时。
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| worker/src/rateLimit.ts | 新增 Worker 端内存限流模块与默认限流配置。 |
| worker/src/rateLimit.test.ts | 由“模拟实现”改为直接测试 rateLimit 模块导出能力与配置。 |
| worker/src/index.ts | 移除内联限流实现,改为导入模块;并调整 KV 写入更新逻辑与数值校验。 |
| worker/src/bvid.test.ts | 修正用例描述文本,使其与断言一致。 |
| worker/src/adTimeRanges.test.ts | 与 Worker 端校验保持一致(Number.isFinite)。 |
| worker/README.md | 更新 Worker 部署文档步骤(移除扩展侧手动填写 URL 的说明)。 |
| test/parseAdResult.test.ts | 增加对弯引号/中文引号替换场景的覆盖。 |
| src/services/cloud-cache.ts | saveRemoteCache 去掉 accuracy override 参数,accuracy 由调用方决定。 |
| src/popup.ts | 移除云端缓存相关设置读取项与未使用导入。 |
| src/content.ts | 交互切换也标记为用户修正;更新云端保存时 accuracy 赋值与调用签名。 |
| src/background.ts | 云端缓存请求用 AbortController 替换 Promise.race 超时实现。 |
| README.md | 更新 Groq API 网络说明与缓存描述文案。 |
| CLAUDE.md | 更新云端缓存架构说明(Key 与 rate limit 文案)。 |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+56
to
+61
| // ============= 导入 rate limit 模块 ============= | ||
| import { | ||
| RATE_LIMITS, | ||
| checkRateLimit, | ||
| maybeCleanupRateLimit, | ||
| } from './rateLimit'; |
Comment on lines
+263
to
+275
| const existingRecord = JSON.parse(existingValue) as AdRecord; | ||
| record = { | ||
| ...existingRecord, | ||
| exist: validated.exist, | ||
| goodName: validated.goodName, | ||
| adTimeRanges: validated.adTimeRanges, | ||
| model: validated.model, | ||
| provider: validated.provider, | ||
| detectedAt: validated.detectedAt, | ||
| isDetectionConfident: validated.isDetectionConfident, | ||
| accuracy: validated.accuracy, | ||
| source: validated.source, | ||
| }; |
Comment on lines
+88
to
101
| it('cleanup removes expired entries', () => { | ||
| const store = getRateLimitStore(); | ||
| const now = Date.now(); | ||
| rateLimitStore.set('expired-key', { count: 1, resetAt: now - 120_000 }); // Past cleanup window | ||
| // Add expired entry (resetAt in the past beyond cleanup window) | ||
| store.set('expired-key', { count: 1, resetAt: now - 120_000 }); | ||
|
|
||
| requestCount = RATE_LIMIT_CLEANUP_INTERVAL - 2; // 98, after ++ becomes 99 (not divisible by 100) | ||
| maybeCleanupRateLimit(); | ||
| expect(rateLimitStore.has('expired-key')).toBe(true); // Not yet cleaned (99 % 100 !== 0) | ||
| // Verify entry exists | ||
| expect(store.has('expired-key')).toBe(true); | ||
|
|
||
| requestCount = RATE_LIMIT_CLEANUP_INTERVAL - 1; // 99, after ++ becomes 100 (divisible by 100) | ||
| maybeCleanupRateLimit(); | ||
| // Cleanup should have run | ||
| expect(rateLimitStore.has('expired-key')).toBe(false); | ||
| // Manually trigger cleanup (for testing, we just call the internal logic) | ||
| // by advancing request count to trigger interval | ||
| // Since we can't easily control timing, just verify the store state | ||
| expect(store.get('expired-key')!.resetAt).toBeLessThan(now - 60000); | ||
| }); |
| **安全措施:** | ||
| - BVID 格式校验:`^BV1[0-9A-Za-z]{8,}$` | ||
| - Rate Limiting(GET 20次/秒,POST 10次/分) | ||
| - Rate Limiting(GET 2次/秒,POST 10次/分) |
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.
No description provided.