feat: dapp registry + /api/getDapps, /img/dapps, DappAdmin; dapp-link verifier default-on (IDRS_VERIFY_DAPPS); is_live sticky override; fix edit-without-upload (Dapp+Token)
This commit is contained in:
1 parent
77d6cd5b92
commit
3b68820beb
9 files changed
+447
-51
No files matched your search
+46
-3
@@ -1,4 +1,5 @@
|
||||
from pathlib import Path
|
||||
import mimetypes
|
||||
|
||||
from fastapi import FastAPI, HTTPException
|
||||
from fastapi.responses import FileResponse
|
||||
@@ -6,12 +7,13 @@ from fastapi.staticfiles import StaticFiles
|
||||
|
||||
from app import db
|
||||
from app.admin import create_admin
|
||||
from app.verify import Verifier
|
||||
from app.verify import DappVerifier, TokenVerifier
|
||||
|
||||
BASE_DIR = Path(__file__).resolve().parent
|
||||
ICON_DIR = BASE_DIR / "static" / "icons"
|
||||
|
||||
verifier = Verifier()
|
||||
token_verifier = TokenVerifier()
|
||||
dapp_verifier = DappVerifier()
|
||||
|
||||
app = FastAPI(title="IDRS API")
|
||||
app.mount("/static", StaticFiles(directory=str(BASE_DIR / "static")), name="static")
|
||||
@@ -59,6 +61,14 @@ def _serve_icon(filename: str):
|
||||
return FileResponse(path, media_type="image/png")
|
||||
|
||||
|
||||
def _serve_dapp_image(filename: str):
|
||||
dapp_dir = ICON_DIR / "dapps"
|
||||
path = (dapp_dir / filename).resolve()
|
||||
if not path.is_file() or dapp_dir.resolve() not in path.parents:
|
||||
raise HTTPException(status_code=404, detail="not found")
|
||||
return FileResponse(path, media_type=mimetypes.guess_type(path.name)[0] or "application/octet-stream")
|
||||
|
||||
|
||||
@app.get("/img/token/{filename}")
|
||||
def get_icon(filename: str):
|
||||
return _serve_icon(filename)
|
||||
@@ -69,7 +79,40 @@ def get_public_icon(filename: str):
|
||||
return _serve_icon(filename)
|
||||
|
||||
|
||||
@app.get("/img/dapps/{filename}")
|
||||
def get_dapp_image(filename: str):
|
||||
return _serve_dapp_image(filename)
|
||||
|
||||
|
||||
@app.get("/public/img/dapps/{filename}")
|
||||
def get_public_dapp_image(filename: str):
|
||||
return _serve_dapp_image(filename)
|
||||
|
||||
|
||||
@app.get("/api/getDapps")
|
||||
def get_dapps():
|
||||
dapps = []
|
||||
for d in db.list_dapps():
|
||||
dapps.append(
|
||||
{
|
||||
"id": d.id,
|
||||
"name": d.name,
|
||||
"description": d.description,
|
||||
"link": d.link,
|
||||
"image": d.image,
|
||||
"is_live": bool(d.is_live),
|
||||
"counter": d.counter,
|
||||
"category_id": d.category_id,
|
||||
"is_available_indonesia": d.is_available_indonesia,
|
||||
"created_at": d.created_at,
|
||||
"updated_at": d.updated_at,
|
||||
}
|
||||
)
|
||||
return {"dappList": dapps}
|
||||
|
||||
|
||||
@app.on_event("startup")
|
||||
def startup():
|
||||
db.init_db()
|
||||
verifier.start()
|
||||
token_verifier.start()
|
||||
dapp_verifier.start()
|
||||
Reference in new issue
Block a user