Skip to content

Commit 82444d9

Browse files
committed
feat: Add R18 artwork permission check in GetArtwork handler
1 parent 635f402 commit 82444d9

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

api/restful/routers/artwork/handlers.go

+5
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ func GetArtwork(ctx *gin.Context) {
8787
})
8888
return
8989
}
90+
if artwork.R18 && !hasKey {
91+
if !checkR18Permission(ctx) {
92+
return
93+
}
94+
}
9095
ctx.JSON(http.StatusOK, ResponseFromArtwork(artwork, hasKey))
9196
}
9297

api/restful/routers/artwork/utils.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,15 @@ import (
1414
"go.mongodb.org/mongo-driver/mongo"
1515
)
1616

17+
// 检查是否能查看 R18 作品 (仅适用于使用了 OptionalJWTMiddleware 的路由)
18+
//
19+
// 在内部做响应处理,如果不能查看则返回 false
1720
func checkR18Permission(ctx *gin.Context) bool {
1821
logged := ctx.GetBool("logged")
1922
if !logged {
2023
ctx.JSON(http.StatusUnauthorized, &ArtworkResponse{
2124
Status: http.StatusUnauthorized,
22-
Message: "You need to login to view R18 artworks",
25+
Message: "You need to login to view this artworks",
2326
})
2427
return false
2528
}
@@ -44,7 +47,7 @@ func checkR18Permission(ctx *gin.Context) bool {
4447
if !user.Settings.R18 {
4548
ctx.JSON(http.StatusBadRequest, &ArtworkResponse{
4649
Status: http.StatusBadRequest,
47-
Message: "Your settings do not allow you to view R18 artworks",
50+
Message: "Your settings do not allow you to view this artworks",
4851
})
4952
return false
5053
}

0 commit comments

Comments
 (0)