增强关键接口幂等与限流保护
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { Router } from "express";
|
||||
|
||||
import { createRateLimitMiddleware, getParamRateLimitKey } from "../middleware/rate-limit.js";
|
||||
import {
|
||||
confirmKuaishouCloudClaimRole,
|
||||
getKuaishouCloudClaimDetail,
|
||||
@@ -14,9 +15,22 @@ import {
|
||||
} from "../utils/http.js";
|
||||
|
||||
const router = Router();
|
||||
const claimReadRateLimit = createRateLimitMiddleware({
|
||||
scope: "claim:read",
|
||||
windowMs: 60_000,
|
||||
max: 120,
|
||||
key: getParamRateLimitKey("token"),
|
||||
});
|
||||
const claimWriteRateLimit = createRateLimitMiddleware({
|
||||
scope: "claim:write",
|
||||
windowMs: 60_000,
|
||||
max: 30,
|
||||
key: getParamRateLimitKey("token"),
|
||||
});
|
||||
|
||||
router.get(
|
||||
"/:token",
|
||||
claimReadRateLimit,
|
||||
createRouteHandler((req) => getKuaishouCloudClaimDetail(req.params.token), {
|
||||
errorMessage: "查询快手领取详情失败",
|
||||
scope: "[claims/:token]",
|
||||
@@ -25,6 +39,7 @@ router.get(
|
||||
|
||||
router.post(
|
||||
"/:token/kuaishou-cloud/verify-ticket",
|
||||
claimWriteRateLimit,
|
||||
createRouteHandler(
|
||||
(req) => verifyKuaishouCloudClaimTicket(req.params.token, req.body),
|
||||
{
|
||||
@@ -37,6 +52,7 @@ router.post(
|
||||
|
||||
router.post(
|
||||
"/:token/kuaishou-cloud/confirm-role",
|
||||
claimWriteRateLimit,
|
||||
createRouteHandler((req) => confirmKuaishouCloudClaimRole(req.params.token), {
|
||||
successMessage: "角色已确认",
|
||||
errorMessage: "确认角色失败",
|
||||
@@ -46,6 +62,7 @@ router.post(
|
||||
|
||||
router.post(
|
||||
"/:token/kuaishou-cloud/redeem",
|
||||
claimWriteRateLimit,
|
||||
createRouteHandler((req) => redeemKuaishouCloudClaim(req.params.token), {
|
||||
successMessage: "兑换请求已提交",
|
||||
errorMessage: "兑换失败",
|
||||
|
||||
Reference in New Issue
Block a user