mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-11 01:36:37 +08:00
fix(cap): keep only /api/v1/cap routes
Drop the unversioned /api/cap aliases so Challenge and Redeem exist only under /api/v1/cap.
This commit is contained in:
@@ -20,7 +20,8 @@ import (
|
|||||||
// @Param request body challengeRequest false "可选范围限制参数"
|
// @Param request body challengeRequest false "可选范围限制参数"
|
||||||
// @Success 200 {object} response.Any{data=cap.ChallengeResponse} "成功返回 PoW 难题"
|
// @Success 200 {object} response.Any{data=cap.ChallengeResponse} "成功返回 PoW 难题"
|
||||||
// @Failure 500 {object} response.Any "内部服务错误"
|
// @Failure 500 {object} response.Any "内部服务错误"
|
||||||
// @Router /api/cap/challenge [post]
|
// @Router /api/v1/cap/challenge [get]
|
||||||
|
// @Router /api/v1/cap/challenge [post]
|
||||||
func Challenge(c *gin.Context) {
|
func Challenge(c *gin.Context) {
|
||||||
var req challengeRequest
|
var req challengeRequest
|
||||||
_ = c.ShouldBind(&req) // 允许不传 body,默认使用 login scope
|
_ = c.ShouldBind(&req) // 允许不传 body,默认使用 login scope
|
||||||
@@ -54,7 +55,7 @@ func Challenge(c *gin.Context) {
|
|||||||
// @Success 200 {object} response.Any{data=cap.RedeemResponse} "核销成功,返回 X-Cap-Token"
|
// @Success 200 {object} response.Any{data=cap.RedeemResponse} "核销成功,返回 X-Cap-Token"
|
||||||
// @Failure 400 {object} response.Any "参数错误或核销失败"
|
// @Failure 400 {object} response.Any "参数错误或核销失败"
|
||||||
// @Failure 500 {object} response.Any "内部服务错误"
|
// @Failure 500 {object} response.Any "内部服务错误"
|
||||||
// @Router /api/cap/redeem [post]
|
// @Router /api/v1/cap/redeem [post]
|
||||||
func Redeem(c *gin.Context) {
|
func Redeem(c *gin.Context) {
|
||||||
var req redeemRequest
|
var req redeemRequest
|
||||||
if err := c.ShouldBindJSON(&req); err != nil {
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
|
|||||||
@@ -86,11 +86,7 @@ func (p *Plugin) Apply(ctx *core.Context) error {
|
|||||||
capGroup.POST("/challenge", Challenge)
|
capGroup.POST("/challenge", Challenge)
|
||||||
capGroup.POST("/redeem", Redeem)
|
capGroup.POST("/redeem", Redeem)
|
||||||
}
|
}
|
||||||
|
ctx.Router().RegisterWhitelist("/api/v1/cap/challenge", "/api/v1/cap/redeem")
|
||||||
legacy := ctx.Router().Group("/api/cap")
|
|
||||||
legacy.POST("/challenge", Challenge)
|
|
||||||
legacy.POST("/redeem", Redeem)
|
|
||||||
ctx.Router().RegisterWhitelist("/api/cap/challenge", "/api/cap/redeem")
|
|
||||||
|
|
||||||
// Register Settings Schemas
|
// Register Settings Schemas
|
||||||
ctx.Settings().Register(extpoints.SettingSchema{
|
ctx.Settings().Register(extpoints.SettingSchema{
|
||||||
|
|||||||
@@ -34,15 +34,18 @@ func TestApplyRegistersUnversionedCapRoutes(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
want := map[string]bool{
|
want := map[string]bool{
|
||||||
|
"GET /api/v1/cap/challenge": false,
|
||||||
"POST /api/v1/cap/challenge": false,
|
"POST /api/v1/cap/challenge": false,
|
||||||
"POST /api/cap/challenge": false,
|
"POST /api/v1/cap/redeem": false,
|
||||||
"POST /api/cap/redeem": false,
|
|
||||||
}
|
}
|
||||||
for _, rd := range ctx.Router().Routes() {
|
for _, rd := range ctx.Router().Routes() {
|
||||||
key := rd.Method + " " + rd.Path
|
key := rd.Method + " " + rd.Path
|
||||||
if _, ok := want[key]; ok {
|
if _, ok := want[key]; ok {
|
||||||
want[key] = true
|
want[key] = true
|
||||||
}
|
}
|
||||||
|
if key == "POST /api/cap/challenge" || key == "POST /api/cap/redeem" {
|
||||||
|
t.Errorf("legacy route must not exist: %s", key)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for key, ok := range want {
|
for key, ok := range want {
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|||||||
Reference in New Issue
Block a user