feat: POST /api/increaseDappCounter (X-Api-Key = IDRS_SECRET, atomic +1, 200/401/404)
This commit is contained in:
1 parent
3b68820beb
commit
01ee7ec733
4 files changed
+36
-6
No files matched your search
+16
-2
@@ -1,7 +1,9 @@
|
||||
from pathlib import Path
|
||||
import hmac
|
||||
import mimetypes
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
from fastapi import FastAPI, HTTPException
|
||||
from fastapi import FastAPI, Header, HTTPException, Query
|
||||
from fastapi.responses import FileResponse
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
|
||||
@@ -12,6 +14,8 @@ from app.verify import DappVerifier, TokenVerifier
|
||||
BASE_DIR = Path(__file__).resolve().parent
|
||||
ICON_DIR = BASE_DIR / "static" / "icons"
|
||||
|
||||
SECRET = os.environ.get("IDRS_SECRET", "")
|
||||
|
||||
token_verifier = TokenVerifier()
|
||||
dapp_verifier = DappVerifier()
|
||||
|
||||
@@ -111,6 +115,16 @@ def get_dapps():
|
||||
return {"dappList": dapps}
|
||||
|
||||
|
||||
@app.post("/api/increaseDappCounter")
|
||||
def increase_dapp_counter(id: int = Query(...), x_api_key: str = Header(default="")):
|
||||
if not SECRET or not hmac.compare_digest(SECRET.encode(), x_api_key.encode()):
|
||||
raise HTTPException(status_code=401, detail="unauthorized")
|
||||
new_counter = db.increment_dapp_counter(id)
|
||||
if new_counter is None:
|
||||
raise HTTPException(status_code=404, detail="dapp not found")
|
||||
return {"id": id, "counter": new_counter}
|
||||
|
||||
|
||||
@app.on_event("startup")
|
||||
def startup():
|
||||
db.init_db()
|
||||
|
||||
Reference in new issue
Block a user