fix
All checks were successful
Dynamic Branch Deploy / build-and-deploy (push) Successful in 1m43s
All checks were successful
Dynamic Branch Deploy / build-and-deploy (push) Successful in 1m43s
This commit is contained in:
67
handlers.go
67
handlers.go
@@ -3,9 +3,12 @@ package main
|
||||
import (
|
||||
"encoding/json"
|
||||
"html"
|
||||
"io"
|
||||
"log"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -344,3 +347,67 @@ func handleAdminBadwords(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
}
|
||||
|
||||
func handleAdminUpload(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodPost {
|
||||
http.Error(w, "Nur POST erlaubt", 405)
|
||||
return
|
||||
}
|
||||
|
||||
r.ParseMultipartForm(10 << 20)
|
||||
file, header, err := r.FormFile("file")
|
||||
if err != nil {
|
||||
http.Error(w, "Keine Datei gefunden", 400)
|
||||
return
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
filename := filepath.Base(header.Filename)
|
||||
|
||||
targetPath := filepath.Join("./static/assets", filename)
|
||||
|
||||
// Datei erstellen
|
||||
dst, err := os.Create(targetPath)
|
||||
if err != nil {
|
||||
http.Error(w, "Konnte Datei nicht speichern (Rechte?)", 500)
|
||||
return
|
||||
}
|
||||
defer dst.Close()
|
||||
|
||||
// Inhalt kopieren
|
||||
if _, err := io.Copy(dst, file); err != nil {
|
||||
http.Error(w, "Fehler beim Schreiben", 500)
|
||||
return
|
||||
}
|
||||
|
||||
log.Printf("📂 UPLOAD: %s erfolgreich gespeichert.", filename)
|
||||
|
||||
// JSON Antwort mit dem Pfad zurückgeben
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(map[string]string{
|
||||
"status": "ok",
|
||||
"filename": filename,
|
||||
})
|
||||
}
|
||||
|
||||
// 2. CONFIG SPEICHERN (Redis)
|
||||
func handleAdminSaveConfig(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodPost {
|
||||
http.Error(w, "Nur POST", 405)
|
||||
return
|
||||
}
|
||||
|
||||
var newConfig GameConfig
|
||||
if err := json.NewDecoder(r.Body).Decode(&newConfig); err != nil {
|
||||
http.Error(w, "Bad JSON", 400)
|
||||
return
|
||||
}
|
||||
|
||||
data, _ := json.Marshal(newConfig)
|
||||
rdb.Set(ctx, "config:gamedata", data, 0)
|
||||
|
||||
defaultConfig.Obstacles = newConfig.Obstacles
|
||||
defaultConfig.Backgrounds = newConfig.Backgrounds
|
||||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user