2023-03-29 14:58:28 +08:00
|
|
|
package v1
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
|
|
|
|
"github.com/1Panel-dev/1Panel/backend/app/dto"
|
|
|
|
"github.com/1Panel-dev/1Panel/backend/app/dto/request"
|
|
|
|
"github.com/1Panel-dev/1Panel/backend/constant"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
|
|
|
// @Tags Runtime
|
|
|
|
// @Summary List runtimes
|
|
|
|
// @Description 获取运行环境列表
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body request.RuntimeSearch true "request"
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /runtimes/search [post]
|
|
|
|
func (b *BaseApi) SearchRuntimes(c *gin.Context) {
|
|
|
|
var req request.RuntimeSearch
|
2023-10-10 18:36:29 +08:00
|
|
|
if err := helper.CheckBindAndValidate(&req, c); err != nil {
|
2023-03-29 14:58:28 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
total, items, err := runtimeService.Page(req)
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, dto.PageResult{
|
|
|
|
Total: total,
|
|
|
|
Items: items,
|
|
|
|
})
|
|
|
|
}
|
2023-03-30 16:47:47 +08:00
|
|
|
|
|
|
|
// @Tags Runtime
|
|
|
|
// @Summary Create runtime
|
|
|
|
// @Description 创建运行环境
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body request.RuntimeCreate true "request"
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /runtimes [post]
|
2023-10-07 15:46:44 +08:00
|
|
|
// @x-panel-log {"bodyKeys":["name"],"paramKeys":[],"BeforeFunctions":[],"formatZH":"创建运行环境 [name]","formatEN":"Create runtime [name]"}
|
2023-03-30 16:47:47 +08:00
|
|
|
func (b *BaseApi) CreateRuntime(c *gin.Context) {
|
|
|
|
var req request.RuntimeCreate
|
2023-10-10 18:36:29 +08:00
|
|
|
if err := helper.CheckBindAndValidate(&req, c); err != nil {
|
2023-03-30 16:47:47 +08:00
|
|
|
return
|
|
|
|
}
|
2023-12-12 15:18:09 +08:00
|
|
|
ssl, err := runtimeService.Create(req)
|
|
|
|
if err != nil {
|
2023-03-30 16:47:47 +08:00
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
2023-12-12 15:18:09 +08:00
|
|
|
helper.SuccessWithData(c, ssl)
|
2023-03-31 14:02:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// @Tags Website
|
|
|
|
// @Summary Delete runtime
|
|
|
|
// @Description 删除运行环境
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body request.RuntimeDelete true "request"
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /runtimes/del [post]
|
2023-10-07 15:46:44 +08:00
|
|
|
// @x-panel-log {"bodyKeys":["id"],"paramKeys":[],"BeforeFunctions":[],"formatZH":"删除网站 [name]","formatEN":"Delete website [name]"}
|
2023-03-31 14:02:28 +08:00
|
|
|
func (b *BaseApi) DeleteRuntime(c *gin.Context) {
|
|
|
|
var req request.RuntimeDelete
|
2023-10-10 18:36:29 +08:00
|
|
|
if err := helper.CheckBindAndValidate(&req, c); err != nil {
|
2023-03-31 14:02:28 +08:00
|
|
|
return
|
|
|
|
}
|
2023-09-25 17:50:14 +08:00
|
|
|
err := runtimeService.Delete(req)
|
2023-03-31 14:02:28 +08:00
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithOutData(c)
|
2023-03-30 16:47:47 +08:00
|
|
|
}
|
2023-04-02 16:54:00 +08:00
|
|
|
|
|
|
|
// @Tags Runtime
|
|
|
|
// @Summary Update runtime
|
|
|
|
// @Description 更新运行环境
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body request.RuntimeUpdate true "request"
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /runtimes/update [post]
|
2023-10-07 15:46:44 +08:00
|
|
|
// @x-panel-log {"bodyKeys":["name"],"paramKeys":[],"BeforeFunctions":[],"formatZH":"更新运行环境 [name]","formatEN":"Update runtime [name]"}
|
2023-04-02 16:54:00 +08:00
|
|
|
func (b *BaseApi) UpdateRuntime(c *gin.Context) {
|
|
|
|
var req request.RuntimeUpdate
|
2023-10-10 18:36:29 +08:00
|
|
|
if err := helper.CheckBindAndValidate(&req, c); err != nil {
|
2023-04-02 16:54:00 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := runtimeService.Update(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithOutData(c)
|
|
|
|
}
|
|
|
|
|
|
|
|
// @Tags Runtime
|
|
|
|
// @Summary Get runtime
|
|
|
|
// @Description 获取运行环境
|
|
|
|
// @Accept json
|
|
|
|
// @Param id path string true "request"
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /runtimes/:id [get]
|
|
|
|
func (b *BaseApi) GetRuntime(c *gin.Context) {
|
|
|
|
id, err := helper.GetIntParamByKey(c, "id")
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInternalServer, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
res, err := runtimeService.Get(id)
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, res)
|
|
|
|
}
|
2023-09-25 17:50:14 +08:00
|
|
|
|
|
|
|
// @Tags Runtime
|
|
|
|
// @Summary Get Node package scripts
|
|
|
|
// @Description 获取 Node 项目的 scripts
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body request.NodePackageReq true "request"
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /runtimes/node/package [post]
|
|
|
|
func (b *BaseApi) GetNodePackageRunScript(c *gin.Context) {
|
|
|
|
var req request.NodePackageReq
|
2023-10-10 18:36:29 +08:00
|
|
|
if err := helper.CheckBindAndValidate(&req, c); err != nil {
|
2023-09-25 17:50:14 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
res, err := runtimeService.GetNodePackageRunScript(req)
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, res)
|
|
|
|
}
|
2023-09-26 22:50:16 +08:00
|
|
|
|
|
|
|
// @Tags Runtime
|
|
|
|
// @Summary Operate runtime
|
|
|
|
// @Description 操作运行环境
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body request.RuntimeOperate true "request"
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /runtimes/operate [post]
|
2023-10-07 15:46:44 +08:00
|
|
|
// @x-panel-log {"bodyKeys":["id"],"paramKeys":[],"BeforeFunctions":[],"formatZH":"操作运行环境 [name]","formatEN":"Operate runtime [name]"}
|
2023-09-26 22:50:16 +08:00
|
|
|
func (b *BaseApi) OperateRuntime(c *gin.Context) {
|
|
|
|
var req request.RuntimeOperate
|
2023-10-10 18:36:29 +08:00
|
|
|
if err := helper.CheckBindAndValidate(&req, c); err != nil {
|
2023-09-26 22:50:16 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
err := runtimeService.OperateRuntime(req)
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithOutData(c)
|
|
|
|
}
|
2023-10-09 19:36:32 +08:00
|
|
|
|
|
|
|
// @Tags Runtime
|
|
|
|
// @Summary Get Node modules
|
|
|
|
// @Description 获取 Node 项目的 modules
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body request.NodeModuleReq true "request"
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /runtimes/node/modules [post]
|
|
|
|
func (b *BaseApi) GetNodeModules(c *gin.Context) {
|
|
|
|
var req request.NodeModuleReq
|
2023-10-10 18:36:29 +08:00
|
|
|
if err := helper.CheckBindAndValidate(&req, c); err != nil {
|
2023-10-09 19:36:32 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
res, err := runtimeService.GetNodeModules(req)
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, res)
|
|
|
|
}
|
2023-10-10 17:34:28 +08:00
|
|
|
|
|
|
|
// @Tags Runtime
|
|
|
|
// @Summary Operate Node modules
|
|
|
|
// @Description 操作 Node 项目 modules
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body request.NodeModuleReq true "request"
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /runtimes/node/modules/operate [post]
|
|
|
|
func (b *BaseApi) OperateNodeModules(c *gin.Context) {
|
2023-10-11 11:22:29 +08:00
|
|
|
var req request.NodeModuleOperateReq
|
2023-10-10 18:36:29 +08:00
|
|
|
if err := helper.CheckBindAndValidate(&req, c); err != nil {
|
2023-10-10 17:34:28 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
err := runtimeService.OperateNodeModules(req)
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithOutData(c)
|
|
|
|
}
|
2024-03-15 15:36:07 +08:00
|
|
|
|
|
|
|
// @Tags Runtime
|
|
|
|
// @Summary Sync runtime status
|
|
|
|
// @Description 同步运行环境状态
|
|
|
|
// @Accept json
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /runtimes/sync [post]
|
|
|
|
func (b *BaseApi) SyncStatus(c *gin.Context) {
|
|
|
|
err := runtimeService.SyncRuntimeStatus()
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithOutData(c)
|
|
|
|
}
|