Skip to content

Commit

Permalink
feat: Routers update
Browse files Browse the repository at this point in the history
  • Loading branch information
BiDuang committed Jul 19, 2024
1 parent 07cff2a commit edb56cf
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 24 deletions.
30 changes: 16 additions & 14 deletions Models/comic.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from pydantic import BaseModel
from typing import Any

from typing import List, Optional, Dict, Any
from pydantic import BaseModel


class BaseComicInfo(BaseModel):
"""BaseComicInfo"""

"""作者,漫画作者"""
author: List[str]
author: list[str]
"""封面,漫画封面图片URL"""
cover: str
"""标识符,漫画在所属平台的索引ID"""
Expand All @@ -17,25 +18,26 @@ class BaseComicInfo(BaseModel):

class ComicInfo(BaseModel):
"""ComicInfo"""

"""章节数,漫画章节数"""
chapters: Optional[int] = None
chapters: int | None = None
"""评论量,漫画评论量"""
comments: Optional[int] = None
comments: int | None = None
"""简介,漫画简介"""
description: Optional[str] = None
description: str | None = None
"""额外信息,源平台携带的其它漫画信息"""
extras: Optional[Dict[str, Any]] = None
extras: dict[str, Any] | None = None
"""收藏量,漫画收藏量"""
favorites: Optional[int] = None
favorites: int | None = None
"""已收藏,漫画是否已收藏"""
is_favorite: Optional[bool] = None
is_favorite: bool | None = None
"""已完结,漫画是否已完结"""
is_finished: Optional[bool] = None
is_finished: bool | None = None
"""已阅读,漫画是否已阅读"""
is_viewed: Optional[bool] = None
is_viewed: bool | None = None
"""标签,漫画标签"""
tags: Optional[List[str]] = None
tags: list[str] | None = None
"""更新时间,漫画最近的更新时间戳"""
updated_at: Optional[int] = None
updated_at: int | None = None
"""阅读量,漫画阅读量"""
views: Optional[int] = None
views: int | None = None
2 changes: 1 addition & 1 deletion Models/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def search(self, keyword: str) -> list[BaseComicInfo]:

class IAuth(ABC):
@abstractmethod
async def login(self, body: dict[str, str], user: UserData) -> StandardResponse:
async def login(self, body: dict[str, str], user_data: UserData) -> StandardResponse:
pass


Expand Down
3 changes: 3 additions & 0 deletions Models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ def __init__(self, uid: str, plugin_cookies: dict[str, BaseCookie[str]]):
self.uid = uid
self.plugin_cookies = plugin_cookies

def set_src_cookies(self, src: str, cookies: BaseCookie[str]) -> None:
self.plugin_cookies[src] = cookies

def get_src_cookies(self, src: str) -> BaseCookie[str]:
if src in self.plugin_cookies:
return self.plugin_cookies[src]
Expand Down
6 changes: 5 additions & 1 deletion Routers/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,9 @@


@core_router.get("/ping")
async def get_status() -> StandardResponse:
async def get_status():
return StandardResponse(message="pong")

@core_router.get("/protocol")
async def get_cnm_version():
pass
8 changes: 4 additions & 4 deletions Routers/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ async def encrypt_src_pwd(
record: PwdDb | None = (
db.query(PwdDb)
.filter(
PwdDb.src_id == src_id
PwdDb.source == src_id
and PwdDb.uid == user.uid
and PwdDb.account == body.account
)
Expand Down Expand Up @@ -160,7 +160,7 @@ async def get_src_accounts(
src: str, db: Session = Depends(get_db), user: User = Depends(get_current_user)
):
records: list[PwdDb] = (
db.query(PwdDb).filter(PwdDb.src_id == src and PwdDb.uid == user.uid).all()
db.query(PwdDb).filter(PwdDb.source == src and PwdDb.uid == user.uid).all()
)

return StandardResponse(data=[record.account for record in records])
Expand All @@ -176,12 +176,12 @@ async def decrypt_src_pwd(
record: PwdDb | None = (
db.query(PwdDb)
.filter(
PwdDb.src_id == src and PwdDb.uid == user.uid and PwdDb.account == account
PwdDb.source == src and PwdDb.uid == user.uid and PwdDb.account == account
)
.first()
)

if record is None:
raise ExceptionResponse.not_found
else:
return StandardResponse(data=decrypt_src_password(record.pwd, record.src_id))
return StandardResponse(data=decrypt_src_password(record.pwd, record.source))
10 changes: 6 additions & 4 deletions Services/Modulator/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
import os
from http.cookies import BaseCookie
from pathlib import Path
from typing import Set, cast
from typing import Set

import toml
from fastapi import Response

from Configs.config import config
from Models.plugins import BasePlugin, Plugin
Expand Down Expand Up @@ -47,6 +46,7 @@ def load_plugin(self, plugin_dir: Path) -> bool:
) as f:
plugin_info = toml.load(f)

src_list: list[str] = []
for src in plugin_info["plugin"]["source"]:
if src in self.registered_source:
logger.error(
Expand All @@ -55,8 +55,10 @@ def load_plugin(self, plugin_dir: Path) -> bool:
return False
else:
logger.info(f"Registering source {src}")
src_list.append(src)

module = importlib.import_module(f"Plugins.{plugin_dir.name}.main")

module = importlib.import_module(f"Plugins.{plugin_dir.name}.main")
if issubclass(entry := getattr(module, plugin_dir.name), BasePlugin):
instance = entry()
if instance.on_load():
Expand All @@ -73,7 +75,7 @@ def load_plugin(self, plugin_dir: Path) -> bool:
else:
raise ImportError
logger.info(f"Plugin {plugin_dir.name} Loaded")
self.registered_source.add(src)
self.registered_source.update(src_list)
return True
else:
logger.error(f"Plugin {plugin_dir.name} is not a valid plugin")
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ pycryptodome = "^3.20.0"
rich = "^13.7.0"
slowapi = "^0.1.8"
toml = "^0.10.2"
nest-asyncio = "^1.6.0"
pymysql = "^1.1.1"

[build-system]
requires = ["poetry-core"]
Expand Down

0 comments on commit edb56cf

Please sign in to comment.