r11_urpm-repo/api.go
2025-01-13 19:23:44 +03:00

35 lines
No EOL
1.1 KiB
Go

package main
import (
"net/http"
"github.com/go-chi/chi/v5"
)
func (r *Repository) UploadHandler(w http.ResponseWriter, req *http.Request) {
arch := chi.URLParam(req, "arch")
if arch == "" {
http.Error(w, "Invalid architecture", http.StatusBadRequest)
logger.Error("Invalid architecture provided")
return
}
file, handler, err := req.FormFile("package")
if err != nil {
http.Error(w, "Error retrieving file", http.StatusInternalServerError)
logger.Errorf("Error retrieving file: %v", err)
return
}
defer file.Close()
logger.Infof("Uploading package %s for architecture %s", handler.Filename, arch)
if err := r.SavePackage(arch, handler.Filename, file); err != nil {
http.Error(w, "Error saving package", http.StatusInternalServerError)
logger.Errorf("Error saving package: %v", err)
return
}
w.WriteHeader(http.StatusOK)
w.Write([]byte("Package uploaded successfully"))
logger.Infof("Package %s uploaded successfully for architecture %s", handler.Filename, arch)
}