@@ -16,42 +16,42 @@ import (
1616// 检查是否能查看 R18 作品 (仅适用于使用了 OptionalJWTMiddleware 的路由)
1717//
1818// 在内部做响应处理,如果不能查看则返回 false
19- func checkR18Permission (ctx * gin.Context ) bool {
20- logged := ctx .GetBool ("logged" )
21- if ! logged {
22- ctx .JSON (http .StatusUnauthorized , common.RestfulCommonResponse [any ]{
23- Status : http .StatusUnauthorized ,
24- Message : "You must log in to view R18 content" ,
25- })
26- return false
27- }
28- claims := ctx .MustGet ("claims" ).(jwt.MapClaims )
29- username := claims ["id" ].(string )
30- user , err := service .GetUserByUsername (ctx , username )
31- if err != nil {
32- if errors .Is (err , mongo .ErrNoDocuments ) {
33- ctx .JSON (http .StatusForbidden , common.RestfulCommonResponse [any ]{
34- Status : http .StatusForbidden ,
35- Message : "Account not found" ,
36- })
37- return false
38- }
39- common .Logger .Errorf ("Failed to get user: %v" , err )
40- ctx .JSON (http .StatusInternalServerError , common.RestfulCommonResponse [any ]{
41- Status : http .StatusInternalServerError ,
42- Message : "Failed to get user" ,
43- })
44- return false
45- }
46- if ! user .Settings .R18 {
47- ctx .JSON (http .StatusForbidden , common.RestfulCommonResponse [any ]{
48- Status : http .StatusForbidden ,
49- Message : "Your settings do not allow you to view R18 content" ,
50- })
51- return false
52- }
53- return true
54- }
19+ // func checkR18Permission(ctx *gin.Context) bool {
20+ // logged := ctx.GetBool("logged")
21+ // if !logged {
22+ // ctx.JSON(http.StatusUnauthorized, common.RestfulCommonResponse[any]{
23+ // Status: http.StatusUnauthorized,
24+ // Message: "You must log in to view R18 content",
25+ // })
26+ // return false
27+ // }
28+ // claims := ctx.MustGet("claims").(jwt.MapClaims)
29+ // username := claims["id"].(string)
30+ // user, err := service.GetUserByUsername(ctx, username)
31+ // if err != nil {
32+ // if errors.Is(err, mongo.ErrNoDocuments) {
33+ // ctx.JSON(http.StatusForbidden, common.RestfulCommonResponse[any]{
34+ // Status: http.StatusForbidden,
35+ // Message: "Account not found",
36+ // })
37+ // return false
38+ // }
39+ // common.Logger.Errorf("Failed to get user: %v", err)
40+ // ctx.JSON(http.StatusInternalServerError, common.RestfulCommonResponse[any]{
41+ // Status: http.StatusInternalServerError,
42+ // Message: "Failed to get user",
43+ // })
44+ // return false
45+ // }
46+ // if !user.Settings.R18 {
47+ // ctx.JSON(http.StatusForbidden, common.RestfulCommonResponse[any]{
48+ // Status: http.StatusForbidden,
49+ // Message: "Your settings do not allow you to view R18 content",
50+ // })
51+ // return false
52+ // }
53+ // return true
54+ // }
5555
5656func validateArtworkIDMiddleware (ctx * gin.Context ) {
5757 var request ArtworkIDRequest
0 commit comments