|
1 | 1 | from fastapi import APIRouter, Depends, HTTPException |
2 | 2 |
|
| 3 | +from Models.comic import BaseComicInfo, ComicInfo |
3 | 4 | from Models.requests import ComicSearchReq |
4 | | -from Models.response import StandardResponse |
| 5 | +from Models.response import BaseResponse, StandardResponse |
5 | 6 | from Models.user import User, UserData |
6 | 7 | from Services.Modulator.manager import plugin_manager |
7 | 8 | from Services.Security.user import get_current_user, get_user_data |
8 | 9 |
|
9 | 10 | comic_router = APIRouter(prefix="/comic") |
10 | 11 |
|
11 | 12 |
|
12 | | -@comic_router.post("/search") |
13 | | -async def search_comic(body: ComicSearchReq, user: User = Depends(get_current_user)): |
14 | | - pass |
| 13 | +@comic_router.post("/search", response_model=BaseResponse[list[BaseComicInfo]]) |
| 14 | +async def search_comic( |
| 15 | + body: ComicSearchReq, user: User = Depends(get_current_user) |
| 16 | +) -> StandardResponse[list[BaseComicInfo]]: |
| 17 | + # TODO: Performence imporvement |
| 18 | + result = [] |
| 19 | + for source in plugin_manager.plugins: |
| 20 | + resp = source.instance.search(body.keyword, *body.extras) |
| 21 | + |
| 22 | + result.extend(resp) |
| 23 | + |
| 24 | + return StandardResponse[list[BaseComicInfo]](data=result) |
| 25 | + |
| 26 | + |
| 27 | +@comic_router.get("/{src_id}/album/{album_id}", response_model=BaseResponse[ComicInfo]) |
| 28 | +async def get_album(src_id: str, album_id: str) -> StandardResponse[ComicInfo]: |
| 29 | + if (source := plugin_manager.get_source(src_id)) is None: |
| 30 | + raise HTTPException(status_code=404, detail="Source not found") |
| 31 | + |
| 32 | + return StandardResponse[ComicInfo](data=source.instance.album(album_id)) |
15 | 33 |
|
16 | 34 |
|
17 | | -@comic_router.get("/{src_id}/favor") |
| 35 | +@comic_router.get("/{src_id}/favor", response_model=BaseResponse[list[BaseComicInfo]]) |
18 | 36 | async def get_favor( |
19 | 37 | src_id: str, |
20 | 38 | data: dict[str, str] | None = None, |
21 | 39 | user_data: UserData = Depends(get_user_data), |
22 | | -): |
| 40 | +) -> StandardResponse[list[BaseComicInfo]]: |
23 | 41 | if (source := plugin_manager.get_source(src_id)) is None: |
24 | 42 | raise HTTPException(status_code=404, detail="Source not found") |
25 | 43 |
|
26 | 44 | if (resp := source.try_call("get_favor", user_data, data)) is not None: |
27 | 45 | return resp |
28 | 46 |
|
29 | | - return StandardResponse(status_code=404, message="Not Found") |
30 | | - |
31 | | - |
32 | | -@comic_router.get("/{src_id}/album/{album_id}") |
33 | | -async def get_album(src_id: str, album_id: str, user: User = Depends(get_current_user)): |
34 | | - if (source := plugin_manager.get_source(src_id)) is None: |
35 | | - raise HTTPException(status_code=404, detail="Source not found") |
36 | | - |
37 | | - pass |
| 47 | + return StandardResponse(status_code=400, message="Source not support") |
38 | 48 |
|
39 | 49 |
|
40 | 50 | @comic_router.get("/{src_id}/album/{album_id}/images/{chapter_id}") |
|
0 commit comments