Hana Celeste commited on
Commit
209f3c1
·
verified ·
1 Parent(s): f6aa8b5

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +24 -2
main.py CHANGED
@@ -1,4 +1,5 @@
1
  from fastapi import FastAPI
 
2
  from contextlib import asynccontextmanager
3
  from app.enka_logic import EnkaApp
4
  from app.akasa_logic import AkasaApp
@@ -16,6 +17,11 @@ yt_info = YoutubeInfo()
16
  yt_dl = YoutubeDownload()
17
  keygen = KeyGenApp()
18
 
 
 
 
 
 
19
  @asynccontextmanager
20
  async def lifespan(app: FastAPI):
21
  await enka.start()
@@ -59,10 +65,26 @@ async def ytdl(url: str):
59
  return await yt_dl.get_download(url)
60
 
61
  @app.get("/keys")
62
- def get_keys(count: int = 10):
 
 
 
 
 
 
 
 
 
 
 
 
63
  if count > 15:
64
  count = 15
65
- return keygen.fetch_keys(count)
 
 
 
 
66
 
67
  @app.get("/")
68
  def home():
 
1
  from fastapi import FastAPI
2
+ from fastapi import HTTPException
3
  from contextlib import asynccontextmanager
4
  from app.enka_logic import EnkaApp
5
  from app.akasa_logic import AkasaApp
 
17
  yt_dl = YoutubeDownload()
18
  keygen = KeyGenApp()
19
 
20
+ BOT_API_KEYS = {
21
+ "fdd8ca0526ca46c9ba3a40101e530810",
22
+ "botkey456"
23
+ }
24
+
25
  @asynccontextmanager
26
  async def lifespan(app: FastAPI):
27
  await enka.start()
 
65
  return await yt_dl.get_download(url)
66
 
67
  @app.get("/keys")
68
+ def get_keys(
69
+ count: int = 10,
70
+ url: str | None = None,
71
+ apikey: str | None = None
72
+ ):
73
+ if apikey not in BOT_API_KEYS:
74
+ raise HTTPException(status_code=403, detail="Invalid API key")
75
+
76
+ if not url:
77
+ raise HTTPException(status_code=400, detail="Missing url")
78
+
79
+ if count < 1:
80
+ count = 1
81
  if count > 15:
82
  count = 15
83
+
84
+ return keygen.fetch_keys(
85
+ target_url=url,
86
+ count=count
87
+ )
88
 
89
  @app.get("/")
90
  def home():