GetUserRunDeploys godoc @Security ApiKey @Summary Get user running deploys @Description Get user running deploys @Tags User @Accept json @Produce json @Param username path string true "username" @Param repo_type path string true "model,space" Enums(model,sp
(ctx *gin.Context)
| 639 | // @Failure 500 {object} types.APIInternalServerError "Internal server error" |
| 640 | // @Router /user/{username}/run/{repo_type} [get] |
| 641 | func (h *UserHandler) GetRunDeploys(ctx *gin.Context) { |
| 642 | currentUser := httpbase.GetCurrentUser(ctx) |
| 643 | if currentUser == "" { |
| 644 | httpbase.UnauthorizedError(ctx, component.ErrUserNotFound) |
| 645 | return |
| 646 | } |
| 647 | |
| 648 | username := ctx.Param("username") |
| 649 | if currentUser != username { |
| 650 | slog.Warn("invalid user to list deploys", slog.String("currentUser", currentUser), slog.String("username", username)) |
| 651 | httpbase.ServerError(ctx, errors.New("invalid user")) |
| 652 | return |
| 653 | } |
| 654 | |
| 655 | deployTypeStr := ctx.Query("deploy_type") |
| 656 | if deployTypeStr == "" { |
| 657 | // backward compatibility for inferences |
| 658 | deployTypeStr = strconv.Itoa(types.InferenceType) |
| 659 | } |
| 660 | deployType, err := strconv.Atoi(deployTypeStr) |
| 661 | if err != nil { |
| 662 | slog.Error("Bad request deploy type format", "error", err) |
| 663 | httpbase.BadRequest(ctx, err.Error()) |
| 664 | return |
| 665 | } |
| 666 | |
| 667 | per, page, err := common.GetPerAndPageFromContext(ctx) |
| 668 | if err != nil { |
| 669 | slog.Error("Bad request format of page and per", slog.Any("error", err)) |
| 670 | httpbase.BadRequest(ctx, err.Error()) |
| 671 | return |
| 672 | } |
| 673 | repoType := common.RepoTypeFromParam(ctx) |
| 674 | if repoType != types.ModelRepo && repoType != types.SpaceRepo { |
| 675 | slog.Error("Invalid repo type", slog.Any("repo_type", repoType)) |
| 676 | httpbase.BadRequest(ctx, "Invalid repo type") |
| 677 | return |
| 678 | } |
| 679 | |
| 680 | var req types.DeployReq |
| 681 | req.CurrentUser = currentUser |
| 682 | req.Page = page |
| 683 | req.PageSize = per |
| 684 | req.RepoType = repoType |
| 685 | req.DeployType = deployType |
| 686 | ds, total, err := h.c.ListDeploys(ctx, repoType, &req) |
| 687 | if err != nil { |
| 688 | slog.Error("Failed to get deploy repo list", slog.Any("error", err), slog.Any("req", req)) |
| 689 | httpbase.ServerError(ctx, err) |
| 690 | return |
| 691 | } |
| 692 | respData := gin.H{ |
| 693 | "message": "OK", |
| 694 | "data": ds, |
| 695 | "total": total, |
| 696 | } |
| 697 | ctx.JSON(http.StatusOK, respData) |
| 698 | } |
nothing calls this directly
no test coverage detected