Mazenbs commited on
Commit
bca9901
·
verified ·
1 Parent(s): fe1f483

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -0
app.py CHANGED
@@ -15,6 +15,30 @@ app = FastAPI(
15
  version="2.1.0"
16
  )
17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
 
19
  class IndexedURLRequest(BaseModel):
20
  url: HttpUrl
 
15
  version="2.1.0"
16
  )
17
 
18
+ API_TOKEN = os.getenv("API_TOKEN")
19
+
20
+ def verify_api_token(x_api_token: str = Header(None)):
21
+ # إذا لم يتم إرسال التوكن
22
+ if not x_api_token:
23
+ raise HTTPException(
24
+ status_code=401,
25
+ detail="API token is required"
26
+ )
27
+
28
+ # إذا لم يكن التوكن مضبوط في secrets
29
+ if not API_TOKEN:
30
+ raise HTTPException(
31
+ status_code=500,
32
+ detail="API token not configured on server"
33
+ )
34
+
35
+ # إذا كان التوكن غير مطابق
36
+ if x_api_token != API_TOKEN:
37
+ raise HTTPException(
38
+ status_code=401,
39
+ detail="Invalid API token"
40
+ )
41
+
42
 
43
  class IndexedURLRequest(BaseModel):
44
  url: HttpUrl