2022-11-18 14:27:40 +08:00
|
|
|
package v1
|
|
|
|
|
|
|
|
import (
|
2022-12-20 20:30:14 +08:00
|
|
|
"github.com/1Panel-dev/1Panel/backend/app/dto/request"
|
|
|
|
|
2022-11-18 14:27:40 +08:00
|
|
|
"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"
|
|
|
|
)
|
|
|
|
|
2023-01-04 22:31:51 +08:00
|
|
|
// @Tags App
|
2023-08-23 22:44:14 +08:00
|
|
|
// @Summary Page app installed
|
|
|
|
// @Description 分页获取已安装应用列表
|
2023-01-04 22:31:51 +08:00
|
|
|
// @Accept json
|
|
|
|
// @Param request body request.AppInstalledSearch true "request"
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
2023-03-02 13:54:07 +08:00
|
|
|
// @Router /apps/installed/search [post]
|
2022-11-18 14:27:40 +08:00
|
|
|
func (b *BaseApi) SearchAppInstalled(c *gin.Context) {
|
2022-12-14 15:08:21 +08:00
|
|
|
var req request.AppInstalledSearch
|
2023-10-27 12:04:11 +08:00
|
|
|
if err := helper.CheckBindAndValidate(&req, c); err != nil {
|
2022-11-18 14:27:40 +08:00
|
|
|
return
|
|
|
|
}
|
2023-10-27 15:13:25 +08:00
|
|
|
if req.All {
|
|
|
|
list, err := appInstallService.SearchForWebsite(req)
|
2022-11-18 14:27:40 +08:00
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
2023-10-27 15:13:25 +08:00
|
|
|
helper.SuccessWithData(c, list)
|
2022-11-18 14:27:40 +08:00
|
|
|
} else {
|
2023-10-27 15:13:25 +08:00
|
|
|
total, list, err := appInstallService.Page(req)
|
2022-11-18 14:27:40 +08:00
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
2023-10-27 15:13:25 +08:00
|
|
|
helper.SuccessWithData(c, dto.PageResult{
|
|
|
|
Items: list,
|
|
|
|
Total: total,
|
|
|
|
})
|
2022-11-18 14:27:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-23 22:44:14 +08:00
|
|
|
// @Tags App
|
|
|
|
// @Summary List app installed
|
|
|
|
// @Description 获取已安装应用列表
|
|
|
|
// @Accept json
|
|
|
|
// @Success 200 array dto.AppInstallInfo
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /apps/installed/list [get]
|
|
|
|
func (b *BaseApi) ListAppInstalled(c *gin.Context) {
|
|
|
|
list, err := appInstallService.GetInstallList()
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, list)
|
|
|
|
}
|
|
|
|
|
2023-01-05 11:57:03 +08:00
|
|
|
// @Tags App
|
|
|
|
// @Summary Check app installed
|
|
|
|
// @Description 检查应用安装情况
|
|
|
|
// @Accept json
|
2023-08-29 10:50:15 +08:00
|
|
|
// @Param request body request.AppInstalledInfo true "request"
|
2023-01-05 11:57:03 +08:00
|
|
|
// @Success 200 {object} response.AppInstalledCheck
|
|
|
|
// @Security ApiKeyAuth
|
2023-08-29 10:50:15 +08:00
|
|
|
// @Router /apps/installed/check [post]
|
2022-11-22 22:47:38 +08:00
|
|
|
func (b *BaseApi) CheckAppInstalled(c *gin.Context) {
|
2023-08-29 10:50:15 +08:00
|
|
|
var req request.AppInstalledInfo
|
2023-10-27 12:04:11 +08:00
|
|
|
if err := helper.CheckBindAndValidate(&req, c); err != nil {
|
2023-08-29 10:50:15 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := global.VALID.Struct(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
2022-11-18 16:14:23 +08:00
|
|
|
return
|
|
|
|
}
|
2023-08-29 10:50:15 +08:00
|
|
|
checkData, err := appInstallService.CheckExist(req)
|
2022-11-18 16:14:23 +08:00
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
2022-12-01 19:25:02 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, checkData)
|
|
|
|
}
|
|
|
|
|
2023-01-05 11:57:03 +08:00
|
|
|
// @Tags App
|
|
|
|
// @Summary Search app port by key
|
|
|
|
// @Description 获取应用端口
|
|
|
|
// @Accept json
|
2023-08-29 10:50:15 +08:00
|
|
|
// @Param request body dto.OperationWithNameAndType true "request"
|
2023-01-05 11:57:03 +08:00
|
|
|
// @Success 200 {integer} port
|
|
|
|
// @Security ApiKeyAuth
|
2023-08-29 10:50:15 +08:00
|
|
|
// @Router /apps/installed/loadport [post]
|
2022-12-04 19:20:36 +08:00
|
|
|
func (b *BaseApi) LoadPort(c *gin.Context) {
|
2023-08-29 10:50:15 +08:00
|
|
|
var req dto.OperationWithNameAndType
|
2023-10-27 12:04:11 +08:00
|
|
|
if err := helper.CheckBindAndValidate(&req, c); err != nil {
|
2022-12-04 19:20:36 +08:00
|
|
|
return
|
|
|
|
}
|
2023-08-29 10:50:15 +08:00
|
|
|
port, err := appInstallService.LoadPort(req)
|
2022-12-04 19:20:36 +08:00
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, port)
|
|
|
|
}
|
|
|
|
|
2023-01-05 11:57:03 +08:00
|
|
|
// @Tags App
|
|
|
|
// @Summary Search app password by key
|
2023-04-11 10:26:25 +08:00
|
|
|
// @Description 获取应用连接信息
|
2023-01-05 11:57:03 +08:00
|
|
|
// @Accept json
|
2023-08-29 10:50:15 +08:00
|
|
|
// @Param request body dto.OperationWithNameAndType true "request"
|
2023-04-11 10:26:25 +08:00
|
|
|
// @Success 200 {string} response.DatabaseConn
|
2023-01-05 11:57:03 +08:00
|
|
|
// @Security ApiKeyAuth
|
2023-04-11 10:26:25 +08:00
|
|
|
// @Router /apps/installed/conninfo/:key [get]
|
|
|
|
func (b *BaseApi) LoadConnInfo(c *gin.Context) {
|
2023-08-29 10:50:15 +08:00
|
|
|
var req dto.OperationWithNameAndType
|
2023-10-27 12:04:11 +08:00
|
|
|
if err := helper.CheckBindAndValidate(&req, c); err != nil {
|
2022-12-20 20:30:14 +08:00
|
|
|
return
|
|
|
|
}
|
2023-08-29 10:50:15 +08:00
|
|
|
conn, err := appInstallService.LoadConnInfo(req)
|
2022-12-20 20:30:14 +08:00
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
2023-04-11 10:26:25 +08:00
|
|
|
helper.SuccessWithData(c, conn)
|
2022-12-20 20:30:14 +08:00
|
|
|
}
|
|
|
|
|
2023-01-05 11:57:03 +08:00
|
|
|
// @Tags App
|
|
|
|
// @Summary Check before delete
|
|
|
|
// @Description 删除前检查
|
|
|
|
// @Accept json
|
|
|
|
// @Param appInstallId path integer true "App install id"
|
2023-07-06 18:04:22 +08:00
|
|
|
// @Success 200 {array} dto.AppResource
|
2023-01-05 11:57:03 +08:00
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /apps/installed/delete/check/:appInstallId [get]
|
2022-12-01 19:25:02 +08:00
|
|
|
func (b *BaseApi) DeleteCheck(c *gin.Context) {
|
|
|
|
appInstallId, err := helper.GetIntParamByKey(c, "appInstallId")
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInternalServer, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
checkData, err := appInstallService.DeleteCheck(appInstallId)
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
2022-11-18 16:14:23 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, checkData)
|
|
|
|
}
|
|
|
|
|
2023-01-05 11:57:03 +08:00
|
|
|
// Sync app installed
|
|
|
|
// @Tags App
|
|
|
|
// @Summary Sync app installed
|
|
|
|
// @Description 同步已安装应用列表
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /apps/installed/sync [post]
|
2023-10-07 15:46:44 +08:00
|
|
|
// @x-panel-log {"bodyKeys":[],"paramKeys":[],"BeforeFunctions":[],"formatZH":"同步已安装应用列表","formatEN":"Sync the list of installed apps"}
|
2022-11-18 14:27:40 +08:00
|
|
|
func (b *BaseApi) SyncInstalled(c *gin.Context) {
|
2023-03-20 10:38:39 +08:00
|
|
|
if err := appInstallService.SyncAll(false); err != nil {
|
2022-11-18 14:27:40 +08:00
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, "")
|
|
|
|
}
|
|
|
|
|
2023-01-05 11:57:03 +08:00
|
|
|
// @Tags App
|
|
|
|
// @Summary Operate installed app
|
|
|
|
// @Description 操作已安装应用
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body request.AppInstalledOperate true "request"
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /apps/installed/op [post]
|
2023-10-07 15:46:44 +08:00
|
|
|
// @x-panel-log {"bodyKeys":["installId","operate"],"paramKeys":[],"BeforeFunctions":[{"input_column":"id","input_value":"installId","isList":false,"db":"app_installs","output_column":"app_id","output_value":"appId"},{"input_column":"id","input_value":"installId","isList":false,"db":"app_installs","output_column":"name","output_value":"appName"},{"input_column":"id","input_value":"appId","isList":false,"db":"apps","output_column":"key","output_value":"appKey"}],"formatZH":"[operate] 应用 [appKey][appName]","formatEN":"[operate] App [appKey][appName]"}
|
2022-11-18 14:27:40 +08:00
|
|
|
func (b *BaseApi) OperateInstalled(c *gin.Context) {
|
2022-12-14 15:08:21 +08:00
|
|
|
var req request.AppInstalledOperate
|
2023-10-27 12:04:11 +08:00
|
|
|
if err := helper.CheckBindAndValidate(&req, c); err != nil {
|
2022-11-18 14:27:40 +08:00
|
|
|
return
|
|
|
|
}
|
2023-04-12 14:22:29 +08:00
|
|
|
if err := appInstallService.Operate(req); err != nil {
|
2022-11-18 14:27:40 +08:00
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, nil)
|
|
|
|
}
|
|
|
|
|
2023-01-05 11:57:03 +08:00
|
|
|
// @Tags App
|
|
|
|
// @Summary Search app service by key
|
|
|
|
// @Description 通过 key 获取应用 service
|
|
|
|
// @Accept json
|
|
|
|
// @Param key path string true "request"
|
2023-07-06 18:04:22 +08:00
|
|
|
// @Success 200 {array} response.AppService
|
2023-01-05 11:57:03 +08:00
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /apps/services/:key [get]
|
2022-11-18 14:27:40 +08:00
|
|
|
func (b *BaseApi) GetServices(c *gin.Context) {
|
|
|
|
key := c.Param("key")
|
|
|
|
services, err := appInstallService.GetServices(key)
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, services)
|
|
|
|
}
|
|
|
|
|
2023-01-05 11:57:03 +08:00
|
|
|
// @Tags App
|
|
|
|
// @Summary Search app update version by install id
|
|
|
|
// @Description 通过 install id 获取应用更新版本
|
|
|
|
// @Accept json
|
|
|
|
// @Param appInstallId path integer true "request"
|
2023-07-06 18:04:22 +08:00
|
|
|
// @Success 200 {array} dto.AppVersion
|
2023-01-05 11:57:03 +08:00
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /apps/installed/:appInstallId/versions [get]
|
2022-11-18 14:27:40 +08:00
|
|
|
func (b *BaseApi) GetUpdateVersions(c *gin.Context) {
|
|
|
|
appInstallId, err := helper.GetIntParamByKey(c, "appInstallId")
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInternalServer, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
versions, err := appInstallService.GetUpdateVersions(appInstallId)
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, versions)
|
|
|
|
}
|
|
|
|
|
2023-01-05 11:57:03 +08:00
|
|
|
// @Tags App
|
|
|
|
// @Summary Change app port
|
|
|
|
// @Description 修改应用端口
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body request.PortUpdate true "request"
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /apps/installed/port/change [post]
|
2023-10-07 15:46:44 +08:00
|
|
|
// @x-panel-log {"bodyKeys":["key","name","port"],"paramKeys":[],"BeforeFunctions":[],"formatZH":"应用端口修改 [key]-[name] => [port]","formatEN":"Application port update [key]-[name] => [port]"}
|
2022-11-18 14:27:40 +08:00
|
|
|
func (b *BaseApi) ChangeAppPort(c *gin.Context) {
|
2022-12-14 15:08:21 +08:00
|
|
|
var req request.PortUpdate
|
2023-10-27 12:04:11 +08:00
|
|
|
if err := helper.CheckBindAndValidate(&req, c); err != nil {
|
2022-11-18 14:27:40 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := appInstallService.ChangeAppPort(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, nil)
|
|
|
|
}
|
2022-12-09 17:16:07 +08:00
|
|
|
|
2023-01-05 11:57:03 +08:00
|
|
|
// @Tags App
|
|
|
|
// @Summary Search default config by key
|
|
|
|
// @Description 通过 key 获取应用默认配置
|
|
|
|
// @Accept json
|
2023-09-06 21:22:12 +08:00
|
|
|
// @Param request body dto.OperationWithNameAndType true "request"
|
2023-01-05 11:57:03 +08:00
|
|
|
// @Success 200 {string} content
|
|
|
|
// @Security ApiKeyAuth
|
2023-09-06 21:22:12 +08:00
|
|
|
// @Router /apps/installed/conf [post]
|
2022-12-09 17:16:07 +08:00
|
|
|
func (b *BaseApi) GetDefaultConfig(c *gin.Context) {
|
2023-09-06 21:22:12 +08:00
|
|
|
var req dto.OperationWithNameAndType
|
2023-10-27 12:04:11 +08:00
|
|
|
if err := helper.CheckBindAndValidate(&req, c); err != nil {
|
2022-12-09 17:16:07 +08:00
|
|
|
return
|
|
|
|
}
|
2023-09-06 21:22:12 +08:00
|
|
|
content, err := appInstallService.GetDefaultConfigByKey(req.Type, req.Name)
|
2022-12-09 17:16:07 +08:00
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
helper.SuccessWithData(c, content)
|
|
|
|
}
|
2023-01-03 14:57:13 +08:00
|
|
|
|
2023-01-05 11:57:03 +08:00
|
|
|
// @Tags App
|
|
|
|
// @Summary Search params by appInstallId
|
|
|
|
// @Description 通过 install id 获取应用参数
|
|
|
|
// @Accept json
|
|
|
|
// @Param appInstallId path string true "request"
|
|
|
|
// @Success 200 {object} response.AppParam
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /apps/installed/params/:appInstallId [get]
|
2023-01-03 14:57:13 +08:00
|
|
|
func (b *BaseApi) GetParams(c *gin.Context) {
|
|
|
|
appInstallId, err := helper.GetIntParamByKey(c, "appInstallId")
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInternalServer, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
content, err := appInstallService.GetParams(appInstallId)
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, content)
|
|
|
|
}
|
2023-03-08 11:04:22 +08:00
|
|
|
|
|
|
|
// @Tags App
|
|
|
|
// @Summary Change app params
|
|
|
|
// @Description 修改应用参数
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body request.AppInstalledUpdate true "request"
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /apps/installed/params/update [post]
|
2023-10-07 15:46:44 +08:00
|
|
|
// @x-panel-log {"bodyKeys":["installId"],"paramKeys":[],"BeforeFunctions":[],"formatZH":"应用参数修改 [installId]","formatEN":"Application param update [installId]"}
|
2023-03-08 11:04:22 +08:00
|
|
|
func (b *BaseApi) UpdateInstalled(c *gin.Context) {
|
|
|
|
var req request.AppInstalledUpdate
|
2023-10-27 12:04:11 +08:00
|
|
|
if err := helper.CheckBindAndValidate(&req, c); err != nil {
|
2023-03-08 11:04:22 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := appInstallService.Update(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, nil)
|
|
|
|
}
|
2023-07-03 16:36:18 +08:00
|
|
|
|
|
|
|
// @Tags App
|
|
|
|
// @Summary ignore App Update
|
|
|
|
// @Description 忽略应用升级版本
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body request.AppInstalledIgnoreUpgrade true "request"
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /apps/installed/ignore [post]
|
2023-10-07 15:46:44 +08:00
|
|
|
// @x-panel-log {"bodyKeys":["installId"],"paramKeys":[],"BeforeFunctions":[],"formatZH":"忽略应用 [installId] 版本升级","formatEN":"Application param update [installId]"}
|
2023-07-03 16:36:18 +08:00
|
|
|
func (b *BaseApi) IgnoreUpgrade(c *gin.Context) {
|
|
|
|
var req request.AppInstalledIgnoreUpgrade
|
2023-10-27 12:04:11 +08:00
|
|
|
if err := helper.CheckBindAndValidate(&req, c); err != nil {
|
2023-07-03 16:36:18 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := appInstallService.IgnoreUpgrade(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithOutData(c)
|
|
|
|
}
|