diff --git a/server/routes.go b/server/routes.go index 71e01a34..0dce976d 100644 --- a/server/routes.go +++ b/server/routes.go @@ -142,6 +142,11 @@ func GenerateHandler(c *gin.Context) { return } + if req.Model == "" { + c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": "model is required"}) + return + } + model, err := GetModel(req.Model) if err != nil { var pErr *fs.PathError @@ -231,6 +236,11 @@ func EmbeddingHandler(c *gin.Context) { return } + if req.Model == "" { + c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": "model is required"}) + return + } + model, err := GetModel(req.Model) if err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) @@ -268,6 +278,11 @@ func PullModelHandler(c *gin.Context) { return } + if req.Name == "" { + c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": "name is required"}) + return + } + ch := make(chan any) go func() { defer close(ch) @@ -302,6 +317,11 @@ func PushModelHandler(c *gin.Context) { return } + if req.Name == "" { + c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": "name is required"}) + return + } + ch := make(chan any) go func() { defer close(ch) @@ -334,6 +354,11 @@ func CreateModelHandler(c *gin.Context) { return } + if req.Name == "" || req.Path == "" { + c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": "name and path are required"}) + return + } + ch := make(chan any) go func() { defer close(ch) @@ -364,6 +389,11 @@ func DeleteModelHandler(c *gin.Context) { return } + if req.Name == "" { + c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": "name is required"}) + return + } + if err := DeleteModel(req.Name); err != nil { if os.IsNotExist(err) { c.JSON(http.StatusNotFound, gin.H{"error": fmt.Sprintf("model '%s' not found", req.Name)}) @@ -394,6 +424,11 @@ func ShowModelHandler(c *gin.Context) { return } + if req.Name == "" { + c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": "name is required"}) + return + } + resp, err := GetModelInfo(req.Name) if err != nil { if os.IsNotExist(err) { @@ -505,6 +540,11 @@ func CopyModelHandler(c *gin.Context) { return } + if req.Source == "" || req.Destination == "" { + c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": "source add destination are required"}) + return + } + if err := CopyModel(req.Source, req.Destination); err != nil { if os.IsNotExist(err) { c.JSON(http.StatusNotFound, gin.H{"error": fmt.Sprintf("model '%s' not found", req.Source)})