-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
42 lines (32 loc) · 1.19 KB
/
server.py
File metadata and controls
42 lines (32 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import komiku
from fastapi import FastAPI
from typing import TypedDict, AsyncIterator
from starlette.applications import Starlette
from starlette.requests import Request
import contextlib
import httpx
class State(TypedDict):
http_client: httpx.AsyncClient
@contextlib.asynccontextmanager
async def lifespan(app: Starlette) -> AsyncIterator[State]:
async with httpx.AsyncClient() as client:
yield {"http_client": client}
app = FastAPI(lifespan=lifespan)
@app.get("/search")
async def read_root(q:str, request: Request):
result = await komiku.Search(q).asyn(request.state.http_client)
respon = await result.result
return respon
@app.get("/manga/{slug}")
async def read_root(slug:str, request: Request):
result = await komiku.Manga(slug).asyn(request.state.http_client)
respon = await result.result
return respon
@app.get("/chapter/{slug}")
async def get_chapter(slug:str, request: Request):
result = await komiku.Chapter(slug).asyn(request.state.http_client)
respon = await result.result
return respon
@app.get("/top/")
def re(type:str = "manga", sort:str = "new"):
return komiku.Search().top(sort, type)