Create Api
Browse files
Api
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI, HTTPException, Request
|
2 |
+
from fastapi.middleware.cors import CORSMiddleware
|
3 |
+
import json
|
4 |
+
app = FastAPI()
|
5 |
+
@app.post("/get_callback")
|
6 |
+
async def get_callback(request: Request):
|
7 |
+
try:
|
8 |
+
json_data = await request.json()
|
9 |
+
challenge = json_data.get("challenge")
|
10 |
+
if challenge is not None:
|
11 |
+
# is a verification request, just return the challenge
|
12 |
+
return {"challenge": challenge}
|
13 |
+
else:
|
14 |
+
# is a callback request, do your own logic here
|
15 |
+
# {
|
16 |
+
# "task_id": "115334141465231360",
|
17 |
+
# "status": "Success",
|
18 |
+
# "file_id": "205258526306433",
|
19 |
+
# "base_resp": {
|
20 |
+
# "status_code": 0,
|
21 |
+
# "status_msg": "success"
|
22 |
+
# }
|
23 |
+
# }
|
24 |
+
return {"status": "success"}
|
25 |
+
except Exception as e:
|
26 |
+
raise HTTPException(status_code=500, detail=str(e))
|
27 |
+
if __name__ == "__main__":
|
28 |
+
import uvicorn
|
29 |
+
uvicorn.run(
|
30 |
+
app, # required
|
31 |
+
host="0.0.0.0", # Required
|
32 |
+
port=8000, # Required, the port can be configured.
|
33 |
+
# ssl_keyfile='yourname.yourDomainName.com.key', # Optional, check whether SSL is enabled.
|
34 |
+
# ssl_certfile='yourname.yourDomainName.com.key', # Optional, check whether SSL is enabled.
|
35 |
+
)
|