Use sockets for server creation progress
This commit is contained in:
@@ -104,6 +104,12 @@ func (f *ServerFilter) ApplyFilter(query *gorm.DB) *gorm.DB {
|
||||
return query
|
||||
}
|
||||
|
||||
func (s *Server) GenerateUUID() {
|
||||
if s.ID == uuid.Nil {
|
||||
s.ID = uuid.New()
|
||||
}
|
||||
}
|
||||
|
||||
// BeforeCreate is a GORM hook that runs before creating a new server
|
||||
func (s *Server) BeforeCreate(tx *gorm.DB) error {
|
||||
if s.Name == "" {
|
||||
@@ -111,9 +117,7 @@ func (s *Server) BeforeCreate(tx *gorm.DB) error {
|
||||
}
|
||||
|
||||
// Generate UUID if not set
|
||||
if s.ID == uuid.Nil {
|
||||
s.ID = uuid.New()
|
||||
}
|
||||
s.GenerateUUID()
|
||||
|
||||
// Generate service name and config path if not set
|
||||
if s.ServiceName == "" {
|
||||
|
||||
89
local/model/websocket.go
Normal file
89
local/model/websocket.go
Normal file
@@ -0,0 +1,89 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// ServerCreationStep represents the steps in server creation process
|
||||
type ServerCreationStep string
|
||||
|
||||
const (
|
||||
StepValidation ServerCreationStep = "validation"
|
||||
StepDirectoryCreation ServerCreationStep = "directory_creation"
|
||||
StepSteamDownload ServerCreationStep = "steam_download"
|
||||
StepConfigGeneration ServerCreationStep = "config_generation"
|
||||
StepServiceCreation ServerCreationStep = "service_creation"
|
||||
StepFirewallRules ServerCreationStep = "firewall_rules"
|
||||
StepDatabaseSave ServerCreationStep = "database_save"
|
||||
StepCompleted ServerCreationStep = "completed"
|
||||
)
|
||||
|
||||
// StepStatus represents the status of a step
|
||||
type StepStatus string
|
||||
|
||||
const (
|
||||
StatusPending StepStatus = "pending"
|
||||
StatusInProgress StepStatus = "in_progress"
|
||||
StatusCompleted StepStatus = "completed"
|
||||
StatusFailed StepStatus = "failed"
|
||||
)
|
||||
|
||||
// WebSocketMessageType represents different types of WebSocket messages
|
||||
type WebSocketMessageType string
|
||||
|
||||
const (
|
||||
MessageTypeStep WebSocketMessageType = "step"
|
||||
MessageTypeSteamOutput WebSocketMessageType = "steam_output"
|
||||
MessageTypeError WebSocketMessageType = "error"
|
||||
MessageTypeComplete WebSocketMessageType = "complete"
|
||||
)
|
||||
|
||||
// WebSocketMessage is the base structure for all WebSocket messages
|
||||
type WebSocketMessage struct {
|
||||
Type WebSocketMessageType `json:"type"`
|
||||
ServerID *uuid.UUID `json:"server_id,omitempty"`
|
||||
Timestamp int64 `json:"timestamp"`
|
||||
Data interface{} `json:"data"`
|
||||
}
|
||||
|
||||
// StepMessage represents a step update message
|
||||
type StepMessage struct {
|
||||
Step ServerCreationStep `json:"step"`
|
||||
Status StepStatus `json:"status"`
|
||||
Message string `json:"message,omitempty"`
|
||||
Error string `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
// SteamOutputMessage represents SteamCMD output
|
||||
type SteamOutputMessage struct {
|
||||
Output string `json:"output"`
|
||||
IsError bool `json:"is_error"`
|
||||
}
|
||||
|
||||
// ErrorMessage represents an error message
|
||||
type ErrorMessage struct {
|
||||
Error string `json:"error"`
|
||||
Details string `json:"details,omitempty"`
|
||||
}
|
||||
|
||||
// CompleteMessage represents completion message
|
||||
type CompleteMessage struct {
|
||||
ServerID uuid.UUID `json:"server_id"`
|
||||
Success bool `json:"success"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
// GetStepDescription returns a human-readable description for each step
|
||||
func GetStepDescription(step ServerCreationStep) string {
|
||||
descriptions := map[ServerCreationStep]string{
|
||||
StepValidation: "Validating server configuration",
|
||||
StepDirectoryCreation: "Creating server directories",
|
||||
StepSteamDownload: "Downloading server files via Steam",
|
||||
StepConfigGeneration: "Generating server configuration files",
|
||||
StepServiceCreation: "Creating Windows service",
|
||||
StepFirewallRules: "Configuring firewall rules",
|
||||
StepDatabaseSave: "Saving server to database",
|
||||
StepCompleted: "Server creation completed",
|
||||
}
|
||||
return descriptions[step]
|
||||
}
|
||||
Reference in New Issue
Block a user