From 58ded2ef5e23c32ce9e0d7fa26790ae2d9d50ae9 Mon Sep 17 00:00:00 2001 From: thsrite Date: Mon, 28 Aug 2023 13:23:56 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=E8=AE=A2=E9=98=85=E7=AB=99=E7=82=B9?= =?UTF-8?q?=E5=8D=95=E7=8B=AC=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- alembic/versions/52ab4930be04_1_0_3.py | 29 ++++++++++++++++++++++++++ app/api/endpoints/site.py | 18 ++++++++++++++++ app/chain/torrents.py | 4 ++-- app/schemas/types.py | 2 ++ 4 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 alembic/versions/52ab4930be04_1_0_3.py diff --git a/alembic/versions/52ab4930be04_1_0_3.py b/alembic/versions/52ab4930be04_1_0_3.py new file mode 100644 index 00000000..76ec5430 --- /dev/null +++ b/alembic/versions/52ab4930be04_1_0_3.py @@ -0,0 +1,29 @@ +"""1_0_3 + +Revision ID: 52ab4930be04 +Revises: ec5fb51fc300 +Create Date: 2023-08-28 13:21:45.152012 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '52ab4930be04' +down_revision = 'ec5fb51fc300' +branch_labels = None +depends_on = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.execute("delete from systemconfig where key = 'RssSites';") + op.execute("insert into systemconfig(key, value) VALUES('RssSites', (select value from systemconfig where key= 'IndexerSites'));") + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + pass + # ### end Alembic commands ### diff --git a/app/api/endpoints/site.py b/app/api/endpoints/site.py index 901af247..9351fc11 100644 --- a/app/api/endpoints/site.py +++ b/app/api/endpoints/site.py @@ -118,6 +118,7 @@ def cookie_cloud_sync(db: Session = Depends(get_db), """ Site.reset(db) SystemConfigOper(db).set(SystemConfigKey.IndexerSites, []) + SystemConfigOper(db).set(SystemConfigKey.RssSites, []) CookieCloudChain(db).process(manual=True) # 插件站点删除 EventManager().send_event(EventType.SiteDeleted, @@ -227,6 +228,23 @@ def read_site_by_domain( return site +@router.get("/rss", summary="所有订阅站点", response_model=List[schemas.Site]) +def read_rss_sites(db: Session = Depends(get_db)) -> List[dict]: + """ + 获取站点列表 + """ + # 选中的rss站点 + rss_sites = SystemConfigOper(db).get(SystemConfigKey.RssSites) + # 所有站点 + all_site = Site.list_order_by_pri(db) + if not rss_sites or not all_site: + return [] + + # 选中的rss站点 + rss_sites = [site for site in all_site if site and site.id in rss_sites] + return rss_sites + + @router.get("/{site_id}", summary="站点详情", response_model=schemas.Site) def read_site( site_id: int, diff --git a/app/chain/torrents.py b/app/chain/torrents.py index 63177baa..e96173d8 100644 --- a/app/chain/torrents.py +++ b/app/chain/torrents.py @@ -52,8 +52,8 @@ class TorrentsChain(ChainBase): # 所有站点索引 indexers = self.siteshelper.get_indexers() - # 配置的索引站点 - config_indexers = [str(sid) for sid in self.systemconfig.get(SystemConfigKey.IndexerSites) or []] + # 配置的Rss站点 + config_indexers = [str(sid) for sid in self.systemconfig.get(SystemConfigKey.RssSites) or []] # 遍历站点缓存资源 for indexer in indexers: # 未开启的站点不搜索 diff --git a/app/schemas/types.py b/app/schemas/types.py index 2f05578b..b8c4e4fd 100644 --- a/app/schemas/types.py +++ b/app/schemas/types.py @@ -50,6 +50,8 @@ class SystemConfigKey(Enum): SearchResults = "SearchResults" # 索引站点范围 IndexerSites = "IndexerSites" + # 订阅站点范围 + RssSites = "RssSites" # 种子优先级规则 TorrentsPriority = "TorrentsPriority" # 通知消息渠道设置