2022-11-18 06:27:40 +00:00
|
|
|
package v1
|
|
|
|
|
|
|
|
import (
|
2022-11-18 08:14:23 +00:00
|
|
|
"errors"
|
|
|
|
"reflect"
|
|
|
|
|
2022-12-20 12:30:14 +00:00
|
|
|
"github.com/1Panel-dev/1Panel/backend/app/dto/request"
|
|
|
|
|
2022-11-18 06:27:40 +00: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 14:31:51 +00:00
|
|
|
// @Tags App
|
2023-01-05 03:57:03 +00:00
|
|
|
// @Summary List app installed
|
2023-01-04 14:31:51 +00:00
|
|
|
// @Description 获取已安装应用列表
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body request.AppInstalledSearch true "request"
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /apps/installed [post]
|
2022-11-18 06:27:40 +00:00
|
|
|
func (b *BaseApi) SearchAppInstalled(c *gin.Context) {
|
2022-12-14 07:08:21 +00:00
|
|
|
var req request.AppInstalledSearch
|
2022-11-18 06:27:40 +00:00
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(req.PageInfo, dto.PageInfo{}) {
|
|
|
|
total, list, err := appInstallService.Page(req)
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, dto.PageResult{
|
|
|
|
Items: list,
|
|
|
|
Total: total,
|
|
|
|
})
|
|
|
|
} else {
|
2023-01-16 07:30:24 +00:00
|
|
|
list, err := appInstallService.SearchForWebsite(req)
|
2022-11-18 06:27:40 +00:00
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, list)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-05 03:57:03 +00:00
|
|
|
// @Tags App
|
|
|
|
// @Summary Check app installed
|
|
|
|
// @Description 检查应用安装情况
|
|
|
|
// @Accept json
|
|
|
|
// @Param key path string true "request"
|
|
|
|
// @Success 200 {object} response.AppInstalledCheck
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /apps/installed/check/:key [get]
|
2022-11-22 14:47:38 +00:00
|
|
|
func (b *BaseApi) CheckAppInstalled(c *gin.Context) {
|
2022-11-18 08:14:23 +00:00
|
|
|
key, ok := c.Params.Get("key")
|
|
|
|
if !ok {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, errors.New("error key in path"))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
checkData, err := appInstallService.CheckExist(key)
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
2022-12-01 11:25:02 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, checkData)
|
|
|
|
}
|
|
|
|
|
2023-01-05 03:57:03 +00:00
|
|
|
// @Tags App
|
|
|
|
// @Summary Search app port by key
|
|
|
|
// @Description 获取应用端口
|
|
|
|
// @Accept json
|
|
|
|
// @Param key path string true "request"
|
|
|
|
// @Success 200 {integer} port
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /apps/installed/loadport/:key [get]
|
2022-12-04 11:20:36 +00:00
|
|
|
func (b *BaseApi) LoadPort(c *gin.Context) {
|
|
|
|
key, ok := c.Params.Get("key")
|
|
|
|
if !ok {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, errors.New("error key in path"))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
port, err := appInstallService.LoadPort(key)
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, port)
|
|
|
|
}
|
|
|
|
|
2023-01-05 03:57:03 +00:00
|
|
|
// @Tags App
|
|
|
|
// @Summary Search app password by key
|
|
|
|
// @Description 获取应用密码
|
|
|
|
// @Accept json
|
|
|
|
// @Param key path string true "request"
|
|
|
|
// @Success 200 {string} password
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /apps/installed/loadpassword/:key [get]
|
2022-12-20 12:30:14 +00:00
|
|
|
func (b *BaseApi) LoadPassword(c *gin.Context) {
|
|
|
|
key, ok := c.Params.Get("key")
|
|
|
|
if !ok {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, errors.New("error key in path"))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
password, err := appInstallService.LoadPassword(key)
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, password)
|
|
|
|
}
|
|
|
|
|
2023-01-05 03:57:03 +00:00
|
|
|
// @Tags App
|
|
|
|
// @Summary Check before delete
|
|
|
|
// @Description 删除前检查
|
|
|
|
// @Accept json
|
|
|
|
// @Param appInstallId path integer true "App install id"
|
|
|
|
// @Success 200 {anrry} dto.AppResource
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /apps/installed/delete/check/:appInstallId [get]
|
2022-12-01 11:25:02 +00: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 08:14:23 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, checkData)
|
|
|
|
}
|
|
|
|
|
2023-01-05 03:57:03 +00:00
|
|
|
// Sync app installed
|
|
|
|
// @Tags App
|
|
|
|
// @Summary Sync app installed
|
|
|
|
// @Description 同步已安装应用列表
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /apps/installed/sync [post]
|
|
|
|
// @x-panel-log {"bodyKeys":[],"paramKeys":[],"BeforeFuntions":[],"formatZH":"同步已安装应用列表","formatEN":"Sync the list of installed apps"}
|
2022-11-18 06:27:40 +00:00
|
|
|
func (b *BaseApi) SyncInstalled(c *gin.Context) {
|
|
|
|
if err := appInstallService.SyncAll(); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, "")
|
|
|
|
}
|
|
|
|
|
2023-01-05 03:57:03 +00:00
|
|
|
// @Tags App
|
|
|
|
// @Summary Page installed backups
|
|
|
|
// @Description 查询已安装备份列表分页
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body request.AppBackupSearch true "request"
|
|
|
|
// @Success 200 {object} dto.PageResult
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /apps/installed/backups [post]
|
2022-11-18 06:27:40 +00:00
|
|
|
func (b *BaseApi) SearchInstalledBackup(c *gin.Context) {
|
2022-12-14 07:08:21 +00:00
|
|
|
var req request.AppBackupSearch
|
2022-11-18 06:27:40 +00:00
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
total, list, err := appInstallService.PageInstallBackups(req)
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, dto.PageResult{
|
|
|
|
Items: list,
|
|
|
|
Total: total,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-01-05 03:57:03 +00: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]
|
|
|
|
// @x-panel-log {"bodyKeys":["installId","operate"],"paramKeys":[],"BeforeFuntions":[{"input_colume":"id","input_value":"installId","isList":false,"db":"app_installs","output_colume":"app_id","output_value":"appId"},{"input_colume":"id","input_value":"installId","isList":false,"db":"app_installs","output_colume":"name","output_value":"appName"},{"input_colume":"id","input_value":"appId","isList":false,"db":"apps","output_colume":"key","output_value":"appKey"}],"formatZH":"[appKey] 应用 [appName] [operate]","formatEN":"[appKey] App [appName] [operate]"}
|
2022-11-18 06:27:40 +00:00
|
|
|
func (b *BaseApi) OperateInstalled(c *gin.Context) {
|
2022-12-14 07:08:21 +00:00
|
|
|
var req request.AppInstalledOperate
|
2022-11-18 06:27:40 +00:00
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := appInstallService.Operate(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, nil)
|
|
|
|
}
|
|
|
|
|
2023-01-05 03:57:03 +00:00
|
|
|
// @Tags App
|
|
|
|
// @Summary Delete app backup record
|
|
|
|
// @Description 删除应用备份记录
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body request.AppBackupDelete true "request"
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /apps/installed/backups/del [post]
|
|
|
|
// @x-panel-log {"bodyKeys":["ids"],"paramKeys":[],"BeforeFuntions":[{"input_colume":"id","input_value":"ids","isList":true,"db":"app_install_backups","output_colume":"name","output_value":"names"}],"formatZH":"删除应用备份 [names]","formatEN":"Deleting an Application Backup [names]"}
|
2022-11-18 06:27:40 +00:00
|
|
|
func (b *BaseApi) DeleteAppBackup(c *gin.Context) {
|
2022-12-14 07:08:21 +00:00
|
|
|
var req request.AppBackupDelete
|
2022-11-18 06:27:40 +00:00
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := appInstallService.DeleteBackup(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, nil)
|
|
|
|
}
|
|
|
|
|
2023-01-05 03:57:03 +00:00
|
|
|
// @Tags App
|
|
|
|
// @Summary Search app service by key
|
|
|
|
// @Description 通过 key 获取应用 service
|
|
|
|
// @Accept json
|
|
|
|
// @Param key path string true "request"
|
|
|
|
// @Success 200 {anrry} response.AppService
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /apps/services/:key [get]
|
2022-11-18 06:27:40 +00: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 03:57:03 +00:00
|
|
|
// @Tags App
|
|
|
|
// @Summary Search app update version by install id
|
|
|
|
// @Description 通过 install id 获取应用更新版本
|
|
|
|
// @Accept json
|
|
|
|
// @Param appInstallId path integer true "request"
|
|
|
|
// @Success 200 {anrry} dto.AppVersion
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /apps/installed/:appInstallId/versions [get]
|
2022-11-18 06:27:40 +00: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 03:57:03 +00: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]
|
|
|
|
// @x-panel-log {"bodyKeys":["key","name","port"],"paramKeys":[],"BeforeFuntions":[],"formatZH":"应用端口修改 [key]-[name] => [port]","formatEN":"Application port update [key]-[name] => [port]"}
|
2022-11-18 06:27:40 +00:00
|
|
|
func (b *BaseApi) ChangeAppPort(c *gin.Context) {
|
2022-12-14 07:08:21 +00:00
|
|
|
var req request.PortUpdate
|
2022-11-18 06:27:40 +00:00
|
|
|
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 := appInstallService.ChangeAppPort(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, nil)
|
|
|
|
}
|
2022-12-09 09:16:07 +00:00
|
|
|
|
2023-01-05 03:57:03 +00:00
|
|
|
// @Tags App
|
|
|
|
// @Summary Search default config by key
|
|
|
|
// @Description 通过 key 获取应用默认配置
|
|
|
|
// @Accept json
|
|
|
|
// @Param key path string true "request"
|
|
|
|
// @Success 200 {string} content
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /apps/installed/conf/:key [get]
|
2022-12-09 09:16:07 +00:00
|
|
|
func (b *BaseApi) GetDefaultConfig(c *gin.Context) {
|
|
|
|
key := c.Param("key")
|
|
|
|
if key == "" {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInternalServer, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
content, err := appInstallService.GetDefaultConfigByKey(key)
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
helper.SuccessWithData(c, content)
|
|
|
|
}
|
2023-01-03 06:57:13 +00:00
|
|
|
|
2023-01-05 03:57:03 +00: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 06:57:13 +00: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)
|
|
|
|
}
|