[优化] POW 系统接口方案

This commit is contained in:
ryan
2026-06-06 12:21:55 +08:00
parent 6bf5023af1
commit 123140b762
4 changed files with 15 additions and 5 deletions
+8 -2
View File
@@ -11,7 +11,10 @@ import (
// GetCapChallenge generates a new CAPTCHA challenge
func GetCapChallenge(c *gin.Context) {
scope := c.Query("scope")
scope := c.Param("scope")
if scope == "" {
scope = c.Query("scope")
}
resp, err := service.CapManager.Generate(scope)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{
@@ -25,7 +28,10 @@ func GetCapChallenge(c *gin.Context) {
// RedeemCapChallenge validates CAPTCHA solutions and yields a one-time redeem token
func RedeemCapChallenge(c *gin.Context) {
scope := c.Query("scope")
scope := c.Param("scope")
if scope == "" {
scope = c.Query("scope")
}
var req cap.RedeemRequest
if !bind.JSON(c, &req) {
+2 -2
View File
@@ -33,8 +33,8 @@ func SetApiRouter(router *gin.Engine) {
capRoute := apiRouter.Group("/cap")
{
capRoute.POST("/challenge", middleware.CriticalRateLimit(), controller.GetCapChallenge)
capRoute.POST("/redeem", middleware.CriticalRateLimit(), controller.RedeemCapChallenge)
capRoute.POST("/:scope/challenge", middleware.CriticalRateLimit(), controller.GetCapChallenge)
capRoute.POST("/:scope/redeem", middleware.CriticalRateLimit(), controller.RedeemCapChallenge)
}
userRoute := apiRouter.Group("/user")
@@ -160,7 +160,7 @@ export function LoginForm() {
<div className="flex justify-center py-2">
<cap-widget
ref={capWidgetRef}
data-cap-api-endpoint="/api/cap/"
data-cap-api-endpoint="/api/cap/login/"
onsolve={(e: CustomEvent<{ token: string }>) => {
setCapToken(e.detail.token);
}}