fix: Fix the recommended application display exception (#8148)

This commit is contained in:
ssongliu 2025-03-14 10:09:04 +08:00 committed by GitHub
parent 47d8c405dd
commit 1220a0c1ae
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 19 additions and 7 deletions

View file

@ -62,7 +62,7 @@ func (b *BaseApi) LoadAppLauncherOption(c *gin.Context) {
}
func (b *BaseApi) SyncAppLauncher(c *gin.Context) {
var req []dto.AppLauncherSync
var req dto.AppLauncherSync
if err := helper.CheckBindAndValidate(&req, c); err != nil {
return
}

View file

@ -101,7 +101,7 @@ type DashboardCurrent struct {
}
type AppLauncherSync struct {
Key string `json:"key"`
Keys []string `json:"keys"`
}
type DiskInfo struct {

View file

@ -31,7 +31,7 @@ import (
type DashboardService struct{}
type IDashboardService interface {
Sync(req []dto.AppLauncherSync) error
Sync(req dto.AppLauncherSync) error
LoadOsInfo() (*dto.OsInfo, error)
LoadBaseInfo(ioOption string, netOption string) (*dto.DashboardBase, error)
@ -47,10 +47,10 @@ func NewIDashboardService() IDashboardService {
return &DashboardService{}
}
func (u *DashboardService) Sync(req []dto.AppLauncherSync) error {
func (u *DashboardService) Sync(req dto.AppLauncherSync) error {
var launchers []model.AppLauncher
for _, item := range req {
launchers = append(launchers, model.AppLauncher{Key: item.Key})
for _, item := range req.Keys {
launchers = append(launchers, model.AppLauncher{Key: item})
}
return launcherRepo.SyncAll(launchers)
}

View file

@ -54,7 +54,19 @@ func (u *LauncherService) ChangeShow(req dto.SettingUpdate) error {
func syncLauncherToAgent() {
launchers, _ := launcherRepo.List()
itemData, _ := json.Marshal(launchers)
var list []string
launcherMap := make(map[string]struct{})
for _, item := range launchers {
if _, ok := launcherMap[item.Key]; ok {
continue
}
launcherMap[item.Key] = struct{}{}
list = append(list, item.Key)
}
launcherData := struct {
Keys []string
}{Keys: list}
itemData, _ := json.Marshal(launcherData)
_, _ = proxy_local.NewLocalClient("/api/v2/dashboard/app/launcher/sync", http.MethodPost, bytes.NewReader((itemData)))
_ = xpack.RequestToAllAgent("/api/v2/dashboard/app/launcher/sync", http.MethodPost, bytes.NewReader((itemData)))
}