fix(miniapp): 幂等键改为按操作稳定;删除指向 404 的互选死代码

1) 幂等键(配合后端机制)

原写法把 Date.now() 拼进幂等键,每次调用都生成新键,即使后端实现了幂等
也永远不会命中 —— 声明端与实现端各自都坏。

api.idempotencyKey(scope, subject):键缓存在 _pendingIdempotency(TTL 10min),
同一逻辑操作在成功之前复用同一把键,收到 200+success 才释放;失败(含网络错误)
不释放,下次重试沿用同一把键。25 处调用点(8 个 service + 2 个 TS 页面)全部替换,
Date.now 幂等键写法残留经 grep 为 0。

2) 删除死代码 submitInterests

它请求 POST /activities/{id}/interests —— 后端从未实现该端点
(Phase 16 已把表达意向合并进 /activities/{id}/feedback 的
interestTargetUserIds)。全仓确认无任何页面/组件调用方。
两个文件各留注释说明删除原因与恢复条件:若产品确认需要独立的
「提交互选」端点,应先定义语义并补后端实现,再恢复前端方法。

store 头部关于 AGENTS 第 6 条(单向意向保密)的注释同步改为引用
submitFeedback 返回的 newMutuals。
This commit is contained in:
WorkBuddy
2026-09-18 16:37:33 +08:00
parent 69cf6a2cc7
commit 8dee67040c
12 changed files with 116 additions and 49 deletions
+7 -7
View File
@@ -26,7 +26,7 @@ const api = require('../utils/api');
* @returns {Promise<import('../types').LikeResult>}
*/
function like(userId) {
const idempotencyKey = `like:${userId}:${Date.now()}`;
const idempotencyKey = api.idempotencyKey('like', userId);
return api.post('/likes', { targetUserId: userId }, undefined, idempotencyKey);
}
@@ -51,7 +51,7 @@ function unlike(userId) {
* @returns {Promise<void>}
*/
function pass(userId) {
const idempotencyKey = `pass:${userId}:${Date.now()}`;
const idempotencyKey = api.idempotencyKey('pass', userId);
return api.post('/passes', { targetUserId: userId }, undefined, idempotencyKey);
}
@@ -65,7 +65,7 @@ function pass(userId) {
* @returns {Promise<void>}
*/
function block(userId, payload = {}) {
const idempotencyKey = `block:${userId}:${Date.now()}`;
const idempotencyKey = api.idempotencyKey('block', userId);
return api.post('/blocks', { targetUserId: userId, reason: payload.reason }, undefined, idempotencyKey);
}
@@ -145,7 +145,7 @@ function getMatches(params = {}) {
* @returns {Promise<void>}
*/
function unmatch(matchId) {
const idempotencyKey = `unmatch:${matchId}:${Date.now()}`;
const idempotencyKey = api.idempotencyKey('unmatch', matchId);
return api.post(`/matches/${encodeURIComponent(matchId)}/unmatch`, {}, undefined, idempotencyKey);
}
@@ -158,7 +158,7 @@ function unmatch(matchId) {
* @returns {Promise<{ requestId: string, initiatedBy: string, status: 'pending' }>}
*/
function requestSuccess(matchId) {
const idempotencyKey = `success-req:${matchId}:${Date.now()}`;
const idempotencyKey = api.idempotencyKey('success-req', matchId);
return api.post(`/matches/${encodeURIComponent(matchId)}/success/request`, {}, undefined, idempotencyKey);
}
@@ -171,7 +171,7 @@ function requestSuccess(matchId) {
* @returns {Promise<{ relationshipStatus: string }>}
*/
function confirmSuccess(matchId) {
const idempotencyKey = `success-confirm:${matchId}:${Date.now()}`;
const idempotencyKey = api.idempotencyKey('success-confirm', matchId);
return api.post(`/matches/${encodeURIComponent(matchId)}/success/confirm`, {}, undefined, idempotencyKey);
}
@@ -182,7 +182,7 @@ function confirmSuccess(matchId) {
* @returns {Promise<void>}
*/
function declineSuccess(matchId) {
const idempotencyKey = `success-decline:${matchId}:${Date.now()}`;
const idempotencyKey = api.idempotencyKey('success-decline', matchId);
return api.post(`/matches/${encodeURIComponent(matchId)}/success/decline`, {}, undefined, idempotencyKey);
}