2022-09-22 08:16:04 +00:00
|
|
|
package v1
|
|
|
|
|
|
|
|
import (
|
2022-10-17 08:32:31 +00:00
|
|
|
"github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
|
2022-12-14 07:08:21 +00:00
|
|
|
"github.com/1Panel-dev/1Panel/backend/app/dto/request"
|
2022-10-17 08:32:31 +00:00
|
|
|
"github.com/1Panel-dev/1Panel/backend/constant"
|
2022-09-22 08:16:04 +00:00
|
|
|
"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 apps
|
2023-01-04 14:31:51 +00:00
|
|
|
// @Description 获取应用列表
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body request.AppSearch true "request"
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /apps/search [post]
|
2022-10-11 08:27:58 +00:00
|
|
|
func (b *BaseApi) SearchApp(c *gin.Context) {
|
2022-12-14 07:08:21 +00:00
|
|
|
var req request.AppSearch
|
2022-09-22 08:16:04 +00:00
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
2022-10-11 08:27:58 +00:00
|
|
|
list, err := appService.PageApp(req)
|
2022-09-22 08:16:04 +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 Sync app list
|
|
|
|
// @Description 同步应用列表
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /apps/sync [post]
|
|
|
|
// @x-panel-log {"bodyKeys":[],"paramKeys":[],"BeforeFuntions":[],"formatZH":"应用商店同步","formatEN":"App store synchronization"}
|
2022-10-11 08:27:58 +00:00
|
|
|
func (b *BaseApi) SyncApp(c *gin.Context) {
|
2022-09-29 10:16:56 +00:00
|
|
|
if err := appService.SyncAppList(); err != nil {
|
2022-09-22 08:16:04 +00:00
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, "")
|
|
|
|
}
|
2022-09-23 08:33:55 +00:00
|
|
|
|
2023-01-05 03:57:03 +00:00
|
|
|
// @Tags App
|
2023-02-08 09:09:21 +00:00
|
|
|
// @Summary Search app by key
|
|
|
|
// @Description 通过 key 获取应用信息
|
2023-01-05 03:57:03 +00:00
|
|
|
// @Accept json
|
2023-02-08 09:09:21 +00:00
|
|
|
// @Param key path string true "app key"
|
2023-01-05 03:57:03 +00:00
|
|
|
// @Success 200 {object} response.AppDTO
|
|
|
|
// @Security ApiKeyAuth
|
2023-02-08 09:09:21 +00:00
|
|
|
// @Router /apps/:key [get]
|
2022-09-23 08:33:55 +00:00
|
|
|
func (b *BaseApi) GetApp(c *gin.Context) {
|
2023-02-08 09:09:21 +00:00
|
|
|
appKey, err := helper.GetStrParamByKey(c, "key")
|
2022-09-23 08:33:55 +00:00
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
2023-02-08 09:09:21 +00:00
|
|
|
appDTO, err := appService.GetApp(appKey)
|
2022-09-23 08:33:55 +00:00
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, appDTO)
|
|
|
|
}
|
2023-01-05 03:57:03 +00:00
|
|
|
|
|
|
|
// @Tags App
|
|
|
|
// @Summary Search app detail by id
|
|
|
|
// @Description 通过 id 获取应用详情
|
|
|
|
// @Accept json
|
|
|
|
// @Param appId path integer true "app id"
|
|
|
|
// @Param version path string true "app 版本"
|
|
|
|
// @Success 200 {object} response.AppDetailDTO
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /apps/detail/:appId/:version [get]
|
2022-09-23 08:33:55 +00:00
|
|
|
func (b *BaseApi) GetAppDetail(c *gin.Context) {
|
2022-11-03 09:06:48 +00:00
|
|
|
appId, err := helper.GetIntParamByKey(c, "appId")
|
2022-09-23 08:33:55 +00:00
|
|
|
if err != nil {
|
2022-11-03 09:06:48 +00:00
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInternalServer, nil)
|
2022-09-23 08:33:55 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
version := c.Param("version")
|
2022-11-03 09:06:48 +00:00
|
|
|
appDetailDTO, err := appService.GetAppDetail(appId, version)
|
2022-09-23 08:33:55 +00:00
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, appDetailDTO)
|
|
|
|
}
|
2022-09-26 08:32:40 +00:00
|
|
|
|
2023-01-05 03:57:03 +00:00
|
|
|
// @Tags App
|
|
|
|
// @Summary Install app
|
|
|
|
// @Description 安装应用
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body request.AppInstallCreate true "request"
|
|
|
|
// @Success 200 {object} model.AppInstall
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /apps/install [post]
|
|
|
|
// @x-panel-log {"bodyKeys":["name"],"paramKeys":[],"BeforeFuntions":[{"input_colume":"name","input_value":"name","isList":false,"db":"app_installs","output_colume":"app_id","output_value":"appId"},{"info":"appId","isList":false,"db":"apps","output_colume":"key","output_value":"appKey"}],"formatZH":"安装应用 [appKey]-[name]","formatEN":"Install app [appKey]-[name]"}
|
2022-09-26 08:32:40 +00:00
|
|
|
func (b *BaseApi) InstallApp(c *gin.Context) {
|
2022-12-14 07:08:21 +00:00
|
|
|
var req request.AppInstallCreate
|
2022-09-26 08:32:40 +00:00
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
2022-12-22 07:26:25 +00:00
|
|
|
tx, ctx := helper.GetTxAndContext()
|
|
|
|
install, err := appService.Install(ctx, req)
|
2022-11-02 07:19:14 +00:00
|
|
|
if err != nil {
|
2022-12-22 07:26:25 +00:00
|
|
|
tx.Rollback()
|
2022-09-26 08:32:40 +00:00
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
2022-12-22 07:26:25 +00:00
|
|
|
tx.Commit()
|
2022-11-02 07:19:14 +00:00
|
|
|
helper.SuccessWithData(c, install)
|
2022-09-26 08:32:40 +00:00
|
|
|
}
|
2023-01-16 07:30:24 +00:00
|
|
|
|
|
|
|
func (b *BaseApi) GetAppTags(c *gin.Context) {
|
|
|
|
tags, err := appService.GetAppTags()
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, tags)
|
|
|
|
}
|