Add image-reset call
This commit is contained in:
parent
053f577c45
commit
60a4910735
@ -1,3 +1,4 @@
|
||||
import datetime
|
||||
import os.path
|
||||
import base64
|
||||
|
||||
@ -688,6 +689,39 @@ async def post_players(new_player: PlayerPydantic, token: str = Depends(oauth2_s
|
||||
return return_val
|
||||
|
||||
|
||||
@router.post('/{player_id}/image-reset')
|
||||
async def post_image_reset(player_id: int, dev: bool = False, token: str = Depends(oauth2_scheme)):
|
||||
if not valid_token(token):
|
||||
logging.warning(f'Bad Token: {token}')
|
||||
db.close()
|
||||
raise HTTPException(
|
||||
status_code=401,
|
||||
detail='You are not authorized to modify players. This event has been logged.'
|
||||
)
|
||||
|
||||
this_player = Player.get_or_none(Player.player_id == player_id)
|
||||
if this_player is None:
|
||||
db.close()
|
||||
raise HTTPException(status_code=404, detail=f'Player ID {player_id} not found')
|
||||
|
||||
now = datetime.datetime.now()
|
||||
today_url = f'https://pd{"dev" if dev else ""}.manticorum.com/api/v2/players/{player_id}/' \
|
||||
f'{"pitch" if "pitch" in this_player.image else "batt"}ingcard?d={now.year}-{now.month}-{now.day}'
|
||||
logging.debug(f'image1 url: {today_url}')
|
||||
this_player.image = today_url
|
||||
|
||||
if this_player.image2 is not None:
|
||||
today_url = f'https://pd{"dev" if dev else ""}.manticorum.com/api/v2/players/{player_id}/' \
|
||||
f'{"pitch" if "pitch" in this_player.image2 else "batt"}ingcard?d={now.year}-{now.month}-{now.day}'
|
||||
logging.debug(f'image2 url: {today_url}')
|
||||
this_player.image2 = today_url
|
||||
|
||||
this_player.save()
|
||||
r_player = model_to_dict(this_player)
|
||||
db.close()
|
||||
return r_player
|
||||
|
||||
|
||||
@router.delete('/{player_id}')
|
||||
async def delete_player(player_id, token: str = Depends(oauth2_scheme)):
|
||||
if not valid_token(token):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user