(sharedCtx **appSyncContext)
| 38 | } |
| 39 | |
| 40 | func (a AppService) createSyncAppStoreTask(sharedCtx **appSyncContext) func(t *task.Task) error { |
| 41 | return func(t *task.Task) (err error) { |
| 42 | t.LogStart(i18n.GetMsgByKey("AppStore") + " " + i18n.GetMsgByKey("TaskSync")) |
| 43 | |
| 44 | updateRes, err := a.GetAppUpdate() |
| 45 | if err != nil { |
| 46 | t.LogFailedWithErr(i18n.GetMsgByKey("CheckAppStoreUpdate"), err) |
| 47 | return err |
| 48 | } |
| 49 | if !updateRes.CanUpdate { |
| 50 | if updateRes.IsSyncing { |
| 51 | t.Log(i18n.GetMsgByKey("AppStoreIsSyncing")) |
| 52 | return nil |
| 53 | } |
| 54 | global.LOG.Infof("[AppStore] Appstore is up to date") |
| 55 | t.Log(i18n.GetMsgByKey("AppStoreIsUpToDate")) |
| 56 | *sharedCtx = &appSyncContext{skipMetaSync: true} |
| 57 | t.LogSuccess(i18n.GetMsgByKey("AppStore") + " " + i18n.GetMsgByKey("TaskSync")) |
| 58 | return nil |
| 59 | } |
| 60 | |
| 61 | list := &dto.AppList{} |
| 62 | if updateRes.AppList == nil { |
| 63 | list, err = getAppList() |
| 64 | if err != nil { |
| 65 | t.LogFailedWithErr(i18n.GetMsgByKey("DownloadAppList"), err) |
| 66 | return err |
| 67 | } |
| 68 | } else { |
| 69 | list = updateRes.AppList |
| 70 | } |
| 71 | |
| 72 | settingService := NewISettingService() |
| 73 | if err := settingService.Update("AppStoreSyncStatus", constant.StatusSyncing); err != nil { |
| 74 | global.LOG.Warnf("[AppStore] failed to update sync status to syncing: %v", err) |
| 75 | } |
| 76 | |
| 77 | setting, err := settingService.GetSettingInfo() |
| 78 | if err != nil { |
| 79 | t.LogFailedWithErr("GetSettingInfo", err) |
| 80 | return err |
| 81 | } |
| 82 | |
| 83 | ctx := &appSyncContext{ |
| 84 | task: t, |
| 85 | httpClient: http.Client{Timeout: time.Duration(constant.TimeOut20s) * time.Second, Transport: xpack.MultiNodeProvider.LoadRequestTransport()}, |
| 86 | baseRemoteUrl: fmt.Sprintf("%s/%s/1panel", global.AppRepoURL(), global.CONF.Base.Mode), |
| 87 | systemVersion: setting.SystemVersion, |
| 88 | settingService: settingService, |
| 89 | list: list, |
| 90 | appTags: make([]*model.AppTag, 0), |
| 91 | pendingIcons: make(map[string]string), |
| 92 | } |
| 93 | |
| 94 | if err = SyncTags(list.Extra); err != nil { |
| 95 | t.LogFailedWithErr(i18n.GetMsgByKey("SyncTags"), err) |
| 96 | return err |
| 97 | } |
no test coverage detected