Add version endpoint
This commit is contained in:
parent
48996cd85f
commit
530767b0d5
21
main.py
21
main.py
|
@ -3,6 +3,8 @@ from pydantic import BaseModel
|
||||||
from fastapi.middleware.cors import CORSMiddleware
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
from calls import *
|
from calls import *
|
||||||
from db import get_db_connection
|
from db import get_db_connection
|
||||||
|
import requests
|
||||||
|
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
app.add_middleware(
|
app.add_middleware(
|
||||||
|
@ -393,4 +395,21 @@ def get_profile(request: ProfileRequest):
|
||||||
raise HTTPException(status_code=400, detail=str(e))
|
raise HTTPException(status_code=400, detail=str(e))
|
||||||
finally:
|
finally:
|
||||||
cursor.close()
|
cursor.close()
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/version")
|
||||||
|
def get_latest_commit_hashes():
|
||||||
|
try:
|
||||||
|
backend_response = requests.get("https://git.mercurio.moe/api/v1/repos/Mercury/dth-pingpong-backend/commits")
|
||||||
|
frontend_response = requests.get("https://git.mercurio.moe/api/v1/repos/Mercury/dth-pingpong-mobileapp/commits")
|
||||||
|
|
||||||
|
if backend_response.status_code == 200 and frontend_response.status_code == 200:
|
||||||
|
backend_hash = backend_response.json()[0]["sha"]
|
||||||
|
frontend_hash = frontend_response.json()[0]["sha"]
|
||||||
|
return {"backend": backend_hash, "frontend": frontend_hash}
|
||||||
|
|
||||||
|
return {"error": "Failed to fetch commit hashes from Forgejo"}
|
||||||
|
except Exception as e:
|
||||||
|
return {"error": str(e)}
|
Loading…
Reference in a new issue