2022-09-22 16:16:04 +08:00
|
|
|
package v1
|
|
|
|
|
|
|
|
import (
|
2022-10-17 16:32:31 +08:00
|
|
|
"github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
|
2022-12-14 15:08:21 +08:00
|
|
|
"github.com/1Panel-dev/1Panel/backend/app/dto/request"
|
2022-10-17 16:32:31 +08:00
|
|
|
"github.com/1Panel-dev/1Panel/backend/constant"
|
2023-02-27 17:22:14 +08:00
|
|
|
"github.com/1Panel-dev/1Panel/backend/global"
|
2023-05-22 17:10:51 +08:00
|
|
|
"github.com/1Panel-dev/1Panel/backend/i18n"
|
2022-09-22 16:16:04 +08:00
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
2023-01-04 22:31:51 +08:00
|
|
|
// @Tags App
|
2023-01-05 11:57:03 +08:00
|
|
|
// @Summary List apps
|
2023-01-04 22:31:51 +08:00
|
|
|
// @Description 获取应用列表
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body request.AppSearch true "request"
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /apps/search [post]
|
2022-10-11 16:27:58 +08:00
|
|
|
func (b *BaseApi) SearchApp(c *gin.Context) {
|
2022-12-14 15:08:21 +08:00
|
|
|
var req request.AppSearch
|
2023-10-27 12:04:11 +08:00
|
|
|
if err := helper.CheckBindAndValidate(&req, c); err != nil {
|
2022-09-22 16:16:04 +08:00
|
|
|
return
|
|
|
|
}
|
2022-10-11 16:27:58 +08:00
|
|
|
list, err := appService.PageApp(req)
|
2022-09-22 16:16:04 +08:00
|
|
|
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 Sync app list
|
|
|
|
// @Description 同步应用列表
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /apps/sync [post]
|
2023-10-07 15:46:44 +08:00
|
|
|
// @x-panel-log {"bodyKeys":[],"paramKeys":[],"BeforeFunctions":[],"formatZH":"应用商店同步","formatEN":"App store synchronization"}
|
2022-10-11 16:27:58 +08:00
|
|
|
func (b *BaseApi) SyncApp(c *gin.Context) {
|
2023-05-09 15:47:43 +08:00
|
|
|
go appService.SyncAppListFromLocal()
|
2023-05-22 17:10:51 +08:00
|
|
|
res, err := appService.GetAppUpdate()
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
2023-11-03 18:18:12 +08:00
|
|
|
|
2023-05-22 17:10:51 +08:00
|
|
|
if !res.CanUpdate {
|
2023-11-03 18:18:12 +08:00
|
|
|
if res.IsSyncing {
|
|
|
|
helper.SuccessWithMsg(c, i18n.GetMsgByKey("AppStoreIsSyncing"))
|
|
|
|
} else {
|
|
|
|
helper.SuccessWithMsg(c, i18n.GetMsgByKey("AppStoreIsUpToDate"))
|
|
|
|
}
|
2023-05-22 17:10:51 +08:00
|
|
|
return
|
|
|
|
}
|
2023-05-09 15:47:43 +08:00
|
|
|
go func() {
|
|
|
|
if err := appService.SyncAppListFromRemote(); err != nil {
|
2023-10-09 15:46:27 +08:00
|
|
|
global.LOG.Errorf("Synchronization with the App Store failed [%s]", err.Error())
|
2023-05-09 15:47:43 +08:00
|
|
|
}
|
|
|
|
}()
|
2022-09-22 16:16:04 +08:00
|
|
|
helper.SuccessWithData(c, "")
|
|
|
|
}
|
2022-09-23 16:33:55 +08:00
|
|
|
|
2023-01-05 11:57:03 +08:00
|
|
|
// @Tags App
|
2023-02-08 17:09:21 +08:00
|
|
|
// @Summary Search app by key
|
|
|
|
// @Description 通过 key 获取应用信息
|
2023-01-05 11:57:03 +08:00
|
|
|
// @Accept json
|
2023-02-08 17:09:21 +08:00
|
|
|
// @Param key path string true "app key"
|
2023-01-05 11:57:03 +08:00
|
|
|
// @Success 200 {object} response.AppDTO
|
|
|
|
// @Security ApiKeyAuth
|
2023-02-08 17:09:21 +08:00
|
|
|
// @Router /apps/:key [get]
|
2022-09-23 16:33:55 +08:00
|
|
|
func (b *BaseApi) GetApp(c *gin.Context) {
|
2023-02-08 17:09:21 +08:00
|
|
|
appKey, err := helper.GetStrParamByKey(c, "key")
|
2022-09-23 16:33:55 +08:00
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
2023-02-08 17:09:21 +08:00
|
|
|
appDTO, err := appService.GetApp(appKey)
|
2022-09-23 16:33:55 +08:00
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, appDTO)
|
|
|
|
}
|
2023-01-05 11:57:03 +08:00
|
|
|
|
|
|
|
// @Tags App
|
2023-04-06 00:09:58 +08:00
|
|
|
// @Summary Search app detail by appid
|
|
|
|
// @Description 通过 appid 获取应用详情
|
2023-01-05 11:57:03 +08:00
|
|
|
// @Accept json
|
|
|
|
// @Param appId path integer true "app id"
|
|
|
|
// @Param version path string true "app 版本"
|
2023-03-30 16:47:47 +08:00
|
|
|
// @Param version path string true "app 类型"
|
2023-01-05 11:57:03 +08:00
|
|
|
// @Success 200 {object} response.AppDetailDTO
|
|
|
|
// @Security ApiKeyAuth
|
2023-03-30 16:47:47 +08:00
|
|
|
// @Router /apps/detail/:appId/:version/:type [get]
|
2022-09-23 16:33:55 +08:00
|
|
|
func (b *BaseApi) GetAppDetail(c *gin.Context) {
|
2023-09-26 22:50:16 +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
|
|
|
|
}
|
|
|
|
version := c.Param("version")
|
2023-03-30 16:47:47 +08:00
|
|
|
appType := c.Param("type")
|
2023-09-26 22:50:16 +08:00
|
|
|
appDetailDTO, err := appService.GetAppDetail(appID, version, appType)
|
2022-09-23 16:33:55 +08:00
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, appDetailDTO)
|
|
|
|
}
|
2022-09-26 16:32:40 +08:00
|
|
|
|
2023-04-03 17:47:23 +08:00
|
|
|
// @Tags App
|
2023-04-06 00:09:58 +08:00
|
|
|
// @Summary Get app detail by id
|
2023-04-03 17:47:23 +08:00
|
|
|
// @Description 通过 id 获取应用详情
|
|
|
|
// @Accept json
|
|
|
|
// @Param appId path integer true "id"
|
|
|
|
// @Success 200 {object} response.AppDetailDTO
|
|
|
|
// @Security ApiKeyAuth
|
2023-04-06 00:09:58 +08:00
|
|
|
// @Router /apps/details/:id [get]
|
2023-04-03 17:47:23 +08:00
|
|
|
func (b *BaseApi) GetAppDetailByID(c *gin.Context) {
|
|
|
|
appDetailID, err := helper.GetIntParamByKey(c, "id")
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInternalServer, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
appDetailDTO, err := appService.GetAppDetailByID(appDetailID)
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, appDetailDTO)
|
|
|
|
}
|
|
|
|
|
2023-07-06 18:48:22 +08:00
|
|
|
// @Tags App
|
|
|
|
// @Summary Get Ignore App
|
|
|
|
// @Description 获取忽略的应用版本
|
|
|
|
// @Accept json
|
|
|
|
// @Success 200 {object} response.IgnoredApp
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /apps/ingored [get]
|
|
|
|
func (b *BaseApi) GetIgnoredApp(c *gin.Context) {
|
|
|
|
res, err := appService.GetIgnoredApp()
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, res)
|
|
|
|
}
|
|
|
|
|
2023-01-05 11:57:03 +08: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]
|
2023-10-07 15:46:44 +08:00
|
|
|
// @x-panel-log {"bodyKeys":["name"],"paramKeys":[],"BeforeFunctions":[{"input_column":"name","input_value":"name","isList":false,"db":"app_installs","output_column":"app_id","output_value":"appId"},{"info":"appId","isList":false,"db":"apps","output_column":"key","output_value":"appKey"}],"formatZH":"安装应用 [appKey]-[name]","formatEN":"Install app [appKey]-[name]"}
|
2022-09-26 16:32:40 +08:00
|
|
|
func (b *BaseApi) InstallApp(c *gin.Context) {
|
2022-12-14 15:08:21 +08:00
|
|
|
var req request.AppInstallCreate
|
2023-10-27 12:04:11 +08:00
|
|
|
if err := helper.CheckBindAndValidate(&req, c); err != nil {
|
2022-09-26 16:32:40 +08:00
|
|
|
return
|
|
|
|
}
|
2022-12-22 15:26:25 +08:00
|
|
|
tx, ctx := helper.GetTxAndContext()
|
|
|
|
install, err := appService.Install(ctx, req)
|
2022-11-02 15:19:14 +08:00
|
|
|
if err != nil {
|
2022-12-22 15:26:25 +08:00
|
|
|
tx.Rollback()
|
2022-09-26 16:32:40 +08:00
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
2022-12-22 15:26:25 +08:00
|
|
|
tx.Commit()
|
2022-11-02 15:19:14 +08:00
|
|
|
helper.SuccessWithData(c, install)
|
2022-09-26 16:32:40 +08:00
|
|
|
}
|
2023-01-16 15:30:24 +08: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)
|
|
|
|
}
|
2023-03-14 13:54:42 +08:00
|
|
|
|
|
|
|
// @Tags App
|
|
|
|
// @Summary Get app list update
|
|
|
|
// @Description 获取应用更新版本
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /apps/checkupdate [get]
|
|
|
|
func (b *BaseApi) GetAppListUpdate(c *gin.Context) {
|
|
|
|
res, err := appService.GetAppUpdate()
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, res)
|
|
|
|
}
|