Commit 82444d9 1 parent 635f402 commit 82444d9 Copy full SHA for 82444d9
File tree 2 files changed +10
-2
lines changed
api/restful/routers/artwork
2 files changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -87,6 +87,11 @@ func GetArtwork(ctx *gin.Context) {
87
87
})
88
88
return
89
89
}
90
+ if artwork .R18 && ! hasKey {
91
+ if ! checkR18Permission (ctx ) {
92
+ return
93
+ }
94
+ }
90
95
ctx .JSON (http .StatusOK , ResponseFromArtwork (artwork , hasKey ))
91
96
}
92
97
Original file line number Diff line number Diff line change @@ -14,12 +14,15 @@ import (
14
14
"go.mongodb.org/mongo-driver/mongo"
15
15
)
16
16
17
+ // 检查是否能查看 R18 作品 (仅适用于使用了 OptionalJWTMiddleware 的路由)
18
+ //
19
+ // 在内部做响应处理,如果不能查看则返回 false
17
20
func checkR18Permission (ctx * gin.Context ) bool {
18
21
logged := ctx .GetBool ("logged" )
19
22
if ! logged {
20
23
ctx .JSON (http .StatusUnauthorized , & ArtworkResponse {
21
24
Status : http .StatusUnauthorized ,
22
- Message : "You need to login to view R18 artworks" ,
25
+ Message : "You need to login to view this artworks" ,
23
26
})
24
27
return false
25
28
}
@@ -44,7 +47,7 @@ func checkR18Permission(ctx *gin.Context) bool {
44
47
if ! user .Settings .R18 {
45
48
ctx .JSON (http .StatusBadRequest , & ArtworkResponse {
46
49
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" ,
48
51
})
49
52
return false
50
53
}
You can’t perform that action at this time.
0 commit comments