fix SiteDeleted

This commit is contained in:
jxxghp 2024-03-27 07:09:00 +08:00
parent fa03232321
commit 2df113ad38
3 changed files with 36 additions and 6 deletions

View File

@ -130,7 +130,7 @@ def reset(db: Session = Depends(get_db),
# 插件站点删除 # 插件站点删除
EventManager().send_event(EventType.SiteDeleted, EventManager().send_event(EventType.SiteDeleted,
{ {
"site_id": None "site_id": "*"
}) })
return schemas.Response(success=True, message="站点已重置!") return schemas.Response(success=True, message="站点已重置!")

View File

@ -9,6 +9,7 @@ from typing import List, Optional
from app.chain import ChainBase from app.chain import ChainBase
from app.core.context import Context from app.core.context import Context
from app.core.context import MediaInfo, TorrentInfo from app.core.context import MediaInfo, TorrentInfo
from app.core.event import eventmanager, Event
from app.core.metainfo import MetaInfo from app.core.metainfo import MetaInfo
from app.db.systemconfig_oper import SystemConfigOper from app.db.systemconfig_oper import SystemConfigOper
from app.helper.progress import ProgressHelper from app.helper.progress import ProgressHelper
@ -16,7 +17,7 @@ from app.helper.sites import SitesHelper
from app.helper.torrent import TorrentHelper from app.helper.torrent import TorrentHelper
from app.log import logger from app.log import logger
from app.schemas import NotExistMediaInfo from app.schemas import NotExistMediaInfo
from app.schemas.types import MediaType, ProgressKey, SystemConfigKey from app.schemas.types import MediaType, ProgressKey, SystemConfigKey, EventType
from app.utils.string import StringUtils from app.utils.string import StringUtils
@ -384,3 +385,24 @@ class SearchChain(ChainBase):
), ),
torrents torrents
)) ))
@eventmanager.register(EventType.SiteDeleted)
def remove_site(self, event: Event):
"""
从搜索站点中移除与已删除站点相关的设置
"""
if not event:
return
event_data = event.event_data or {}
site_id = event_data.get("site_id")
if not site_id:
return
if site_id == "*":
# 清空搜索站点
SystemConfigOper().set(SystemConfigKey.IndexerSites, [])
return
# 从选中的rss站点中移除
selected_sites = SystemConfigOper().get(SystemConfigKey.IndexerSites) or []
if site_id in selected_sites:
selected_sites.remove(site_id)
SystemConfigOper().set(SystemConfigKey.IndexerSites, selected_sites)

View File

@ -969,21 +969,29 @@ class SubscribeChain(ChainBase):
site_id = event_data.get("site_id") site_id = event_data.get("site_id")
if not site_id: if not site_id:
return return
if site_id == "*":
# 站点被重置
SystemConfigOper().set(SystemConfigKey.RssSites, [])
for subscribe in self.subscribeoper.list():
if not subscribe.sites:
continue
self.subscribeoper.update(subscribe.id, {
"sites": ""
})
return
# 从选中的rss站点中移除 # 从选中的rss站点中移除
selected_sites = SystemConfigOper().get(SystemConfigKey.RssSites) or [] selected_sites = SystemConfigOper().get(SystemConfigKey.RssSites) or []
if site_id in selected_sites: if site_id in selected_sites:
selected_sites.remove(site_id) selected_sites.remove(site_id)
SystemConfigOper().set(SystemConfigKey.RssSites, selected_sites) SystemConfigOper().set(SystemConfigKey.RssSites, selected_sites)
# 查询所有订阅 # 查询所有订阅
subscribes = self.subscribeoper.list() for subscribe in self.subscribeoper.list():
for subscribe in subscribes:
if not subscribe.sites: if not subscribe.sites:
continue continue
sites = json.loads(subscribe.sites) or [] sites = json.loads(subscribe.sites) or []
if site_id not in sites: if site_id not in sites:
continue continue
sites.remove(site_id) sites.remove(site_id)
sites = json.dumps(sites)
self.subscribeoper.update(subscribe.id, { self.subscribeoper.update(subscribe.id, {
"sites": sites "sites": json.dumps(sites)
}) })