82 lines
2.3 KiB
Go
82 lines
2.3 KiB
Go
package router
|
|
|
|
import (
|
|
"encoding/json"
|
|
"io"
|
|
"net/http"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"chatapp3-golang/internal/service/errorlog"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// registerAgoraErrorLogRoutes registers client report and admin page APIs for Agora errors.
|
|
func registerAgoraErrorLogRoutes(engine *gin.Engine, javaClient authGateway, service *errorlog.Service) {
|
|
if service == nil {
|
|
return
|
|
}
|
|
|
|
appGroup := engine.Group("/app/agora")
|
|
appGroup.Use(authMiddleware(javaClient))
|
|
appGroup.POST("/error-log", func(c *gin.Context) {
|
|
raw, err := io.ReadAll(c.Request.Body)
|
|
if err != nil {
|
|
writeError(c, errorlog.NewAppError(http.StatusBadRequest, "bad_request", err.Error()))
|
|
return
|
|
}
|
|
var req errorlog.AgoraErrorReportRequest
|
|
if len(strings.TrimSpace(string(raw))) > 0 {
|
|
if err := json.Unmarshal(raw, &req); err != nil {
|
|
writeError(c, errorlog.NewAppError(http.StatusBadRequest, "bad_request", err.Error()))
|
|
return
|
|
}
|
|
}
|
|
resp, err := service.ReportAgoraError(
|
|
c.Request.Context(),
|
|
mustAuthUser(c),
|
|
req,
|
|
errorlog.AgoraErrorReportContext{
|
|
ReqClient: c.GetHeader("Req-Client"),
|
|
ReqAppIntel: c.GetHeader("Req-App-Intel"),
|
|
ClientIP: resolveClientIP(c),
|
|
UserAgent: c.GetHeader("User-Agent"),
|
|
RawPayload: string(raw),
|
|
},
|
|
)
|
|
if err != nil {
|
|
writeError(c, err)
|
|
return
|
|
}
|
|
writeOK(c, resp)
|
|
})
|
|
|
|
adminGroup := engine.Group("/app-system/error-logs/agora")
|
|
adminGroup.Use(consoleAuthMiddleware(javaClient))
|
|
adminGroup.GET("/page", func(c *gin.Context) {
|
|
cursor, _ := strconv.Atoi(strings.TrimSpace(c.DefaultQuery("cursor", "1")))
|
|
limit, _ := strconv.Atoi(strings.TrimSpace(c.DefaultQuery("limit", "20")))
|
|
bannedOnly, _ := strconv.ParseBool(strings.TrimSpace(c.DefaultQuery("bannedOnly", "false")))
|
|
resp, err := service.PageAgoraErrorLogs(c.Request.Context(), errorlog.AgoraErrorLogQuery{
|
|
SysOrigin: c.Query("sysOrigin"),
|
|
UserID: parseInt64(c.Query("userId")),
|
|
RoomID: c.Query("roomId"),
|
|
AgoraUID: c.Query("agoraUid"),
|
|
ErrorCodeType: c.Query("errorCodeType"),
|
|
ReasonType: c.Query("reasonType"),
|
|
BannedOnly: bannedOnly,
|
|
NetworkType: c.Query("networkType"),
|
|
StartTime: c.Query("startTime"),
|
|
EndTime: c.Query("endTime"),
|
|
Cursor: cursor,
|
|
Limit: limit,
|
|
})
|
|
if err != nil {
|
|
writeError(c, err)
|
|
return
|
|
}
|
|
writeOK(c, resp)
|
|
})
|
|
}
|