mirror of
https://github.com/nezhahq/nezha.git
synced 2025-02-13 06:28:14 -05:00
feat: batch set server config
This commit is contained in:
parent
a5ecdbf612
commit
e9f8847708
@ -273,40 +273,38 @@ func getServerConfig(c *gin.Context) (string, error) {
|
||||
// @Description Set server config
|
||||
// @Tags auth required
|
||||
// @Accept json
|
||||
// @param request body string true "config"
|
||||
// @Param body body model.ServerConfigForm true "ServerConfigForm"
|
||||
// @Produce json
|
||||
// @Success 200 {object} model.CommonResponse[any]
|
||||
// @Router /server/{id}/config [post]
|
||||
// @Router /server/config [post]
|
||||
func setServerConfig(c *gin.Context) (any, error) {
|
||||
idStr := c.Param("id")
|
||||
id, err := strconv.ParseUint(idStr, 10, 64)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
var configRaw string
|
||||
if err := c.ShouldBindJSON(&configRaw); err != nil {
|
||||
var configForm model.ServerConfigForm
|
||||
if err := c.ShouldBindJSON(&configForm); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
singleton.ServerLock.RLock()
|
||||
s, ok := singleton.ServerList[id]
|
||||
for _, sid := range configForm.Servers {
|
||||
s, ok := singleton.ServerList[sid]
|
||||
if !ok || s.TaskStream == nil {
|
||||
singleton.ServerLock.RUnlock()
|
||||
return "", nil
|
||||
}
|
||||
singleton.ServerLock.RUnlock()
|
||||
|
||||
if !s.HasPermission(c) {
|
||||
singleton.ServerLock.RUnlock()
|
||||
return "", singleton.Localizer.ErrorT("permission denied")
|
||||
}
|
||||
|
||||
if err := s.TaskStream.Send(&pb.Task{
|
||||
Type: model.TaskTypeApplyConfig,
|
||||
Data: configRaw,
|
||||
Data: configForm.Config,
|
||||
}); err != nil {
|
||||
singleton.ServerLock.RUnlock()
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
|
||||
singleton.ServerLock.RUnlock()
|
||||
return nil, nil
|
||||
}
|
||||
|
@ -31,6 +31,11 @@ type ServerForm struct {
|
||||
OverrideDDNSDomains map[uint64][]string `json:"override_ddns_domains,omitempty" validate:"optional"`
|
||||
}
|
||||
|
||||
type ServerConfigForm struct {
|
||||
Servers []uint64 `json:"servers,omitempty"`
|
||||
Config string `json:"config,omitempty"`
|
||||
}
|
||||
|
||||
type ForceUpdateResponse struct {
|
||||
Success []uint64 `json:"success,omitempty" validate:"optional"`
|
||||
Failure []uint64 `json:"failure,omitempty" validate:"optional"`
|
||||
|
Loading…
Reference in New Issue
Block a user