Skip to content

Commit

Permalink
feat: filter app list in AppStore by CPU arch (#203)
Browse files Browse the repository at this point in the history
  • Loading branch information
CorrectRoadH authored Aug 15, 2024
1 parent b0b2c3b commit 111f568
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/utils/cpu.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package utils

import "runtime"

func GetCPUArch() string {
return runtime.GOARCH
}
21 changes: 21 additions & 0 deletions route/v2/appstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"github.com/samber/lo"
"go.uber.org/zap"
"gopkg.in/yaml.v3"

pkg_utils "github.com/IceWhaleTech/CasaOS-AppManagement/pkg/utils"
)

func (a *AppManagement) AppStoreList(ctx echo.Context) error {
Expand Down Expand Up @@ -113,6 +115,7 @@ func (a *AppManagement) UnregisterAppStore(ctx echo.Context, id codegen.AppStore
}

func (a *AppManagement) ComposeAppStoreInfoList(ctx echo.Context, params codegen.ComposeAppStoreInfoListParams) error {

catalog, err := service.MyService.AppStoreManagement().Catalog()
if err != nil {
message := err.Error()
Expand Down Expand Up @@ -141,6 +144,24 @@ func (a *AppManagement) ComposeAppStoreInfoList(ctx echo.Context, params codegen
catalog = FilterCatalogByAppStoreID(catalog, recommendedList)
}

cpuArch := pkg_utils.GetCPUArch()

// Filter applications based on CPU architecture
catalog = lo.PickBy(catalog, func(appStoreID string, composeApp *service.ComposeApp) bool {
storeInfo, err := composeApp.StoreInfo(true)
if err != nil {
logger.Error("Failed to get app store information", zap.Error(err), zap.String("appStoreID", appStoreID))
return false
}

// If architecture information is empty, assume it supports all architectures
if storeInfo.Architectures == nil {
return true
}
// Check if the application supports the current CPU architecture
return lo.Contains(*storeInfo.Architectures, cpuArch)
})

// list
list := lo.MapValues(catalog, func(composeApp *service.ComposeApp, appStoreID string) codegen.ComposeAppStoreInfo {
storeInfo, err := composeApp.StoreInfo(true)
Expand Down

0 comments on commit 111f568

Please sign in to comment.