1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-01-20 00:39:17 +08:00

211 lines
5.9 KiB
Go
Raw Normal View History

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/constant"
"github.com/1Panel-dev/1Panel/backend/global"
"github.com/gin-gonic/gin"
2022-10-28 17:04:57 +08:00
"reflect"
)
func (b *BaseApi) SearchApp(c *gin.Context) {
var req dto.AppRequest
if err := c.ShouldBindJSON(&req); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
return
}
list, err := appService.PageApp(req)
if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
helper.SuccessWithData(c, list)
}
func (b *BaseApi) SyncApp(c *gin.Context) {
if err := appService.SyncAppList(); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
helper.SuccessWithData(c, "")
}
2022-09-23 16:33:55 +08:00
func (b *BaseApi) GetApp(c *gin.Context) {
2022-11-03 17:06:48 +08:00
id, err := helper.GetParamID(c)
2022-09-23 16:33:55 +08:00
if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
return
}
2022-11-03 17:06:48 +08:00
appDTO, err := appService.GetApp(id)
2022-09-23 16:33:55 +08:00
if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
helper.SuccessWithData(c, appDTO)
}
func (b *BaseApi) GetAppDetail(c *gin.Context) {
2022-11-03 17:06:48 +08:00
appId, err := helper.GetIntParamByKey(c, "appId")
2022-09-23 16:33:55 +08:00
if err != nil {
2022-11-03 17:06:48 +08:00
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInternalServer, nil)
2022-09-23 16:33:55 +08:00
return
}
2022-11-03 17:06:48 +08:00
2022-09-23 16:33:55 +08:00
version := c.Param("version")
2022-11-03 17:06:48 +08:00
appDetailDTO, err := appService.GetAppDetail(appId, version)
2022-09-23 16:33:55 +08:00
if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
helper.SuccessWithData(c, appDetailDTO)
}
func (b *BaseApi) InstallApp(c *gin.Context) {
var req dto.AppInstallRequest
if err := c.ShouldBindJSON(&req); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
return
}
2022-11-02 15:19:14 +08:00
install, err := appService.Install(req.Name, req.AppDetailId, req.Params)
if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
2022-11-02 15:19:14 +08:00
helper.SuccessWithData(c, install)
}
2022-10-12 18:57:22 +08:00
func (b *BaseApi) DeleteAppBackup(c *gin.Context) {
var req dto.AppBackupDeleteRequest
if err := c.ShouldBindJSON(&req); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
return
}
if err := appService.DeleteBackup(req); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
helper.SuccessWithData(c, nil)
}
func (b *BaseApi) SearchInstalled(c *gin.Context) {
var req dto.AppInstalledRequest
if err := c.ShouldBindJSON(&req); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
return
}
2022-10-28 17:04:57 +08:00
if !reflect.DeepEqual(req.PageInfo, dto.PageInfo{}) {
total, list, err := appService.PageInstalled(req)
if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
helper.SuccessWithData(c, dto.PageResult{
Items: list,
Total: total,
})
} else {
list, err := appService.SearchInstalled(req)
if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
helper.SuccessWithData(c, list)
}
2022-10-12 18:57:22 +08:00
}
func (b *BaseApi) SearchInstalledBackup(c *gin.Context) {
var req dto.AppBackupRequest
if err := c.ShouldBindJSON(&req); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
return
}
total, list, err := appService.PageInstallBackups(req)
if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
helper.SuccessWithData(c, dto.PageResult{
Items: list,
Total: total,
})
}
2022-09-26 18:20:21 +08:00
func (b *BaseApi) OperateInstalled(c *gin.Context) {
2022-09-26 18:20:21 +08:00
var req dto.AppInstallOperate
if err := c.ShouldBindJSON(&req); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
return
}
if err := appService.OperateInstall(req); err != nil {
2022-09-26 18:20:21 +08:00
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
helper.SuccessWithData(c, nil)
}
func (b *BaseApi) SyncInstalled(c *gin.Context) {
if err := appService.SyncAllInstalled(); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
helper.SuccessWithData(c, "")
}
2022-10-07 15:49:39 +08:00
func (b *BaseApi) GetServices(c *gin.Context) {
key := c.Param("key")
services, err := appService.GetServices(key)
if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
helper.SuccessWithData(c, services)
}
2022-10-13 18:56:53 +08:00
func (b *BaseApi) GetUpdateVersions(c *gin.Context) {
2022-11-03 17:06:48 +08:00
appInstallId, err := helper.GetIntParamByKey(c, "appInstallId")
2022-10-13 18:56:53 +08:00
if err != nil {
2022-11-03 17:06:48 +08:00
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInternalServer, nil)
2022-10-13 18:56:53 +08:00
return
}
2022-11-03 17:06:48 +08:00
versions, err := appService.GetUpdateVersions(appInstallId)
2022-10-13 18:56:53 +08:00
if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
helper.SuccessWithData(c, versions)
}
func (b *BaseApi) ChangeAppPort(c *gin.Context) {
var req dto.PortUpdate
if err := c.ShouldBindJSON(&req); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
return
}
if err := global.VALID.Struct(req); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
return
}
if err := appService.ChangeAppPort(req); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
helper.SuccessWithData(c, nil)
}