MCPcopy Create free account
hub / github.com/AandStep/ResultV / RefreshSubscription

Method RefreshSubscription

app.go:2260–2340  ·  view source on GitHub ↗
(subID string)

Source from the content-addressed store, hash-verified

2258}
2259
2260func (a *App) RefreshSubscription(subID string) ([]config.ProxyEntry, error) {
2261 if a.config == nil {
2262 return nil, fmt.Errorf("config manager not initialized")
2263 }
2264
2265 cfg := a.config.GetConfig()
2266 var sub *config.Subscription
2267 for i := range cfg.Subscriptions {
2268 if cfg.Subscriptions[i].ID == subID {
2269 sub = &cfg.Subscriptions[i]
2270 break
2271 }
2272 }
2273 if sub == nil {
2274 return nil, fmt.Errorf("subscription %s not found", subID)
2275 }
2276
2277 // Replay the consent the user gave when adding this subscription. If
2278 // they accepted plaintext at AddSubscription time, refresh keeps using
2279 // http; if not, an http URL refresh will fail with ErrInsecureSubscription
2280 // and the UI must re-prompt before retrying.
2281 entries, up, down, tot, exp, iconURL, profileTitle, err := a.fetchSubscriptionFromURL(sub.URL, sub.AllowInsecure)
2282 if err != nil {
2283 return nil, fmt.Errorf("refreshing subscription %s: %w", sub.Name, err)
2284 }
2285
2286 displayName := sub.Name
2287 if profileTitle != "" {
2288 displayName = profileTitle
2289 }
2290 for i := range entries {
2291 entries[i].Provider = displayName
2292 entries[i].SubscriptionURL = sub.URL
2293 }
2294
2295 for i := range cfg.Subscriptions {
2296 if cfg.Subscriptions[i].ID == subID {
2297 cfg.Subscriptions[i].UpdatedAt = time.Now().Format(time.RFC3339)
2298 cfg.Subscriptions[i].TrafficUpload = up
2299 cfg.Subscriptions[i].TrafficDownload = down
2300 cfg.Subscriptions[i].TrafficTotal = tot
2301 cfg.Subscriptions[i].ExpireUnix = exp
2302 if profileTitle != "" {
2303 cfg.Subscriptions[i].Name = profileTitle
2304 }
2305 if iconURL != "" {
2306 cfg.Subscriptions[i].IconURL = iconURL
2307 }
2308 break
2309 }
2310 }
2311 if err := a.config.SaveConfig(cfg); err != nil {
2312 a.log.Error(fmt.Sprintf("Ошибка сохранения после обновления подписки: %v", err))
2313 }
2314
2315 visibleCount := len(entries)
2316 memberIDs := make(map[string]bool)
2317 for _, e := range entries {

Callers

nothing calls this directly

Calls 5

ErrorMethod · 0.80
SuccessMethod · 0.80
GetConfigMethod · 0.45
SaveConfigMethod · 0.45

Tested by

no test coverage detected