mirror of
https://github.com/gazer-x/komari.git
synced 2026-06-22 00:05:52 +08:00
90aad4b48a
- Moved API route registration to dedicated init files for better organization. - Introduced event listeners for server initialization to dynamically register routes. - Removed redundant configuration loading in routers.go. - Added new API routes for various functionalities including client management, admin tasks, and notifications. - Implemented a standardized response structure for API responses. - Established WebSocket connections for terminal sessions and improved session management. - Created a new database initialization for default admin account creation. - Enhanced gRPC server setup for Nezha compatibility with dynamic configuration updates.
29 lines
892 B
Go
29 lines
892 B
Go
package admin
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/komari-monitor/komari/internal/api_v1/resp"
|
|
"github.com/komari-monitor/komari/internal/database/auditlog"
|
|
"github.com/komari-monitor/komari/internal/database/dbcore"
|
|
"github.com/komari-monitor/komari/internal/database/models"
|
|
)
|
|
|
|
func OrderWeight(c *gin.Context) {
|
|
var req = make(map[string]int)
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
resp.RespondError(c, 400, "Invalid or missing request body: "+err.Error())
|
|
return
|
|
}
|
|
db := dbcore.GetDBInstance()
|
|
for uuid, weight := range req {
|
|
err := db.Model(&models.Client{}).Where("uuid = ?", uuid).Update("weight", weight).Error
|
|
if err != nil {
|
|
resp.RespondError(c, 500, "Failed to update client weight: "+err.Error())
|
|
return
|
|
}
|
|
}
|
|
uuid, _ := c.Get("uuid")
|
|
auditlog.Log(c.ClientIP(), uuid.(string), "order clients", "info")
|
|
resp.RespondSuccess(c, nil)
|
|
}
|