add passcode
Browse files- games/game_angrybird.py +2 -2
- games/game_snake.py +2 -2
- games/game_util.py +9 -1
- main.py +4 -4
games/game_angrybird.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
import game_util
|
| 2 |
|
| 3 |
-
def process(command: str):
|
| 4 |
-
return game_util.util_process("angrybird", command)
|
|
|
|
| 1 |
import game_util
|
| 2 |
|
| 3 |
+
def process(passcode: str, command: str):
|
| 4 |
+
return game_util.util_process("angrybird", passcode, command)
|
games/game_snake.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
import game_util
|
| 2 |
|
| 3 |
-
def process(command: str):
|
| 4 |
-
return game_util.util_process("snake", command)
|
|
|
|
| 1 |
import game_util
|
| 2 |
|
| 3 |
+
def process(passcode: str, command: str):
|
| 4 |
+
return game_util.util_process("snake", passcode, command)
|
games/game_util.py
CHANGED
|
@@ -2,8 +2,16 @@ import os
|
|
| 2 |
import json
|
| 3 |
import requests
|
| 4 |
|
|
|
|
| 5 |
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
url = f'https://{os.getenv("hfs_space")}.hf.space/games/{game}'
|
| 8 |
# url = 'http://127.0.0.1:8080/nlp'
|
| 9 |
myobj = {
|
|
|
|
| 2 |
import json
|
| 3 |
import requests
|
| 4 |
|
| 5 |
+
from fastapi import HTTPException, status
|
| 6 |
|
| 7 |
+
|
| 8 |
+
def util_process(game: str, passcode: str, command: str):
|
| 9 |
+
code = os.getenv("hfs_code")
|
| 10 |
+
if code is None:
|
| 11 |
+
raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
|
| 12 |
+
if passcode != code:
|
| 13 |
+
raise HTTPException(status.HTTP_511_NETWORK_AUTHENTICATION_REQUIRED)
|
| 14 |
+
|
| 15 |
url = f'https://{os.getenv("hfs_space")}.hf.space/games/{game}'
|
| 16 |
# url = 'http://127.0.0.1:8080/nlp'
|
| 17 |
myobj = {
|
main.py
CHANGED
|
@@ -12,10 +12,10 @@ def root():
|
|
| 12 |
|
| 13 |
|
| 14 |
@app.post("/games/snake")
|
| 15 |
-
def main_snake(command: str=Body(embed=True)):
|
| 16 |
-
return game_snake.process(command)
|
| 17 |
|
| 18 |
|
| 19 |
@app.post("/games/angrybird")
|
| 20 |
-
def main_angrybird(command: str=Body(embed=True)):
|
| 21 |
-
return game_angrybird.process(command)
|
|
|
|
| 12 |
|
| 13 |
|
| 14 |
@app.post("/games/snake")
|
| 15 |
+
def main_snake(passcode: str, command: str=Body(embed=True)):
|
| 16 |
+
return game_snake.process(passcode, command)
|
| 17 |
|
| 18 |
|
| 19 |
@app.post("/games/angrybird")
|
| 20 |
+
def main_angrybird(passcode: str, command: str=Body(embed=True)):
|
| 21 |
+
return game_angrybird.process(passcode, command)
|