mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-03-16 18:54:43 +08:00
feat: 系统启动增加同步已安装应用步骤 (#295)
Co-authored-by: zhengkunwang223 <zhengkun@fit2cloud.com>
This commit is contained in:
parent
e8582bea75
commit
89b7a06662
@ -144,7 +144,7 @@ func (b *BaseApi) DeleteCheck(c *gin.Context) {
|
|||||||
// @Router /apps/installed/sync [post]
|
// @Router /apps/installed/sync [post]
|
||||||
// @x-panel-log {"bodyKeys":[],"paramKeys":[],"BeforeFuntions":[],"formatZH":"同步已安装应用列表","formatEN":"Sync the list of installed apps"}
|
// @x-panel-log {"bodyKeys":[],"paramKeys":[],"BeforeFuntions":[],"formatZH":"同步已安装应用列表","formatEN":"Sync the list of installed apps"}
|
||||||
func (b *BaseApi) SyncInstalled(c *gin.Context) {
|
func (b *BaseApi) SyncInstalled(c *gin.Context) {
|
||||||
if err := appInstallService.SyncAll(); err != nil {
|
if err := appInstallService.SyncAll(false); err != nil {
|
||||||
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,28 @@ import (
|
|||||||
type AppInstallService struct {
|
type AppInstallService struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a AppInstallService) Page(req request.AppInstalledSearch) (int64, []response.AppInstalledDTO, error) {
|
type IAppInstallService interface {
|
||||||
|
Page(req request.AppInstalledSearch) (int64, []response.AppInstalledDTO, error)
|
||||||
|
CheckExist(key string) (*response.AppInstalledCheck, error)
|
||||||
|
LoadPort(key string) (int64, error)
|
||||||
|
LoadPassword(key string) (string, error)
|
||||||
|
SearchForWebsite(req request.AppInstalledSearch) ([]response.AppInstalledDTO, error)
|
||||||
|
Operate(req request.AppInstalledOperate) error
|
||||||
|
Update(req request.AppInstalledUpdate) error
|
||||||
|
SyncAll(systemInit bool) error
|
||||||
|
GetServices(key string) ([]response.AppService, error)
|
||||||
|
GetUpdateVersions(installId uint) ([]dto.AppVersion, error)
|
||||||
|
GetParams(id uint) ([]response.AppParam, error)
|
||||||
|
ChangeAppPort(req request.PortUpdate) error
|
||||||
|
GetDefaultConfigByKey(key string) (string, error)
|
||||||
|
DeleteCheck(installId uint) ([]dto.AppResource, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewIAppInstalledService() IAppInstallService {
|
||||||
|
return &AppInstallService{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *AppInstallService) Page(req request.AppInstalledSearch) (int64, []response.AppInstalledDTO, error) {
|
||||||
var opts []repo.DBOption
|
var opts []repo.DBOption
|
||||||
|
|
||||||
if req.Name != "" {
|
if req.Name != "" {
|
||||||
@ -73,7 +94,7 @@ func (a AppInstallService) Page(req request.AppInstalledSearch) (int64, []respon
|
|||||||
return total, installDTOs, nil
|
return total, installDTOs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a AppInstallService) CheckExist(key string) (*response.AppInstalledCheck, error) {
|
func (a *AppInstallService) CheckExist(key string) (*response.AppInstalledCheck, error) {
|
||||||
res := &response.AppInstalledCheck{
|
res := &response.AppInstalledCheck{
|
||||||
IsExist: false,
|
IsExist: false,
|
||||||
}
|
}
|
||||||
@ -103,7 +124,7 @@ func (a AppInstallService) CheckExist(key string) (*response.AppInstalledCheck,
|
|||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a AppInstallService) LoadPort(key string) (int64, error) {
|
func (a *AppInstallService) LoadPort(key string) (int64, error) {
|
||||||
app, err := appInstallRepo.LoadBaseInfo(key, "")
|
app, err := appInstallRepo.LoadBaseInfo(key, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return int64(0), nil
|
return int64(0), nil
|
||||||
@ -111,7 +132,7 @@ func (a AppInstallService) LoadPort(key string) (int64, error) {
|
|||||||
return app.Port, nil
|
return app.Port, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a AppInstallService) LoadPassword(key string) (string, error) {
|
func (a *AppInstallService) LoadPassword(key string) (string, error) {
|
||||||
app, err := appInstallRepo.LoadBaseInfo(key, "")
|
app, err := appInstallRepo.LoadBaseInfo(key, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", nil
|
return "", nil
|
||||||
@ -119,7 +140,7 @@ func (a AppInstallService) LoadPassword(key string) (string, error) {
|
|||||||
return app.Password, nil
|
return app.Password, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a AppInstallService) SearchForWebsite(req request.AppInstalledSearch) ([]response.AppInstalledDTO, error) {
|
func (a *AppInstallService) SearchForWebsite(req request.AppInstalledSearch) ([]response.AppInstalledDTO, error) {
|
||||||
var (
|
var (
|
||||||
installs []model.AppInstall
|
installs []model.AppInstall
|
||||||
err error
|
err error
|
||||||
@ -152,7 +173,7 @@ func (a AppInstallService) SearchForWebsite(req request.AppInstalledSearch) ([]r
|
|||||||
return handleInstalled(installs, false)
|
return handleInstalled(installs, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a AppInstallService) Operate(req request.AppInstalledOperate) error {
|
func (a *AppInstallService) Operate(req request.AppInstalledOperate) error {
|
||||||
install, err := appInstallRepo.GetFirst(commonRepo.WithByID(req.InstallId))
|
install, err := appInstallRepo.GetFirst(commonRepo.WithByID(req.InstallId))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -196,7 +217,7 @@ func (a AppInstallService) Operate(req request.AppInstalledOperate) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a AppInstallService) Update(req request.AppInstalledUpdate) error {
|
func (a *AppInstallService) Update(req request.AppInstalledUpdate) error {
|
||||||
installed, err := appInstallRepo.GetFirst(commonRepo.WithByID(req.InstallId))
|
installed, err := appInstallRepo.GetFirst(commonRepo.WithByID(req.InstallId))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -270,13 +291,18 @@ func (a AppInstallService) Update(req request.AppInstalledUpdate) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a AppInstallService) SyncAll() error {
|
func (a *AppInstallService) SyncAll(systemInit bool) error {
|
||||||
allList, err := appInstallRepo.ListBy()
|
allList, err := appInstallRepo.ListBy()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, i := range allList {
|
for _, i := range allList {
|
||||||
if i.Status == constant.Installing {
|
if i.Status == constant.Installing {
|
||||||
|
if systemInit {
|
||||||
|
i.Status = constant.Error
|
||||||
|
i.Message = "System restart causes application exception"
|
||||||
|
_ = appInstallRepo.Save(&i)
|
||||||
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if err := syncById(i.ID); err != nil {
|
if err := syncById(i.ID); err != nil {
|
||||||
@ -286,7 +312,7 @@ func (a AppInstallService) SyncAll() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a AppInstallService) GetServices(key string) ([]response.AppService, error) {
|
func (a *AppInstallService) GetServices(key string) ([]response.AppService, error) {
|
||||||
app, err := appRepo.GetFirst(appRepo.WithKey(key))
|
app, err := appRepo.GetFirst(appRepo.WithKey(key))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -310,7 +336,7 @@ func (a AppInstallService) GetServices(key string) ([]response.AppService, error
|
|||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a AppInstallService) GetUpdateVersions(installId uint) ([]dto.AppVersion, error) {
|
func (a *AppInstallService) GetUpdateVersions(installId uint) ([]dto.AppVersion, error) {
|
||||||
install, err := appInstallRepo.GetFirst(commonRepo.WithByID(installId))
|
install, err := appInstallRepo.GetFirst(commonRepo.WithByID(installId))
|
||||||
var versions []dto.AppVersion
|
var versions []dto.AppVersion
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -335,7 +361,7 @@ func (a AppInstallService) GetUpdateVersions(installId uint) ([]dto.AppVersion,
|
|||||||
return versions, nil
|
return versions, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a AppInstallService) ChangeAppPort(req request.PortUpdate) error {
|
func (a *AppInstallService) ChangeAppPort(req request.PortUpdate) error {
|
||||||
if common.ScanPort(int(req.Port)) {
|
if common.ScanPort(int(req.Port)) {
|
||||||
return buserr.WithDetail(constant.ErrPortInUsed, req.Port, nil)
|
return buserr.WithDetail(constant.ErrPortInUsed, req.Port, nil)
|
||||||
}
|
}
|
||||||
@ -363,7 +389,7 @@ func (a AppInstallService) ChangeAppPort(req request.PortUpdate) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a AppInstallService) DeleteCheck(installId uint) ([]dto.AppResource, error) {
|
func (a *AppInstallService) DeleteCheck(installId uint) ([]dto.AppResource, error) {
|
||||||
var res []dto.AppResource
|
var res []dto.AppResource
|
||||||
appInstall, err := appInstallRepo.GetFirst(commonRepo.WithByID(installId))
|
appInstall, err := appInstallRepo.GetFirst(commonRepo.WithByID(installId))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -404,7 +430,7 @@ func (a AppInstallService) DeleteCheck(installId uint) ([]dto.AppResource, error
|
|||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a AppInstallService) GetDefaultConfigByKey(key string) (string, error) {
|
func (a *AppInstallService) GetDefaultConfigByKey(key string) (string, error) {
|
||||||
appInstall, err := getAppInstallByKey(key)
|
appInstall, err := getAppInstallByKey(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
@ -426,7 +452,7 @@ func (a AppInstallService) GetDefaultConfigByKey(key string) (string, error) {
|
|||||||
return string(contentByte), nil
|
return string(contentByte), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a AppInstallService) GetParams(id uint) ([]response.AppParam, error) {
|
func (a *AppInstallService) GetParams(id uint) ([]response.AppParam, error) {
|
||||||
var (
|
var (
|
||||||
res []response.AppParam
|
res []response.AppParam
|
||||||
appForm dto.AppForm
|
appForm dto.AppForm
|
||||||
|
@ -11,35 +11,35 @@ import (
|
|||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetMsgWithMap(msg string, maps map[string]interface{}) string {
|
func GetMsgWithMap(key string, maps map[string]interface{}) string {
|
||||||
content := ""
|
content := ""
|
||||||
if maps == nil {
|
if maps == nil {
|
||||||
content = ginI18n.MustGetMessage(&i18n.LocalizeConfig{
|
content = ginI18n.MustGetMessage(&i18n.LocalizeConfig{
|
||||||
MessageID: msg,
|
MessageID: key,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
content = ginI18n.MustGetMessage(&i18n.LocalizeConfig{
|
content = ginI18n.MustGetMessage(&i18n.LocalizeConfig{
|
||||||
MessageID: msg,
|
MessageID: key,
|
||||||
TemplateData: maps,
|
TemplateData: maps,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
content = strings.ReplaceAll(content, ": <no value>", "")
|
content = strings.ReplaceAll(content, ": <no value>", "")
|
||||||
if content == "" {
|
if content == "" {
|
||||||
return msg
|
return key
|
||||||
} else {
|
} else {
|
||||||
return content
|
return content
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetErrMsg(msg string, maps map[string]interface{}) string {
|
func GetErrMsg(key string, maps map[string]interface{}) string {
|
||||||
content := ""
|
content := ""
|
||||||
if maps == nil {
|
if maps == nil {
|
||||||
content = ginI18n.MustGetMessage(&i18n.LocalizeConfig{
|
content = ginI18n.MustGetMessage(&i18n.LocalizeConfig{
|
||||||
MessageID: msg,
|
MessageID: key,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
content = ginI18n.MustGetMessage(&i18n.LocalizeConfig{
|
content = ginI18n.MustGetMessage(&i18n.LocalizeConfig{
|
||||||
MessageID: msg,
|
MessageID: key,
|
||||||
TemplateData: maps,
|
TemplateData: maps,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -6,18 +6,30 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func Init() {
|
func Init() {
|
||||||
|
syncApp()
|
||||||
|
syncInstalledApp()
|
||||||
|
}
|
||||||
|
|
||||||
|
func syncApp() {
|
||||||
setting, err := service.NewISettingService().GetSettingInfo()
|
setting, err := service.NewISettingService().GetSettingInfo()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
global.LOG.Errorf("sync app error: %s", err.Error())
|
global.LOG.Errorf("sync app error: %s", err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if setting.AppStoreVersion != "" {
|
if setting.AppStoreVersion != "" {
|
||||||
global.LOG.Info("do not sync")
|
global.LOG.Info("no need to sync")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
global.LOG.Info("sync app start...")
|
global.LOG.Info("sync app start...")
|
||||||
if err := service.NewIAppService().SyncAppList(); err != nil {
|
if err := service.NewIAppService().SyncAppList(); err != nil {
|
||||||
global.LOG.Errorf("sync app error: %s", err.Error())
|
global.LOG.Errorf("sync app error: %s", err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
global.LOG.Info("sync app successful")
|
||||||
|
}
|
||||||
|
|
||||||
|
func syncInstalledApp() {
|
||||||
|
if err := service.NewIAppInstalledService().SyncAll(true); err != nil {
|
||||||
|
global.LOG.Errorf("sync instaled app error: %s", err.Error())
|
||||||
}
|
}
|
||||||
global.LOG.Info("sync app success")
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user