feat: implement file upload

This commit is contained in:
2025-05-18 19:29:36 +02:00
parent e1fdf51ed0
commit 17a5e98e77
5 changed files with 116 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
package http
import (
"encoding/base64"
"encoding/json"
"net/http"
@@ -26,3 +27,31 @@ func HandleShutdown(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(map[string]string{"status": "success"})
}
func HandleFileUpload(w http.ResponseWriter, r *http.Request) {
// Parse the request body
var fileUpload struct {
Path string `json:"path"`
Content string `json:"content"`
}
if err := json.NewDecoder(r.Body).Decode(&fileUpload); err != nil {
WriteError(w, "Invalid request body", http.StatusBadRequest)
return
}
// Decode base64 encoded content to bytes
contentBytes, err := base64.StdEncoding.DecodeString(fileUpload.Content)
if err != nil {
WriteError(w, "Failed to decode base64 content", http.StatusBadRequest)
return
}
// Store the file
if err := system.StoreFile(fileUpload.Path, contentBytes); err != nil {
WriteError(w, err.Error(), http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(map[string]string{"status": "success"})
}