fix #204
This commit is contained in:
parent
4135df693c
commit
6337a72b0f
@ -8,13 +8,14 @@ from app import schemas
|
|||||||
from app.chain.cookiecloud import CookieCloudChain
|
from app.chain.cookiecloud import CookieCloudChain
|
||||||
from app.chain.search import SearchChain
|
from app.chain.search import SearchChain
|
||||||
from app.chain.site import SiteChain
|
from app.chain.site import SiteChain
|
||||||
|
from app.core.event import EventManager
|
||||||
from app.core.security import verify_token
|
from app.core.security import verify_token
|
||||||
from app.db import get_db
|
from app.db import get_db
|
||||||
from app.db.models.site import Site
|
from app.db.models.site import Site
|
||||||
from app.db.models.siteicon import SiteIcon
|
from app.db.models.siteicon import SiteIcon
|
||||||
from app.db.systemconfig_oper import SystemConfigOper
|
from app.db.systemconfig_oper import SystemConfigOper
|
||||||
from app.helper.sites import SitesHelper
|
from app.helper.sites import SitesHelper
|
||||||
from app.schemas.types import SystemConfigKey
|
from app.schemas.types import SystemConfigKey, EventType
|
||||||
from app.utils.string import StringUtils
|
from app.utils.string import StringUtils
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
@ -90,6 +91,12 @@ def delete_site(
|
|||||||
删除站点
|
删除站点
|
||||||
"""
|
"""
|
||||||
Site.delete(db, site_id)
|
Site.delete(db, site_id)
|
||||||
|
# 插件站点删除
|
||||||
|
EventManager().send_event(EventType.SiteDeleted,
|
||||||
|
{
|
||||||
|
"plugin_id": ['AutoSignIn', 'SiteStatistic'],
|
||||||
|
"site_id": site_id
|
||||||
|
})
|
||||||
return schemas.Response(success=True)
|
return schemas.Response(success=True)
|
||||||
|
|
||||||
|
|
||||||
@ -113,6 +120,12 @@ def cookie_cloud_sync(db: Session = Depends(get_db),
|
|||||||
Site.reset(db)
|
Site.reset(db)
|
||||||
SystemConfigOper(db).set(SystemConfigKey.IndexerSites, [])
|
SystemConfigOper(db).set(SystemConfigKey.IndexerSites, [])
|
||||||
CookieCloudChain(db).process(manual=True)
|
CookieCloudChain(db).process(manual=True)
|
||||||
|
# 插件站点删除
|
||||||
|
EventManager().send_event(EventType.SiteDeleted,
|
||||||
|
{
|
||||||
|
"plugin_id": ['AutoSignIn', 'SiteStatistic'],
|
||||||
|
"site_id": None
|
||||||
|
})
|
||||||
return schemas.Response(success=True, message="站点已重置!")
|
return schemas.Response(success=True, message="站点已重置!")
|
||||||
|
|
||||||
|
|
||||||
|
@ -571,3 +571,44 @@ class AutoSignIn(_PluginBase):
|
|||||||
self._scheduler = None
|
self._scheduler = None
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error("退出插件失败:%s" % str(e))
|
logger.error("退出插件失败:%s" % str(e))
|
||||||
|
|
||||||
|
@eventmanager.register(EventType.SiteDeleted)
|
||||||
|
def site_deleted(self, event):
|
||||||
|
"""
|
||||||
|
删除对应站点选中
|
||||||
|
"""
|
||||||
|
plugin_id = event.event_data.get("plugin_id")
|
||||||
|
site_id = event.event_data.get("site_id")
|
||||||
|
if not plugin_id:
|
||||||
|
return
|
||||||
|
if self.__class__.__name__ not in plugin_id:
|
||||||
|
return
|
||||||
|
config = self.get_config()
|
||||||
|
if config:
|
||||||
|
sign_sites = config.get("sign_sites")
|
||||||
|
if sign_sites:
|
||||||
|
if isinstance(sign_sites, str):
|
||||||
|
sign_sites = [sign_sites]
|
||||||
|
|
||||||
|
# 删除对应站点
|
||||||
|
if site_id:
|
||||||
|
sign_sites = [site for site in sign_sites if int(site) != int(site_id)]
|
||||||
|
else:
|
||||||
|
# 清空
|
||||||
|
sign_sites = []
|
||||||
|
|
||||||
|
# 若无站点,则停止
|
||||||
|
if len(sign_sites) == 0:
|
||||||
|
self._enabled = False
|
||||||
|
|
||||||
|
# 保存配置
|
||||||
|
self.update_config(
|
||||||
|
{
|
||||||
|
"enabled": self._enabled,
|
||||||
|
"notify": self._notify,
|
||||||
|
"cron": self._cron,
|
||||||
|
"onlyonce": self._onlyonce,
|
||||||
|
"queue_cnt": self._queue_cnt,
|
||||||
|
"sign_sites": sign_sites
|
||||||
|
}
|
||||||
|
)
|
||||||
|
@ -1099,3 +1099,36 @@ class SiteStatistic(_PluginBase):
|
|||||||
"statistic_type": self._statistic_type,
|
"statistic_type": self._statistic_type,
|
||||||
"statistic_sites": self._statistic_sites,
|
"statistic_sites": self._statistic_sites,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@eventmanager.register(EventType.SiteDeleted)
|
||||||
|
def site_deleted(self, event):
|
||||||
|
"""
|
||||||
|
删除对应站点选中
|
||||||
|
"""
|
||||||
|
plugin_id = event.event_data.get("plugin_id")
|
||||||
|
site_id = event.event_data.get("site_id")
|
||||||
|
if not plugin_id:
|
||||||
|
return
|
||||||
|
if self.__class__.__name__ not in plugin_id:
|
||||||
|
return
|
||||||
|
config = self.get_config()
|
||||||
|
if config:
|
||||||
|
statistic_sites = config.get("statistic_sites")
|
||||||
|
if statistic_sites:
|
||||||
|
if isinstance(statistic_sites, str):
|
||||||
|
statistic_sites = [statistic_sites]
|
||||||
|
|
||||||
|
# 删除对应站点
|
||||||
|
if site_id:
|
||||||
|
statistic_sites = [site for site in statistic_sites if int(site) != int(site_id)]
|
||||||
|
else:
|
||||||
|
# 清空
|
||||||
|
statistic_sites = []
|
||||||
|
|
||||||
|
# 若无站点,则停止
|
||||||
|
if len(statistic_sites) == 0:
|
||||||
|
self._enabled = False
|
||||||
|
|
||||||
|
self._statistic_sites = statistic_sites
|
||||||
|
# 保存配置
|
||||||
|
self.__update_config()
|
||||||
|
@ -22,6 +22,8 @@ class EventType(Enum):
|
|||||||
SiteSignin = "site.signin"
|
SiteSignin = "site.signin"
|
||||||
# 站点数据统计
|
# 站点数据统计
|
||||||
SiteStatistic = "site.statistic"
|
SiteStatistic = "site.statistic"
|
||||||
|
# 站点删除
|
||||||
|
SiteDeleted = "site.deleted"
|
||||||
# 豆瓣想看
|
# 豆瓣想看
|
||||||
DoubanSync = "douban.sync"
|
DoubanSync = "douban.sync"
|
||||||
# Webhook消息
|
# Webhook消息
|
||||||
@ -40,6 +42,7 @@ class EventType(Enum):
|
|||||||
NoticeMessage = "notice.message"
|
NoticeMessage = "notice.message"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# 系统配置Key字典
|
# 系统配置Key字典
|
||||||
class SystemConfigKey(Enum):
|
class SystemConfigKey(Enum):
|
||||||
# 用户已安装的插件
|
# 用户已安装的插件
|
||||||
|
Loading…
x
Reference in New Issue
Block a user