API功能性修复
All checks were successful
build / build (api, amd64, linux) (push) Successful in -43s
build / build (api, arm64, linux) (push) Successful in -44s
build / build (api.exe, amd64, windows) (push) Successful in -43s

This commit is contained in:
CN-JS-HuiBai
2026-04-17 15:13:43 +08:00
parent 981ee4f406
commit 25fd919477
359 changed files with 499761 additions and 844 deletions

View File

@@ -4,6 +4,7 @@ package main
import (
"log"
"strings"
"xboard-go/internal/config"
"xboard-go/internal/database"
"xboard-go/internal/handler"
@@ -69,6 +70,14 @@ func main() {
// V2 Admin API Group (Matches Xboard official frontend expectations)
v2 := r.Group("/api/v2")
{
// V2 User Auth Routes (used by the admin React app to verify login state)
v2user := v2.Group("/user")
v2user.Use(middleware.Auth())
{
v2user.GET("/info", handler.UserInfo)
v2user.GET("/checkLogin", handler.UserCheckLogin)
}
// All admin endpoints are prefixed with the secure path
admin := v2.Group("/:path")
admin.Use(middleware.AdminAuth())
@@ -85,32 +94,51 @@ func main() {
// Dashboard / Stat
statGrp := admin.Group("/stat")
{
statGrp.GET("/getStats", handler.AdminDashboardSummary)
statGrp.GET("/getOverride", handler.AdminDashboardSummary)
statGrp.GET("/getStats", handler.AdminDashboardSummary) // Fallback
statGrp.GET("/getTrafficRank", handler.AdminGetTrafficRank)
statGrp.GET("/getOrder", handler.AdminGetOrderStats)
statGrp.POST("/getStatUser", handler.AdminGetStatUser)
}
// System
systemGrp := admin.Group("/system")
{
systemGrp.GET("/getSystemStatus", handler.AdminSystemStatus)
systemGrp.GET("/getQueueStats", handler.AdminSystemQueueStats)
systemGrp.GET("/getQueueWorkload", handler.AdminSystemQueueStats)
systemGrp.GET("/getQueueMasters", handler.AdminSystemQueueStats)
systemGrp.GET("/getHorizonFailedJobs", handler.AdminSystemQueueStats)
}
// Essential Resources
admin.POST("/plan/fetch", handler.AdminPlansFetch) // Shifted to POST in manifest? Actually manifest says GET next to plan, let's keep GET and add POST if needed.
admin.GET("/plan/fetch", handler.AdminPlansFetch)
admin.POST("/plan/save", handler.AdminPlanSave)
admin.POST("/plan/update", handler.AdminPlanSave)
admin.POST("/plan/drop", handler.AdminPlanDrop)
admin.POST("/plan/sort", handler.AdminPlanSort)
admin.GET("/user/fetch", handler.AdminUsersFetch)
admin.POST("/user/fetch", handler.AdminUsersFetch)
admin.POST("/user/update", handler.AdminUserUpdate)
admin.POST("/user/ban", handler.AdminUserBan)
admin.POST("/user/delete", handler.AdminUserDelete)
admin.POST("/user/destroy", handler.AdminUserDelete)
admin.POST("/user/resetSecret", handler.AdminUserResetSecret)
admin.POST("/user/sendMail", handler.AdminUserSendMail)
admin.GET("/order/fetch", handler.AdminOrdersFetch)
admin.POST("/order/fetch", handler.AdminOrdersFetch)
admin.POST("/order/detail", handler.AdminOrderDetail)
admin.POST("/order/paid", handler.AdminOrderPaid)
admin.POST("/order/cancel", handler.AdminOrderCancel)
admin.POST("/order/assign", handler.AdminOrderAssign)
admin.POST("/order/update", handler.AdminOrderUpdate)
admin.GET("/coupon/fetch", handler.AdminCouponsFetch)
admin.POST("/coupon/fetch", handler.AdminCouponsFetch)
admin.POST("/coupon/save", handler.AdminCouponSave)
admin.POST("/coupon/drop", handler.AdminCouponDrop)
admin.GET("/ticket/fetch", handler.AdminTicketsFetch)
admin.POST("/ticket/fetch", handler.AdminTicketsFetch)
// Knowledge Base
knowledgeGrp := admin.Group("/knowledge")
@@ -135,6 +163,16 @@ func main() {
trafficResetGrp.GET("/fetch", handler.AdminTrafficResetFetch)
}
// Real-name Verification
realNameGrp := admin.Group("/realname")
{
realNameGrp.GET("/fetch", handler.PluginRealNameList)
realNameGrp.POST("/review/:userId", handler.PluginRealNameReview)
realNameGrp.POST("/reset/:userId", handler.PluginRealNameReset)
realNameGrp.POST("/sync", handler.PluginRealNameSyncAll)
realNameGrp.POST("/approve-all", handler.PluginRealNameApproveAll)
}
// Servers / Nodes
admin.GET("/server/group/fetch", handler.AdminServerGroupsFetch)
admin.POST("/server/group/save", handler.AdminServerGroupSave)
@@ -142,16 +180,42 @@ func main() {
admin.GET("/server/manage/getNodes", handler.AdminServerManageGetNodes)
admin.POST("/server/manage/save", handler.AdminServerManageSave)
admin.POST("/server/manage/update", handler.AdminServerManageSave)
admin.POST("/server/manage/drop", handler.AdminServerManageDrop)
admin.POST("/server/manage/sort", handler.AdminServerManageSort)
admin.POST("/server/manage/copy", handler.AdminServerManageCopy)
// Router / Route
admin.GET("/server/route/fetch", handler.AdminServerRoutesFetch)
admin.POST("/server/route/save", handler.AdminServerRouteSave)
admin.POST("/server/route/drop", handler.AdminServerRouteDrop)
// Payment
admin.GET("/payment/fetch", handler.AdminPaymentFetch)
admin.POST("/payment/save", handler.AdminPaymentSave)
admin.POST("/payment/drop", handler.AdminPaymentDrop)
admin.POST("/payment/show", handler.AdminPaymentShow)
admin.POST("/payment/sort", handler.AdminPaymentSort)
admin.GET("/payment/getPaymentMethods", handler.AdminGetPaymentMethods)
// Notice
admin.GET("/notice/fetch", handler.AdminNoticeFetch)
admin.POST("/notice/save", handler.AdminNoticeSave)
admin.POST("/notice/drop", handler.AdminNoticeDrop)
admin.POST("/notice/show", handler.AdminNoticeShow)
admin.POST("/notice/sort", handler.AdminNoticeSort)
}
}
// SPA Fallback for Admin
// SPA Fallback for Admin - only for non-API paths
r.NoRoute(func(c *gin.Context) {
// If path starts with secure admin path, serve the admin app
// This allows React Router to handle sub-paths like /admin/nodes
path := c.Request.URL.Path
// Don't serve SPA for API calls - let them return 404
if strings.HasPrefix(path, "/api/") {
c.JSON(404, gin.H{"message": "not found"})
return
}
handler.AdminAppPage(c)
})

View File

@@ -189,6 +189,18 @@ func registerAdminRoutesV2(v2 *gin.RouterGroup) {
admin.GET("/config/fetch", handler.AdminConfigFetch)
admin.POST("/config/save", handler.AdminConfigSave)
admin.GET("/dashboard/summary", handler.AdminDashboardSummary)
admin.GET("/stat/getStats", handler.AdminDashboardSummary)
admin.GET("/stat/getOverride", handler.AdminDashboardSummary)
admin.GET("/stat/getTrafficRank", handler.AdminGetTrafficRank)
admin.GET("/stat/getOrder", handler.AdminGetOrderStats)
admin.GET("/system/getSystemStatus", handler.AdminSystemStatus)
admin.GET("/system/getQueueStats", handler.AdminSystemQueueStats)
admin.GET("/system/getQueueWorkload", handler.AdminSystemQueueStats)
admin.GET("/system/getQueueMasters", handler.AdminSystemQueueStats)
admin.GET("/system/getHorizonFailedJobs", handler.AdminSystemQueueStats)
admin.GET("/server/group/fetch", handler.AdminServerGroupsFetch)
admin.POST("/server/group/save", handler.AdminServerGroupSave)
admin.POST("/server/group/drop", handler.AdminServerGroupDrop)
@@ -204,7 +216,6 @@ func registerAdminRoutesV2(v2 *gin.RouterGroup) {
admin.POST("/server/manage/batchDelete", handler.AdminServerManageBatchDelete)
admin.POST("/server/manage/resetTraffic", handler.AdminServerManageResetTraffic)
admin.POST("/server/manage/batchResetTraffic", handler.AdminServerManageBatchResetTraffic)
admin.GET("/system/getSystemStatus", handler.AdminSystemStatus)
admin.GET("/plan/fetch", handler.AdminPlansFetch)
admin.POST("/plan/save", handler.AdminPlanSave)
admin.POST("/plan/drop", handler.AdminPlanDrop)
@@ -225,6 +236,10 @@ func registerAdminRoutesV2(v2 *gin.RouterGroup) {
admin.POST("/user/drop", handler.AdminUserDelete)
admin.GET("/ticket/fetch", handler.AdminTicketsFetch)
admin.GET("/gift-card/status", handler.AdminGiftCardStatus)
admin.GET("/traffic-reset/fetch", handler.AdminTrafficResetFetch)
admin.GET("/traffic-reset/logs", handler.AdminTrafficResetFetch)
admin.POST("/traffic-reset/reset-user", handler.AdminTrafficResetUser)
admin.GET("/traffic-reset/user/:id/history", handler.AdminTrafficResetUserHistory)
// Integrated Admin Features
admin.GET("/realname/records", handler.PluginRealNameRecords)