Update main.py
Browse files
main.py
CHANGED
|
@@ -26,6 +26,9 @@ gs_code_app = GSCodeApp()
|
|
| 26 |
from app.ht_noti import HentaiApp
|
| 27 |
hentai_app = HentaiApp()
|
| 28 |
|
|
|
|
|
|
|
|
|
|
| 29 |
@asynccontextmanager
|
| 30 |
async def lifespan(app: FastAPI):
|
| 31 |
await invite_app.start()
|
|
@@ -33,12 +36,14 @@ async def lifespan(app: FastAPI):
|
|
| 33 |
await gs_app.start()
|
| 34 |
await gs_code_app.start()
|
| 35 |
await hentai_app.start()
|
|
|
|
| 36 |
yield
|
| 37 |
await invite_app.stop()
|
| 38 |
await lq_app.stop()
|
| 39 |
await gs_app.stop()
|
| 40 |
await gs_code_app.stop()
|
| 41 |
await hentai_app.stop()
|
|
|
|
| 42 |
|
| 43 |
app = FastAPI(lifespan=lifespan)
|
| 44 |
|
|
@@ -118,7 +123,20 @@ async def hentai_newest(
|
|
| 118 |
):
|
| 119 |
key_to_check = x_api_key or apikey
|
| 120 |
return await hentai_app.get_new(key_to_check, API_KEY)
|
| 121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
@app.get("/")
|
| 123 |
def home():
|
| 124 |
uptime_seconds = int(time.time() - START_TIME)
|
|
|
|
| 26 |
from app.ht_noti import HentaiApp
|
| 27 |
hentai_app = HentaiApp()
|
| 28 |
|
| 29 |
+
from app.ht_rd import HentaiRandomApp
|
| 30 |
+
hentai_random_app = HentaiRandomApp()
|
| 31 |
+
|
| 32 |
@asynccontextmanager
|
| 33 |
async def lifespan(app: FastAPI):
|
| 34 |
await invite_app.start()
|
|
|
|
| 36 |
await gs_app.start()
|
| 37 |
await gs_code_app.start()
|
| 38 |
await hentai_app.start()
|
| 39 |
+
await hentai_random_app.start()
|
| 40 |
yield
|
| 41 |
await invite_app.stop()
|
| 42 |
await lq_app.stop()
|
| 43 |
await gs_app.stop()
|
| 44 |
await gs_code_app.stop()
|
| 45 |
await hentai_app.stop()
|
| 46 |
+
await hentai_random_app.stop()
|
| 47 |
|
| 48 |
app = FastAPI(lifespan=lifespan)
|
| 49 |
|
|
|
|
| 123 |
):
|
| 124 |
key_to_check = x_api_key or apikey
|
| 125 |
return await hentai_app.get_new(key_to_check, API_KEY)
|
| 126 |
+
|
| 127 |
+
@app.get("/api/v1/hentai/random")
|
| 128 |
+
async def get_hentai_random(
|
| 129 |
+
limit: int = Query(5, ge=1, le=20),
|
| 130 |
+
x_api_key: str = Header(None)
|
| 131 |
+
):
|
| 132 |
+
if API_KEY and x_api_key != API_KEY:
|
| 133 |
+
raise HTTPException(status_code=403, detail="Cút!")
|
| 134 |
+
|
| 135 |
+
res = await hentai_random_app.get_random(limit)
|
| 136 |
+
if not res["ok"]:
|
| 137 |
+
raise HTTPException(status_code=500, detail=res["error"])
|
| 138 |
+
return res
|
| 139 |
+
|
| 140 |
@app.get("/")
|
| 141 |
def home():
|
| 142 |
uptime_seconds = int(time.time() - START_TIME)
|