mirror of
https://github.com/truewhile/MeBox.git
synced 2026-10-08 06:16:37 +08:00
Update MediaStationGo branding and deployment docs
This commit is contained in:
@@ -34,6 +34,7 @@ type SubscriptionService struct {
|
||||
site *SiteService
|
||||
scraper *ScraperService
|
||||
hub *Hub
|
||||
notify *NotifyChannelService
|
||||
stop chan struct{}
|
||||
}
|
||||
|
||||
@@ -54,6 +55,10 @@ func (s *SubscriptionService) SetScraper(scraper *ScraperService) {
|
||||
s.scraper = scraper
|
||||
}
|
||||
|
||||
func (s *SubscriptionService) SetNotifyChannels(notify *NotifyChannelService) {
|
||||
s.notify = notify
|
||||
}
|
||||
|
||||
// Start runs the polling loop in the background.
|
||||
func (s *SubscriptionService) Start(ctx context.Context) {
|
||||
go s.loop(ctx)
|
||||
@@ -272,6 +277,7 @@ func (s *SubscriptionService) runOne(ctx context.Context, sub *model.Subscriptio
|
||||
"name": sub.Name,
|
||||
"queued": queued,
|
||||
})
|
||||
s.notifySubscriptionHit(sub, queued, nil)
|
||||
}
|
||||
return queued, nil
|
||||
}
|
||||
@@ -377,6 +383,7 @@ func (s *SubscriptionService) runSiteSearch(ctx context.Context, sub *model.Subs
|
||||
"keyword": keyword,
|
||||
"resources": resources,
|
||||
})
|
||||
s.notifySubscriptionHit(sub, queued, resources)
|
||||
return queued, nil
|
||||
}
|
||||
if lastEnqueueErr != nil {
|
||||
@@ -385,6 +392,21 @@ func (s *SubscriptionService) runSiteSearch(ctx context.Context, sub *model.Subs
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
func (s *SubscriptionService) notifySubscriptionHit(sub *model.Subscription, queued int, resources []string) {
|
||||
if s == nil || s.notify == nil || sub == nil || queued <= 0 {
|
||||
return
|
||||
}
|
||||
body := fmt.Sprintf("订阅:%s\n新增资源:%d", sub.Name, queued)
|
||||
if len(resources) > 0 {
|
||||
body += "\n资源:\n- " + strings.Join(resources, "\n- ")
|
||||
}
|
||||
go func() {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
defer cancel()
|
||||
s.notify.Broadcast(ctx, "MediaStationGo 订阅命中新资源", body, EventSubscriptionHit)
|
||||
}()
|
||||
}
|
||||
|
||||
func (s *SubscriptionService) archiveCompletedSubscription(ctx context.Context, sub *model.Subscription, availability LocalAvailability) error {
|
||||
if s == nil || s.repo == nil || s.repo.Subscription == nil || sub == nil {
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user