@@ -12,6 +12,7 @@ import (
1212 "reflect"
1313 "strconv"
1414 "strings"
15+ "sync"
1516
1617 "github.com/gin-gonic/gin"
1718
@@ -34,6 +35,11 @@ import (
3435 "gopkg.in/yaml.v3"
3536)
3637
38+ var (
39+ appStoreSyncMu sync.Mutex
40+ appStoreSyncing bool
41+ )
42+
3743type AppService struct {
3844}
3945
@@ -840,6 +846,13 @@ func (a AppService) GetAppUpdate() (*response.AppUpdateRes, error) {
840846 res .CanUpdate = true
841847 return res , err
842848 }
849+ if appicon .IsIconFile (app .Icon ) {
850+ fileName , _ := appicon .ParseIconField (app .Icon )
851+ if fileName == "" || ! appicon .IconFileExists (fileName ) {
852+ res .CanUpdate = true
853+ return res , err
854+ }
855+ }
843856 }
844857
845858 list , err := getAppList ()
@@ -897,33 +910,61 @@ var InitTypes = map[string]struct{}{
897910}
898911
899912func deleteCustomApp () {
913+ installs , err := appInstallRepo .ListBy (context .Background ())
914+ if err != nil {
915+ global .LOG .Errorf ("[AppStore] deleteCustomApp: failed to list installs, skipping: %v" , err )
916+ return
917+ }
900918 var appIDS []uint
901- installs , _ := appInstallRepo .ListBy (context .Background ())
902919 for _ , install := range installs {
903920 appIDS = append (appIDS , install .AppId )
904921 }
905922 var ops []repo.DBOption
906- ops = append (ops , repo .WithByIDNotIn (appIDS ))
907923 if len (appIDS ) > 0 {
908924 ops = append (ops , repo .WithByIDNotIn (appIDS ))
909925 }
910- apps , _ := appRepo .GetBy (ops ... )
926+ apps , err := appRepo .GetBy (ops ... )
927+ if err != nil {
928+ global .LOG .Errorf ("[AppStore] deleteCustomApp: failed to get apps, skipping: %v" , err )
929+ return
930+ }
911931 var deleteIDS []uint
912932 for _ , app := range apps {
913933 if app .Resource == constant .AppResourceCustom {
914934 deleteIDS = append (deleteIDS , app .ID )
915935 }
916936 }
917- _ = appRepo .DeleteByIDs (context .Background (), deleteIDS )
918- _ = appDetailRepo .DeleteByAppIds (context .Background (), deleteIDS )
937+ if len (deleteIDS ) == 0 {
938+ return
939+ }
940+ if err = appRepo .DeleteByIDs (context .Background (), deleteIDS ); err != nil {
941+ global .LOG .Errorf ("[AppStore] deleteCustomApp: failed to delete apps: %v" , err )
942+ }
943+ if err = appDetailRepo .DeleteByAppIds (context .Background (), deleteIDS ); err != nil {
944+ global .LOG .Errorf ("[AppStore] deleteCustomApp: failed to delete app details: %v" , err )
945+ }
919946}
920947
921948func (a AppService ) SyncAppListFromRemote (taskID string ) (err error ) {
922949 if xpack .IsUseCustomApp () {
923950 return nil
924951 }
952+
953+ appStoreSyncMu .Lock ()
954+ global .LOG .Info ("[AppStore] sync app from remote task create start" )
955+ if appStoreSyncing {
956+ appStoreSyncMu .Unlock ()
957+ global .LOG .Info ("[AppStore] sync already in progress, skipping" )
958+ return nil
959+ }
960+ appStoreSyncing = true
961+ appStoreSyncMu .Unlock ()
962+
925963 syncTask , err := task .NewTaskWithOps (i18n .GetMsgByKey ("App" ), task .TaskSync , task .TaskScopeAppStore , taskID , 0 )
926964 if err != nil {
965+ appStoreSyncMu .Lock ()
966+ appStoreSyncing = false
967+ appStoreSyncMu .Unlock ()
927968 return err
928969 }
929970
@@ -933,13 +974,29 @@ func (a AppService) SyncAppListFromRemote(taskID string) (err error) {
933974 syncTask .AddSubTask (i18n .GetMsgByKey ("SyncAppDetail" ), a .createSyncAppStoreMetaTask (& sharedCtx ), nil )
934975
935976 go func () {
977+ defer func () {
978+ if r := recover (); r != nil {
979+ global .LOG .Errorf ("[AppStore] sync goroutine recovered from panic: %v" , r )
980+ if updateErr := NewISettingService ().Update ("AppStoreSyncStatus" , constant .StatusError ); updateErr != nil {
981+ global .LOG .Warnf ("[AppStore] failed to update sync status after panic: %v" , updateErr )
982+ }
983+ }
984+ appStoreSyncMu .Lock ()
985+ appStoreSyncing = false
986+ appStoreSyncMu .Unlock ()
987+ }()
936988 if err := syncTask .Execute (); err != nil {
937- _ = NewISettingService ().Update ("AppStoreLastModified" , "0" )
938- _ = NewISettingService ().Update ("AppStoreSyncStatus" , constant .StatusError )
989+ if updateErr := NewISettingService ().Update ("AppStoreLastModified" , "0" ); updateErr != nil {
990+ global .LOG .Warnf ("[AppStore] failed to reset last modified: %v" , updateErr )
991+ }
992+ if updateErr := NewISettingService ().Update ("AppStoreSyncStatus" , constant .StatusError ); updateErr != nil {
993+ global .LOG .Warnf ("[AppStore] failed to update sync status to error: %v" , updateErr )
994+ }
939995 return
940996 }
941997 }()
942998
999+ global .LOG .Info ("[AppStore] sync app from remote task create ok" )
9431000 return nil
9441001}
9451002
0 commit comments