62 lines
1.7 KiB
Python
62 lines
1.7 KiB
Python
from pathlib import Path
|
|
|
|
from fastapi import FastAPI, HTTPException
|
|
from fastapi.responses import FileResponse
|
|
from fastapi.staticfiles import StaticFiles
|
|
|
|
from app import db
|
|
from app.admin import create_admin
|
|
|
|
BASE_DIR = Path(__file__).resolve().parent
|
|
ICON_DIR = BASE_DIR / "static" / "icons"
|
|
|
|
app = FastAPI(title="IDRS API")
|
|
app.mount("/static", StaticFiles(directory=str(BASE_DIR / "static")), name="static")
|
|
|
|
create_admin(app)
|
|
|
|
|
|
@app.get("/api/getTokenInfo")
|
|
def get_token_info():
|
|
tokens = []
|
|
for t in db.list_tokens():
|
|
tokens.append(
|
|
{
|
|
"idfToken": t.idfToken,
|
|
"position": t.position,
|
|
"typeBlockchain": t.typeBlockchain,
|
|
"name": t.name,
|
|
"symbol": t.symbol,
|
|
"contractAddr": t.contractAddr,
|
|
"decimals": t.decimals,
|
|
"iconUrl": t.iconUrl,
|
|
"filename": t.filename,
|
|
"is_live": bool(t.is_live),
|
|
}
|
|
)
|
|
return {"tokenList": tokens}
|
|
|
|
|
|
@app.get("/api/version/android")
|
|
def get_version_android():
|
|
v = db.get_version()
|
|
return {
|
|
"idVersion": v.idVersion,
|
|
"appName": v.appName,
|
|
"acceptableVersion": v.acceptableVersion,
|
|
"latestVersion": v.latestVersion,
|
|
}
|
|
|
|
|
|
@app.get("/img/token/{filename}")
|
|
def get_icon(filename: str):
|
|
token_dir = ICON_DIR / "token"
|
|
path = (token_dir / filename).resolve()
|
|
if not path.is_file() or token_dir.resolve() not in path.parents:
|
|
raise HTTPException(status_code=404, detail="not found")
|
|
return FileResponse(path, media_type="image/png")
|
|
|
|
|
|
@app.on_event("startup")
|
|
def startup():
|
|
db.init_db() |