Saketh-Reddy commited on
Commit
55af089
1 Parent(s): 66a0ed8

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +12 -22
main.py CHANGED
@@ -16,26 +16,16 @@ def read_root():
16
  return {"Hello": "World!"}
17
 
18
  @app.post("/webhook")
19
- async def post_webhook(
20
- payload: WebhookPayload,
21
- task_queue: BackgroundTasks,
22
- x_webhook_secret: Optional[str] = Header(default=None),
23
- ):
24
- if x_webhook_secret is None:
25
- raise HTTPException(401)
26
- if x_webhook_secret != "webhooksecret":
27
- raise HTTPException(403)
28
-
29
- if not (
30
- payload.event.action == "update"
31
- and payload.event.scope.startswith("repo.content")
32
- and payload.repo.name == "SakethTest/ThirdParty"
33
- and payload.repo.type == "model"
34
- ):
35
- # no-op
36
- return {"processed": False}
37
 
38
- snapshot_download(repo_id="SakethTest/ThirdParty",local_dir="./ThirdParty")
39
- api.upload_folder(folder_path="./ThirdParty",repo_id="shellplc/ThirdParty",repo_type="model",commit_message="uploaded third party model",token="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")
40
-
41
- return {"processed": True}
 
16
  return {"Hello": "World!"}
17
 
18
  @app.post("/webhook")
19
+ async def webhook(request: Request):
20
+ if request.method == "POST":
21
+ if request.headers.get("X-Webhook-Secret") != "webhooksecret":
22
+ return Response("Invalid secret", status_code=401)
23
+ data = await request.json()
24
+ result = create_or_update_report(data)
25
+ if(data["event"]["action"]=="update" and data["event"]["scope"]=="repo.content" and data["repo"]["type"]=="model"):
26
+ snapshot_download(repo_id="SakethTest/ThirdParty",local_dir="./ThirdParty")
27
+ api.upload_folder(folder_path="./ThirdParty",repo_id="shellplc/ThirdParty",repo_type="model",commit_message="uploaded third party model",token="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")
28
+ return {"processed": True}
29
+ else:
30
+ return {"processed": False}
 
 
 
 
 
 
31