新增模块: - 友链(friendlink)后端处理 + 前端管理页与友链板 - 书库(library):导入、章节、封面、阅读页、横竖版自适应 AdaptiveCoverSlot - 顶栏导航(header_nav)配置与 MobileTabBar/MobileRailDrawers 移动端抽屉 - 排行榜 service 测试、站点页面测试、时间线发布(timeline_release) 其它改动: - 后端 handlers/services 全量小幅调整 - 前端组件、库函数、URL/品牌/站点 URL 工具更新 - Lightbox 图片、MdEntries 条目卡、coverColor 派生色相等前端能力
107 lines
3.4 KiB
Go
107 lines
3.4 KiB
Go
package handler
|
||
|
||
import (
|
||
"github.com/freefire/jiang13-bbs/config"
|
||
"github.com/freefire/jiang13-bbs/model"
|
||
"github.com/freefire/jiang13-bbs/realtime"
|
||
"github.com/freefire/jiang13-bbs/service"
|
||
"github.com/gin-gonic/gin"
|
||
)
|
||
|
||
// Handlers 聚合所有服务引用
|
||
type Handlers struct {
|
||
Ops *service.Operations
|
||
Cfg *config.Config
|
||
Hub *realtime.Hub
|
||
Auth *service.AuthService
|
||
Board *service.BoardService
|
||
Post *service.PostService
|
||
Comment *service.CommentService
|
||
Like *service.LikeService
|
||
Favorite *service.FavoriteService
|
||
Follow *service.FollowService
|
||
Notification *service.NotificationService
|
||
OverviewSvc *service.OverviewService
|
||
Checkin *service.CheckinService
|
||
Announcement *service.AnnouncementService
|
||
SitePage *service.SitePageService
|
||
Upload *service.UploadService
|
||
PostFile *service.PostFileService
|
||
Points *service.PointsService
|
||
Setting *service.SettingService
|
||
AdminUser *service.AdminUserService
|
||
LegacyImport *service.LegacyImportService
|
||
Moderation *service.ModerationService
|
||
Chat *service.ChatService
|
||
Visit *service.VisitStatsService
|
||
Analytics *service.AnalyticsService
|
||
HidePwd *service.HidePasswordCookie
|
||
Ads *service.AdService
|
||
Sidebar *service.SidebarService
|
||
FriendLink *service.FriendLinkService
|
||
Badge *service.BadgeService
|
||
LeaderboardSvc *service.LeaderboardService
|
||
LibrarySvc *service.LibraryService
|
||
}
|
||
|
||
// resolvePublishStatus 决定新帖/新评的初始状态:
|
||
// staff 直发;全站免审开启时所有人直发;否则若开启「已过审免审」且用户已有 published 内容则直发;否则进 pending。
|
||
func (h *Handlers) resolvePublishStatus(userID uint, role string) string {
|
||
if model.IsStaff(model.Role(role)) {
|
||
return model.ContentStatusPublished
|
||
}
|
||
if withoutReview, err := h.Setting.PublishWithoutReview(); err == nil && withoutReview {
|
||
return model.ContentStatusPublished
|
||
}
|
||
trust, err := h.Setting.TrustReviewedPublish()
|
||
if err != nil || !trust {
|
||
return model.ContentStatusPending
|
||
}
|
||
ok, err := h.Moderation.UserHasApprovedContent(userID)
|
||
if err != nil || !ok {
|
||
return model.ContentStatusPending
|
||
}
|
||
return model.ContentStatusPublished
|
||
}
|
||
|
||
// broadcastFeedChanged 帖子流有公开发布内容时全员广播(三期)
|
||
func (h *Handlers) broadcastFeedChanged(kind string, postID, boardID, actorID uint) {
|
||
if h.Hub == nil {
|
||
return
|
||
}
|
||
h.Hub.BroadcastAll(realtime.Envelope{
|
||
Type: realtime.EventFeedChanged,
|
||
Data: gin.H{
|
||
"kind": kind,
|
||
"post_id": postID,
|
||
"board_id": boardID,
|
||
"actor_id": actorID,
|
||
},
|
||
})
|
||
}
|
||
|
||
// notifyPendingReview 待审内容通知该板可审者(WS 红点由 Notification.OnNotifyNew 统一推送)
|
||
func (h *Handlers) notifyPendingReview(boardID, actorID, postID, commentID uint, preview string) {
|
||
ids, err := h.Auth.ListBoardModeratorIDs(boardID)
|
||
if err != nil || len(ids) == 0 {
|
||
return
|
||
}
|
||
for _, uid := range ids {
|
||
if uid == actorID {
|
||
continue
|
||
}
|
||
h.Notification.Create(uid, actorID, model.NotificationTypePendingReview, postID, commentID, preview)
|
||
}
|
||
h.broadcastModerationChanged()
|
||
}
|
||
|
||
// broadcastModerationChanged 通知管理团队待审队列有变化(角标由客户端按权限再拉一次)
|
||
func (h *Handlers) broadcastModerationChanged() {
|
||
if h.Hub == nil {
|
||
return
|
||
}
|
||
h.Hub.BroadcastRoom(realtime.RoomStaff, realtime.Envelope{
|
||
Type: realtime.EventModerationChanged,
|
||
})
|
||
}
|