This commit is contained in:
tamakyi
2026-10-19 01:58:00 +08:00
parent bd613a6f5a
commit 4592b6ef24
14 changed files with 608 additions and 244 deletions
+14
View File
@@ -281,6 +281,20 @@ func ListAPI(ctx context.Context) error {
return ctx.ServerError()
}
// ⚠️ 这个接口不经过 question.Pager 中间件,必须自己补两道检查:
// 1) L4 整页停用:否则「停用」只挡 HTML 页面,API 仍能整页拉取内容;
// 2) 页面访问密码:Pager 用 session 标记校验,API 不校验就等于密码形同虚设。
// 两者都返回「用户不存在」以隐藏真实原因(不暴露处置状态与密码设置)。
if level, _, err := db.Restrictions.ActiveLevel(ctx.Request().Context(), pageUser.ID); err == nil && level == db.RestrictionL4 {
return ctx.JSONError(40400, i18n.T(ctx.Lang(), "auth.errUserNotFound"))
}
if pageUser.PagePassword != "" && !(ctx.IsLogged && ctx.User.ID == pageUser.ID) {
passKey := fmt.Sprintf("page_pass_%d", pageUser.ID)
if authorized, _ := ctx.Session.Get(passKey).(bool); !authorized {
return ctx.JSONError(40100, i18n.T(ctx.Lang(), "password.desc"))
}
}
pageQuestions, err := db.Questions.GetByUserID(ctx.Request().Context(), pageUser.ID, db.GetQuestionsByUserIDOptions{
Cursor: &dbutil.Cursor{
Value: cursorValue,