Skip to content

Commit edb56cf

Browse files
committed
feat: Routers update
1 parent 07cff2a commit edb56cf

File tree

7 files changed

+37
-24
lines changed

7 files changed

+37
-24
lines changed

Models/comic.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
from pydantic import BaseModel
1+
from typing import Any
22

3-
from typing import List, Optional, Dict, Any
3+
from pydantic import BaseModel
44

55

66
class BaseComicInfo(BaseModel):
77
"""BaseComicInfo"""
8+
89
"""作者,漫画作者"""
9-
author: List[str]
10+
author: list[str]
1011
"""封面,漫画封面图片URL"""
1112
cover: str
1213
"""标识符,漫画在所属平台的索引ID"""
@@ -17,25 +18,26 @@ class BaseComicInfo(BaseModel):
1718

1819
class ComicInfo(BaseModel):
1920
"""ComicInfo"""
21+
2022
"""章节数,漫画章节数"""
21-
chapters: Optional[int] = None
23+
chapters: int | None = None
2224
"""评论量,漫画评论量"""
23-
comments: Optional[int] = None
25+
comments: int | None = None
2426
"""简介,漫画简介"""
25-
description: Optional[str] = None
27+
description: str | None = None
2628
"""额外信息,源平台携带的其它漫画信息"""
27-
extras: Optional[Dict[str, Any]] = None
29+
extras: dict[str, Any] | None = None
2830
"""收藏量,漫画收藏量"""
29-
favorites: Optional[int] = None
31+
favorites: int | None = None
3032
"""已收藏,漫画是否已收藏"""
31-
is_favorite: Optional[bool] = None
33+
is_favorite: bool | None = None
3234
"""已完结,漫画是否已完结"""
33-
is_finished: Optional[bool] = None
35+
is_finished: bool | None = None
3436
"""已阅读,漫画是否已阅读"""
35-
is_viewed: Optional[bool] = None
37+
is_viewed: bool | None = None
3638
"""标签,漫画标签"""
37-
tags: Optional[List[str]] = None
39+
tags: list[str] | None = None
3840
"""更新时间,漫画最近的更新时间戳"""
39-
updated_at: Optional[int] = None
41+
updated_at: int | None = None
4042
"""阅读量,漫画阅读量"""
41-
views: Optional[int] = None
43+
views: int | None = None

Models/plugins.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def search(self, keyword: str) -> list[BaseComicInfo]:
2727

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

3333

Models/user.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ def __init__(self, uid: str, plugin_cookies: dict[str, BaseCookie[str]]):
2020
self.uid = uid
2121
self.plugin_cookies = plugin_cookies
2222

23+
def set_src_cookies(self, src: str, cookies: BaseCookie[str]) -> None:
24+
self.plugin_cookies[src] = cookies
25+
2326
def get_src_cookies(self, src: str) -> BaseCookie[str]:
2427
if src in self.plugin_cookies:
2528
return self.plugin_cookies[src]

Routers/core.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,9 @@
1212

1313

1414
@core_router.get("/ping")
15-
async def get_status() -> StandardResponse:
15+
async def get_status():
1616
return StandardResponse(message="pong")
17+
18+
@core_router.get("/protocol")
19+
async def get_cnm_version():
20+
pass

Routers/user.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ async def encrypt_src_pwd(
129129
record: PwdDb | None = (
130130
db.query(PwdDb)
131131
.filter(
132-
PwdDb.src_id == src_id
132+
PwdDb.source == src_id
133133
and PwdDb.uid == user.uid
134134
and PwdDb.account == body.account
135135
)
@@ -160,7 +160,7 @@ async def get_src_accounts(
160160
src: str, db: Session = Depends(get_db), user: User = Depends(get_current_user)
161161
):
162162
records: list[PwdDb] = (
163-
db.query(PwdDb).filter(PwdDb.src_id == src and PwdDb.uid == user.uid).all()
163+
db.query(PwdDb).filter(PwdDb.source == src and PwdDb.uid == user.uid).all()
164164
)
165165

166166
return StandardResponse(data=[record.account for record in records])
@@ -176,12 +176,12 @@ async def decrypt_src_pwd(
176176
record: PwdDb | None = (
177177
db.query(PwdDb)
178178
.filter(
179-
PwdDb.src_id == src and PwdDb.uid == user.uid and PwdDb.account == account
179+
PwdDb.source == src and PwdDb.uid == user.uid and PwdDb.account == account
180180
)
181181
.first()
182182
)
183183

184184
if record is None:
185185
raise ExceptionResponse.not_found
186186
else:
187-
return StandardResponse(data=decrypt_src_password(record.pwd, record.src_id))
187+
return StandardResponse(data=decrypt_src_password(record.pwd, record.source))

Services/Modulator/manager.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
import os
55
from http.cookies import BaseCookie
66
from pathlib import Path
7-
from typing import Set, cast
7+
from typing import Set
88

99
import toml
10-
from fastapi import Response
1110

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

49+
src_list: list[str] = []
5050
for src in plugin_info["plugin"]["source"]:
5151
if src in self.registered_source:
5252
logger.error(
@@ -55,8 +55,10 @@ def load_plugin(self, plugin_dir: Path) -> bool:
5555
return False
5656
else:
5757
logger.info(f"Registering source {src}")
58+
src_list.append(src)
59+
60+
module = importlib.import_module(f"Plugins.{plugin_dir.name}.main")
5861

59-
module = importlib.import_module(f"Plugins.{plugin_dir.name}.main")
6062
if issubclass(entry := getattr(module, plugin_dir.name), BasePlugin):
6163
instance = entry()
6264
if instance.on_load():
@@ -73,7 +75,7 @@ def load_plugin(self, plugin_dir: Path) -> bool:
7375
else:
7476
raise ImportError
7577
logger.info(f"Plugin {plugin_dir.name} Loaded")
76-
self.registered_source.add(src)
78+
self.registered_source.update(src_list)
7779
return True
7880
else:
7981
logger.error(f"Plugin {plugin_dir.name} is not a valid plugin")

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ pycryptodome = "^3.20.0"
1919
rich = "^13.7.0"
2020
slowapi = "^0.1.8"
2121
toml = "^0.10.2"
22+
nest-asyncio = "^1.6.0"
23+
pymysql = "^1.1.1"
2224

2325
[build-system]
2426
requires = ["poetry-core"]

0 commit comments

Comments
 (0)