From 61d7374d95cbce38022abe2adc21fae733ba80ee Mon Sep 17 00:00:00 2001 From: jxxghp Date: Mon, 23 Dec 2024 16:58:04 +0800 Subject: [PATCH] fix ide warnings --- app/chain/download.py | 3 +- app/chain/user.py | 2 +- app/command.py | 3 +- app/core/event.py | 2 +- app/db/__init__.py | 8 +- app/modules/bangumi/bangumi.py | 1 - app/modules/emby/__init__.py | 11 ++- app/modules/filemanager/__init__.py | 3 +- app/modules/filemanager/storages/__init__.py | 2 +- app/modules/indexer/__init__.py | 2 +- app/modules/indexer/spider/__init__.py | 2 +- app/modules/jellyfin/__init__.py | 2 +- app/modules/plex/__init__.py | 2 +- app/modules/telegram/__init__.py | 3 +- app/modules/wechat/__init__.py | 3 +- app/schemas/__init__.py | 1 + app/schemas/event.py | 2 +- app/schemas/mediaserver.py | 2 +- app/schemas/servarr.py | 78 ++++++++++---------- app/schemas/site.py | 14 ++-- database/versions/a295e41830a6_2_0_6.py | 3 - 21 files changed, 71 insertions(+), 78 deletions(-) diff --git a/app/chain/download.py b/app/chain/download.py index 61f0f218..5cbf4489 100644 --- a/app/chain/download.py +++ b/app/chain/download.py @@ -19,8 +19,7 @@ from app.helper.directory import DirectoryHelper from app.helper.message import MessageHelper from app.helper.torrent import TorrentHelper from app.log import logger -from app.schemas import ExistMediaInfo, NotExistMediaInfo, DownloadingTorrent, Notification -from app.schemas.event import ResourceSelectionEventData, ResourceDownloadEventData +from app.schemas import ExistMediaInfo, NotExistMediaInfo, DownloadingTorrent, Notification, ResourceSelectionEventData, ResourceDownloadEventData from app.schemas.types import MediaType, TorrentStatus, EventType, MessageChannel, NotificationType, ChainEventType from app.utils.http import RequestUtils from app.utils.string import StringUtils diff --git a/app/chain/user.py b/app/chain/user.py index 6a36aef2..26601931 100644 --- a/app/chain/user.py +++ b/app/chain/user.py @@ -7,7 +7,7 @@ from app.core.security import get_password_hash, verify_password from app.db.models.user import User from app.db.user_oper import UserOper from app.log import logger -from app.schemas.event import AuthCredentials, AuthInterceptCredentials +from app.schemas import AuthCredentials, AuthInterceptCredentials from app.schemas.types import ChainEventType from app.utils.otp import OtpUtils from app.utils.singleton import Singleton diff --git a/app/command.py b/app/command.py index 6cef31dc..3d581efd 100644 --- a/app/command.py +++ b/app/command.py @@ -15,8 +15,7 @@ from app.helper.message import MessageHelper from app.helper.thread import ThreadHelper from app.log import logger from app.scheduler import Scheduler -from app.schemas import Notification -from app.schemas.event import CommandRegisterEventData +from app.schemas import Notification, CommandRegisterEventData from app.schemas.types import EventType, MessageChannel, ChainEventType from app.utils.object import ObjectUtils from app.utils.singleton import Singleton diff --git a/app/core/event.py b/app/core/event.py index 4e17da5a..666224d0 100644 --- a/app/core/event.py +++ b/app/core/event.py @@ -13,7 +13,7 @@ from typing import Callable, Dict, List, Optional, Union from app.helper.message import MessageHelper from app.helper.thread import ThreadHelper from app.log import logger -from app.schemas.event import ChainEventData +from app.schemas import ChainEventData from app.schemas.types import ChainEventType, EventType from app.utils.limit import ExponentialBackoffRateLimiter from app.utils.singleton import Singleton diff --git a/app/db/__init__.py b/app/db/__init__.py index 01bc2d1d..5812066c 100644 --- a/app/db/__init__.py +++ b/app/db/__init__.py @@ -13,7 +13,7 @@ connect_args = { # 启用 WAL 模式时的额外配置 if settings.DB_WAL_ENABLE: connect_args["check_same_thread"] = False -kwargs = { +db_kwargs = { "url": f"sqlite:///{settings.CONFIG_PATH}/user.db", "pool_pre_ping": settings.DB_POOL_PRE_PING, "echo": settings.DB_ECHO, @@ -23,13 +23,13 @@ kwargs = { } # 当使用 QueuePool 时,添加 QueuePool 特有的参数 if pool_class == QueuePool: - kwargs.update({ + db_kwargs.update({ "pool_size": settings.DB_POOL_SIZE, "pool_timeout": settings.DB_POOL_TIMEOUT, "max_overflow": settings.DB_MAX_OVERFLOW }) # 创建数据库引擎 -Engine = create_engine(**kwargs) +Engine = create_engine(**db_kwargs) # 根据配置设置日志模式 journal_mode = "WAL" if settings.DB_WAL_ENABLE else "DELETE" with Engine.connect() as connection: @@ -198,7 +198,7 @@ class Base: @classmethod @db_query def get(cls, db: Session, rid: int) -> Self: - return db.query(cls).filter(cls.id == rid).first() + return db.query(cls).filter(and_(cls.id == rid)).first() @db_update def update(self, db: Session, payload: dict): diff --git a/app/modules/bangumi/bangumi.py b/app/modules/bangumi/bangumi.py index df8c92d0..abf9330b 100644 --- a/app/modules/bangumi/bangumi.py +++ b/app/modules/bangumi/bangumi.py @@ -1,5 +1,4 @@ from datetime import datetime -from functools import lru_cache import requests from cachetools import TTLCache, cached diff --git a/app/modules/emby/__init__.py b/app/modules/emby/__init__.py index d562f1b4..59b1f625 100644 --- a/app/modules/emby/__init__.py +++ b/app/modules/emby/__init__.py @@ -6,7 +6,6 @@ from app.core.event import eventmanager from app.log import logger from app.modules import _MediaServerBase, _ModuleBase from app.modules.emby.emby import Emby -from app.schemas.event import AuthCredentials, AuthInterceptCredentials from app.schemas.types import MediaType, ModuleType, ChainEventType, MediaServerType @@ -73,8 +72,8 @@ class EmbyModule(_ModuleBase, _MediaServerBase[Emby]): logger.info(f"Emby服务器 {name} 连接断开,尝试重连 ...") server.reconnect() - def user_authenticate(self, credentials: AuthCredentials, service_name: Optional[str] = None) \ - -> Optional[AuthCredentials]: + def user_authenticate(self, credentials: schemas.AuthCredentials, service_name: Optional[str] = None) \ + -> Optional[schemas.AuthCredentials]: """ 使用Emby用户辅助完成用户认证 :param credentials: 认证数据 @@ -96,11 +95,11 @@ class EmbyModule(_ModuleBase, _MediaServerBase[Emby]): # 触发认证拦截事件 intercept_event = eventmanager.send_event( etype=ChainEventType.AuthIntercept, - data=AuthInterceptCredentials(username=credentials.username, channel=self.get_name(), - service=name, status="triggered") + data=schemas.AuthInterceptCredentials(username=credentials.username, channel=self.get_name(), + service=name, status="triggered") ) if intercept_event and intercept_event.event_data: - intercept_data: AuthInterceptCredentials = intercept_event.event_data + intercept_data: schemas.AuthInterceptCredentials = intercept_event.event_data if intercept_data.cancel: continue token = server.authenticate(credentials.username, credentials.password) diff --git a/app/modules/filemanager/__init__.py b/app/modules/filemanager/__init__.py index 0bdd04ee..83a8a000 100644 --- a/app/modules/filemanager/__init__.py +++ b/app/modules/filemanager/__init__.py @@ -16,8 +16,7 @@ from app.helper.module import ModuleHelper from app.log import logger from app.modules import _ModuleBase from app.modules.filemanager.storages import StorageBase -from app.schemas import TransferInfo, ExistMediaInfo, TmdbEpisode, TransferDirectoryConf, FileItem, StorageUsage -from app.schemas.event import TransferRenameEventData +from app.schemas import TransferInfo, ExistMediaInfo, TmdbEpisode, TransferDirectoryConf, FileItem, StorageUsage, TransferRenameEventData from app.schemas.types import MediaType, ModuleType, ChainEventType, OtherModulesType from app.utils.system import SystemUtils diff --git a/app/modules/filemanager/storages/__init__.py b/app/modules/filemanager/storages/__init__.py index 2ffa561c..a4ede267 100644 --- a/app/modules/filemanager/storages/__init__.py +++ b/app/modules/filemanager/storages/__init__.py @@ -1,6 +1,6 @@ from abc import ABCMeta, abstractmethod from pathlib import Path -from typing import Optional, List, Union, Dict, Tuple +from typing import Optional, List, Dict, Tuple from app import schemas from app.helper.storage import StorageHelper diff --git a/app/modules/indexer/__init__.py b/app/modules/indexer/__init__.py index 99c80d12..7bd0ff42 100644 --- a/app/modules/indexer/__init__.py +++ b/app/modules/indexer/__init__.py @@ -282,6 +282,6 @@ class IndexerModule(_ModuleBase): leeching_size=site_obj.leeching_size, message_unread=site_obj.message_unread, message_unread_contents=site_obj.message_unread_contents or [], - updated_at=datetime.now().strftime('%Y-%m-%d'), + updated_day=datetime.now().strftime('%Y-%m-%d'), err_msg=site_obj.err_msg ) diff --git a/app/modules/indexer/spider/__init__.py b/app/modules/indexer/spider/__init__.py index b5d5d8f8..4c7017f7 100644 --- a/app/modules/indexer/spider/__init__.py +++ b/app/modules/indexer/spider/__init__.py @@ -675,7 +675,7 @@ class TorrentSpider: elif method_name == "appendleft": text = f"{args}{text}" elif method_name == "querystring": - parsed_url = urlparse(text) + parsed_url = urlparse(str(text)) query_params = parse_qs(parsed_url.query) param_value = query_params.get(args) text = param_value[0] if param_value else '' diff --git a/app/modules/jellyfin/__init__.py b/app/modules/jellyfin/__init__.py index 41f3f1f8..a781b500 100644 --- a/app/modules/jellyfin/__init__.py +++ b/app/modules/jellyfin/__init__.py @@ -6,7 +6,7 @@ from app.core.event import eventmanager from app.log import logger from app.modules import _MediaServerBase, _ModuleBase from app.modules.jellyfin.jellyfin import Jellyfin -from app.schemas.event import AuthCredentials, AuthInterceptCredentials +from app.schemas import AuthCredentials, AuthInterceptCredentials from app.schemas.types import MediaType, ModuleType, ChainEventType, MediaServerType diff --git a/app/modules/plex/__init__.py b/app/modules/plex/__init__.py index 6e583c12..3fecf029 100644 --- a/app/modules/plex/__init__.py +++ b/app/modules/plex/__init__.py @@ -6,7 +6,7 @@ from app.core.event import eventmanager from app.log import logger from app.modules import _ModuleBase, _MediaServerBase from app.modules.plex.plex import Plex -from app.schemas.event import AuthCredentials, AuthInterceptCredentials +from app.schemas import AuthCredentials, AuthInterceptCredentials from app.schemas.types import MediaType, ModuleType, ChainEventType, MediaServerType diff --git a/app/modules/telegram/__init__.py b/app/modules/telegram/__init__.py index 42cf520e..52dc0d61 100644 --- a/app/modules/telegram/__init__.py +++ b/app/modules/telegram/__init__.py @@ -7,8 +7,7 @@ from app.core.event import eventmanager from app.log import logger from app.modules import _ModuleBase, _MessageBase from app.modules.telegram.telegram import Telegram -from app.schemas import MessageChannel, CommingMessage, Notification -from app.schemas.event import CommandRegisterEventData +from app.schemas import MessageChannel, CommingMessage, Notification, CommandRegisterEventData from app.schemas.types import ModuleType, ChainEventType from app.utils.structures import DictUtils diff --git a/app/modules/wechat/__init__.py b/app/modules/wechat/__init__.py index df4ce743..059afd2f 100644 --- a/app/modules/wechat/__init__.py +++ b/app/modules/wechat/__init__.py @@ -8,8 +8,7 @@ from app.log import logger from app.modules import _ModuleBase, _MessageBase from app.modules.wechat.WXBizMsgCrypt3 import WXBizMsgCrypt from app.modules.wechat.wechat import WeChat -from app.schemas import MessageChannel, CommingMessage, Notification -from app.schemas.event import CommandRegisterEventData +from app.schemas import MessageChannel, CommingMessage, Notification, CommandRegisterEventData from app.schemas.types import ModuleType, ChainEventType from app.utils.dom import DomUtils from app.utils.structures import DictUtils diff --git a/app/schemas/__init__.py b/app/schemas/__init__.py index f7bf7e31..ec0e5ae3 100644 --- a/app/schemas/__init__.py +++ b/app/schemas/__init__.py @@ -18,3 +18,4 @@ from .system import * from .file import * from .exception import * from .system import * +from .event import * diff --git a/app/schemas/event.py b/app/schemas/event.py index 66a27487..16a1349c 100644 --- a/app/schemas/event.py +++ b/app/schemas/event.py @@ -89,7 +89,7 @@ class AuthInterceptCredentials(ChainEventData): channel: str = Field(..., description="认证渠道") service: str = Field(..., description="服务名称") status: str = Field(..., description="认证状态, 包含 'triggered' 表示认证触发,'completed' 表示认证成功") - token: Optional[str] = Field(None, description="认证令牌") + token: Optional[str] = Field(default=None, description="认证令牌") # 输出参数 source: str = Field(default="未知拦截源", description="拦截源") diff --git a/app/schemas/mediaserver.py b/app/schemas/mediaserver.py index 30d1ffaf..bfd6bfe1 100644 --- a/app/schemas/mediaserver.py +++ b/app/schemas/mediaserver.py @@ -132,7 +132,7 @@ class MediaServerSeasonInfo(BaseModel): 媒体服务器媒体剧集信息 """ season: Optional[int] = None - episodes: Optional[List[int]] = Field(default_factory=list) + episodes: Optional[List[Dict[int, list]]] = Field(default_factory=list) class WebhookEventInfo(BaseModel): diff --git a/app/schemas/servarr.py b/app/schemas/servarr.py index 9eaa3cf4..0fd0170e 100644 --- a/app/schemas/servarr.py +++ b/app/schemas/servarr.py @@ -3,55 +3,57 @@ from pydantic import BaseModel, Field class RadarrMovie(BaseModel): - id: Optional[int] - title: Optional[str] - year: Optional[str] + id: Optional[int] = None + title: Optional[str] = None + year: Optional[str] = None isAvailable: bool = False monitored: bool = False - tmdbId: Optional[int] - imdbId: Optional[str] - titleSlug: Optional[str] - folderName: Optional[str] - path: Optional[str] - profileId: Optional[int] - qualityProfileId: Optional[int] - added: Optional[str] + tmdbId: Optional[int] = None + imdbId: Optional[str] = None + titleSlug: Optional[str] = None + folderName: Optional[str] = None + path: Optional[str] = None + profileId: Optional[int] = None + qualityProfileId: Optional[int] = None + added: Optional[str] = None hasFile: bool = False class SonarrSeries(BaseModel): - id: Optional[int] - title: Optional[str] - sortTitle: Optional[str] - seasonCount: Optional[int] - status: Optional[str] - overview: Optional[str] - network: Optional[str] - airTime: Optional[str] + id: Optional[int] = None + title: Optional[str] = None + sortTitle: Optional[str] = None + seasonCount: Optional[int] = None + status: Optional[str] = None + overview: Optional[str] = None + network: Optional[str] = None + airTime: Optional[str] = None images: list = Field(default_factory=list) - remotePoster: Optional[str] + remotePoster: Optional[str] = None seasons: list = Field(default_factory=list) - year: Optional[str] - path: Optional[str] - profileId: Optional[int] - languageProfileId: Optional[int] + year: Optional[str] = None + path: Optional[str] = None + profileId: Optional[int] = None + languageProfileId: Optional[int] = None seasonFolder: bool = False monitored: bool = False useSceneNumbering: bool = False - runtime: Optional[int] - tmdbId: Optional[int] - imdbId: Optional[str] - tvdbId: Optional[int] - tvRageId: Optional[int] - tvMazeId: Optional[int] - firstAired: Optional[str] - seriesType: Optional[str] - cleanTitle: Optional[str] - titleSlug: Optional[str] - certification: Optional[str] + runtime: Optional[int] = None + tmdbId: Optional[int] = None + imdbId: Optional[str] = None + tvdbId: Optional[int] = None + tvRageId: Optional[int] = None + tvMazeId: Optional[int] = None + firstAired: Optional[str] = None + seriesType: Optional[str] = None + cleanTitle: Optional[str] = None + titleSlug: Optional[str] = None + certification: Optional[str] = None genres: list = Field(default_factory=list) tags: list = Field(default_factory=list) - added: Optional[str] - ratings: Optional[dict] - qualityProfileId: Optional[int] + added: Optional[str] = None + ratings: Optional[dict] = None + qualityProfileId: Optional[int] = None statistics: dict = Field(default_factory=dict) + isAvailable: Optional[bool] = False + hasFile: Optional[bool] = False diff --git a/app/schemas/site.py b/app/schemas/site.py index e59824f3..ee0909df 100644 --- a/app/schemas/site.py +++ b/app/schemas/site.py @@ -53,7 +53,7 @@ class Site(BaseModel): class SiteStatistic(BaseModel): # 站点ID - domain: Optional[str] + domain: Optional[str] = None # 成功次数 success: Optional[int] = 0 # 失败次数 @@ -63,7 +63,7 @@ class SiteStatistic(BaseModel): # 最后状态 lst_state: Optional[int] = 0 # 最后修改时间 - lst_mod_date: Optional[str] + lst_mod_date: Optional[str] = None # 备注 note: Optional[Any] = None @@ -73,15 +73,15 @@ class SiteStatistic(BaseModel): class SiteUserData(BaseModel): # 站点域名 - domain: Optional[str] + domain: Optional[str] = None # 用户名 - username: Optional[str] + username: Optional[str] = None # 用户ID - userid: Optional[Union[int, str]] + userid: Optional[Union[int, str]] = None # 用户等级 - user_level: Optional[str] + user_level: Optional[str] = None # 加入时间 - join_at: Optional[str] + join_at: Optional[str] = None # 积分 bonus: Optional[float] = 0.0 # 上传量 diff --git a/database/versions/a295e41830a6_2_0_6.py b/database/versions/a295e41830a6_2_0_6.py index d243f140..97a21d86 100644 --- a/database/versions/a295e41830a6_2_0_6.py +++ b/database/versions/a295e41830a6_2_0_6.py @@ -5,9 +5,6 @@ Revises: ecf3c693fdf3 Create Date: 2024-11-14 12:49:13.838120 """ -from alembic import op -import sqlalchemy as sa -from sqlalchemy.dialects import sqlite from app.db.systemconfig_oper import SystemConfigOper from app.schemas.types import SystemConfigKey