steveagi commited on
Commit
9798bad
·
1 Parent(s): 776a6c0

add reset

Browse files
Files changed (3) hide show
  1. main.py +1 -1
  2. routers/game_util.py +9 -2
  3. routers/watermelon.py +5 -0
main.py CHANGED
@@ -3,5 +3,5 @@ from routers import root, snake, watermelon
3
 
4
  app = FastAPI()
5
  app.include_router(root.router)
6
- app.include_router(snake.router)
7
  app.include_router(watermelon.router)
 
 
3
 
4
  app = FastAPI()
5
  app.include_router(root.router)
 
6
  app.include_router(watermelon.router)
7
+ app.include_router(snake.router)
routers/game_util.py CHANGED
@@ -10,14 +10,21 @@ debug = False
10
 
11
 
12
  def op(game: str, code: str, crud: str, command: str, result="", desc="") -> Any:
13
- if crud not in "crud":
14
- raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
15
  _code = os.getenv("hfs_code")
16
  if _code is None:
17
  raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
18
  if code != _code:
19
  raise HTTPException(status.HTTP_511_NETWORK_AUTHENTICATION_REQUIRED)
20
 
 
 
 
 
 
 
 
 
21
  # url = f'https://{os.getenv("hfs_space")}.hf.space/games/{game}'
22
  url = f'https://{os.getenv("hfs_space")}.hf.space/games/{game}/nlp/{crud}'
23
  if debug:
 
10
 
11
 
12
  def op(game: str, code: str, crud: str, command: str, result="", desc="") -> Any:
13
+ # check passcode
 
14
  _code = os.getenv("hfs_code")
15
  if _code is None:
16
  raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
17
  if code != _code:
18
  raise HTTPException(status.HTTP_511_NETWORK_AUTHENTICATION_REQUIRED)
19
 
20
+ # handle reset
21
+ if crud == 'reset':
22
+ raise HTTPException(status_code=status.HTTP_501_NOT_IMPLEMENTED)
23
+
24
+ # handle c/r/u/d
25
+ if crud not in "crud":
26
+ raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
27
+
28
  # url = f'https://{os.getenv("hfs_space")}.hf.space/games/{game}'
29
  url = f'https://{os.getenv("hfs_space")}.hf.space/games/{game}/nlp/{crud}'
30
  if debug:
routers/watermelon.py CHANGED
@@ -25,3 +25,8 @@ def update(code: str=Body(), command: str=Body()):
25
  @router.post("/d")
26
  def delete(code: str=Body(), command: str=Body()):
27
  return game_util.op(GAME, code, "d", command)
 
 
 
 
 
 
25
  @router.post("/d")
26
  def delete(code: str=Body(), command: str=Body()):
27
  return game_util.op(GAME, code, "d", command)
28
+
29
+
30
+ @router.post("/reset")
31
+ def reset(code: str=Body()):
32
+ return game_util.op(GAME, code, "reset", "")