mirror of
https://gitlab.sectorq.eu/jaydee/api_server.git
synced 2026-09-17 02:12:55 +02:00
build
This commit is contained in:
+9
-4
@@ -1,19 +1,24 @@
|
|||||||
from fastapi import FastAPI, Depends
|
from fastapi import FastAPI, Depends
|
||||||
|
from pydantic import BaseModel
|
||||||
from app.auth import verify_token
|
from app.auth import verify_token
|
||||||
from app.scripts import script1, script2
|
from app.scripts import script1, script2
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
||||||
|
class Payload(BaseModel):
|
||||||
|
name: str
|
||||||
|
action: str
|
||||||
|
|
||||||
@app.get("/")
|
@app.get("/")
|
||||||
def root():
|
def root():
|
||||||
return {"status": "API running"}
|
return {"status": "API running"}
|
||||||
|
|
||||||
@app.post("/script1")
|
@app.post("/script1")
|
||||||
def run_script1(auth=Depends(verify_token)):
|
def run_script1(payload: Payload,auth=Depends(verify_token)):
|
||||||
result = script1.run()
|
result = script1.run(payload)
|
||||||
return {"result": result}
|
return {"result": result}
|
||||||
|
|
||||||
@app.post("/script2")
|
@app.post("/script2")
|
||||||
def run_script2(auth=Depends(verify_token)):
|
def run_script2(payload: Payload, auth=Depends(verify_token)):
|
||||||
result = script2.run()
|
result = script2.run(payload)
|
||||||
return {"result": result}
|
return {"result": result}
|
||||||
@@ -1,2 +1,5 @@
|
|||||||
def run():
|
def run(data):
|
||||||
return "Script1 executed"
|
name = data.get("name")
|
||||||
|
action = data.get("action")
|
||||||
|
|
||||||
|
return f"{name} requested {action}"
|
||||||
Reference in New Issue
Block a user