fix: preset logging

This commit is contained in:
2026-03-26 22:32:24 +01:00
parent 180555c903
commit f23f276ee5
3 changed files with 27 additions and 2 deletions

View File

@@ -15,6 +15,8 @@ const (
ActionServerStop ActionType = "server_stop"
ActionServerRestart ActionType = "server_restart"
ActionLeaderboardUpdate ActionType = "leaderboard_update"
ActionPresetCreate ActionType = "preset_create"
ActionPresetApply ActionType = "preset_apply"
)
type ActivityLog struct {

View File

@@ -564,7 +564,7 @@ func (as *ConfigService) SaveConfiguration(server *model.Server, config *model.C
// ApplySection writes a single config section to the server's config file and
// records the change. It is used by ConfigPresetService to apply preset sections.
func (as *ConfigService) ApplySection(ctx context.Context, serverID, configFile string, body *map[string]interface{}, actorID, actorUsername string) (*model.Config, error) {
return as.updateConfigInternal(ctx, serverID, configFile, body, false, actorID, actorUsername)
return as.updateConfigInternal(ctx, serverID, configFile, body, true, actorID, actorUsername)
}
func (as *ConfigService) SetServerName(server *model.Server, name string) error {

View File

@@ -3,6 +3,7 @@ package service
import (
"acc-server-manager/local/model"
"acc-server-manager/local/repository"
"acc-server-manager/local/utl/logging"
"context"
"encoding/json"
"fmt"
@@ -19,12 +20,14 @@ const (
type ConfigPresetService struct {
repository *repository.ConfigPresetRepository
configService *ConfigService
activityLog *ActivityLogService
}
func NewConfigPresetService(repo *repository.ConfigPresetRepository, configService *ConfigService) *ConfigPresetService {
func NewConfigPresetService(repo *repository.ConfigPresetRepository, configService *ConfigService, activityLog *ActivityLogService) *ConfigPresetService {
return &ConfigPresetService{
repository: repo,
configService: configService,
activityLog: activityLog,
}
}
@@ -66,6 +69,8 @@ func (s *ConfigPresetService) CreatePreset(ctx context.Context, req *model.Confi
if err := s.repository.Insert(ctx, preset); err != nil {
return nil, err
}
logging.Info("Preset created: id=%s name=%q", preset.ID, preset.Name)
return preset, nil
}
@@ -110,6 +115,11 @@ func (s *ConfigPresetService) ApplyPreset(ctx context.Context, serverID string,
return nil, err
}
serverUUID, err := uuid.Parse(serverID)
if err != nil {
return nil, fmt.Errorf("invalid server ID: %v", err)
}
type sectionEntry struct {
fileName string
raw string
@@ -141,6 +151,19 @@ func (s *ConfigPresetService) ApplyPreset(ctx context.Context, serverID string,
}
}
details := fmt.Sprintf(`{"preset_id":%q,"preset_name":%q,"sections_applied":%d}`, presetID, preset.Name, len(results))
go func() {
if logErr := s.activityLog.Log(context.Background(), &model.ActivityLog{
ServerID: serverUUID,
UserID: actorID,
Username: actorUsername,
Action: model.ActionPresetApply,
Details: details,
}); logErr != nil {
logging.Error("Failed to log preset apply: %v", logErr)
}
}()
return results, nil
}