|
@@ -414,8 +414,13 @@ func PullModelHandler(c *gin.Context) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- if req.Name == "" {
|
|
|
- c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": "name is required"})
|
|
|
+ var model string
|
|
|
+ if req.Model != "" {
|
|
|
+ model = req.Model
|
|
|
+ } else if req.Name != "" {
|
|
|
+ model = req.Name
|
|
|
+ } else {
|
|
|
+ c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": "model is required"})
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -433,7 +438,7 @@ func PullModelHandler(c *gin.Context) {
|
|
|
ctx, cancel := context.WithCancel(c.Request.Context())
|
|
|
defer cancel()
|
|
|
|
|
|
- if err := PullModel(ctx, req.Name, regOpts, fn); err != nil {
|
|
|
+ if err := PullModel(ctx, model, regOpts, fn); err != nil {
|
|
|
ch <- gin.H{"error": err.Error()}
|
|
|
}
|
|
|
}()
|
|
@@ -458,8 +463,13 @@ func PushModelHandler(c *gin.Context) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- if req.Name == "" {
|
|
|
- c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": "name is required"})
|
|
|
+ var model string
|
|
|
+ if req.Model != "" {
|
|
|
+ model = req.Model
|
|
|
+ } else if req.Name != "" {
|
|
|
+ model = req.Name
|
|
|
+ } else {
|
|
|
+ c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": "model is required"})
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -477,7 +487,7 @@ func PushModelHandler(c *gin.Context) {
|
|
|
ctx, cancel := context.WithCancel(c.Request.Context())
|
|
|
defer cancel()
|
|
|
|
|
|
- if err := PushModel(ctx, req.Name, regOpts, fn); err != nil {
|
|
|
+ if err := PushModel(ctx, model, regOpts, fn); err != nil {
|
|
|
ch <- gin.H{"error": err.Error()}
|
|
|
}
|
|
|
}()
|
|
@@ -502,12 +512,17 @@ func CreateModelHandler(c *gin.Context) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- if req.Name == "" {
|
|
|
- c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": "name is required"})
|
|
|
+ var model string
|
|
|
+ if req.Model != "" {
|
|
|
+ model = req.Model
|
|
|
+ } else if req.Name != "" {
|
|
|
+ model = req.Name
|
|
|
+ } else {
|
|
|
+ c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": "model is required"})
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- if err := ParseModelPath(req.Name).Validate(); err != nil {
|
|
|
+ if err := ParseModelPath(model).Validate(); err != nil {
|
|
|
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
|
return
|
|
|
}
|
|
@@ -545,7 +560,7 @@ func CreateModelHandler(c *gin.Context) {
|
|
|
ctx, cancel := context.WithCancel(c.Request.Context())
|
|
|
defer cancel()
|
|
|
|
|
|
- if err := CreateModel(ctx, req.Name, filepath.Dir(req.Path), commands, fn); err != nil {
|
|
|
+ if err := CreateModel(ctx, model, filepath.Dir(req.Path), commands, fn); err != nil {
|
|
|
ch <- gin.H{"error": err.Error()}
|
|
|
}
|
|
|
}()
|
|
@@ -570,14 +585,19 @@ func DeleteModelHandler(c *gin.Context) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- if req.Name == "" {
|
|
|
- c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": "name is required"})
|
|
|
+ var model string
|
|
|
+ if req.Model != "" {
|
|
|
+ model = req.Model
|
|
|
+ } else if req.Name != "" {
|
|
|
+ model = req.Name
|
|
|
+ } else {
|
|
|
+ c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": "model is required"})
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- if err := DeleteModel(req.Name); err != nil {
|
|
|
+ if err := DeleteModel(model); err != nil {
|
|
|
if os.IsNotExist(err) {
|
|
|
- c.JSON(http.StatusNotFound, gin.H{"error": fmt.Sprintf("model '%s' not found", req.Name)})
|
|
|
+ c.JSON(http.StatusNotFound, gin.H{"error": fmt.Sprintf("model '%s' not found", model)})
|
|
|
} else {
|
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
|
}
|
|
@@ -610,21 +630,20 @@ func ShowModelHandler(c *gin.Context) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- switch {
|
|
|
- case req.Model == "" && req.Name == "":
|
|
|
+ var model string
|
|
|
+ if req.Model != "" {
|
|
|
+ model = req.Model
|
|
|
+ } else if req.Name != "" {
|
|
|
+ model = req.Name
|
|
|
+ } else {
|
|
|
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": "model is required"})
|
|
|
return
|
|
|
- case req.Model != "" && req.Name != "":
|
|
|
- c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": "both model and name are set"})
|
|
|
- return
|
|
|
- case req.Model == "" && req.Name != "":
|
|
|
- req.Model = req.Name
|
|
|
}
|
|
|
|
|
|
resp, err := GetModelInfo(req)
|
|
|
if err != nil {
|
|
|
if os.IsNotExist(err) {
|
|
|
- c.JSON(http.StatusNotFound, gin.H{"error": fmt.Sprintf("model '%s' not found", req.Name)})
|
|
|
+ c.JSON(http.StatusNotFound, gin.H{"error": fmt.Sprintf("model '%s' not found", model)})
|
|
|
} else {
|
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
|
}
|