Merge pull request 'Fix mai2 photo merge problem and Add UserScoreRankingAPI handler' (#2) from mai2_tournament_support into develop
Reviewed-on: https://gitea.tendokyu.moe/SoulGateKey/artemis/pulls/2pull/181/head
commit
7a307b4d69
|
@ -963,3 +963,6 @@ class Mai2Base:
|
||||||
userRecommendSelectionMusicIdList: list[int]
|
userRecommendSelectionMusicIdList: list[int]
|
||||||
"""
|
"""
|
||||||
return {"userId": data["userId"], "userRecommendSelectionMusicIdList": []}
|
return {"userId": data["userId"], "userRecommendSelectionMusicIdList": []}
|
||||||
|
async def handle_get_user_score_ranking_api_request(self, data: Dict) ->Dict:
|
||||||
|
|
||||||
|
return {"userId": data["userId"], "userScoreRanking": []}
|
|
@ -103,10 +103,10 @@ class Mai2Frontend(FE_Base):
|
||||||
if not path_index or int(path_index) < 1:
|
if not path_index or int(path_index) < 1:
|
||||||
index = 0
|
index = 0
|
||||||
else:
|
else:
|
||||||
index = int(path_index) - 1 # 0 and 1 are 1st page
|
index = int(path_index) - 1 # 0 and 1 are 1st page
|
||||||
user_id = usr_sesh.user_id
|
user_id = usr_sesh.user_id
|
||||||
playlog_count = await self.data.score.get_user_playlogs_count(user_id)
|
playlog_count = await self.data.score.get_user_playlogs_count(user_id)
|
||||||
if playlog_count < index * 20 :
|
if playlog_count < index * 20:
|
||||||
return Response(template.render(
|
return Response(template.render(
|
||||||
title=f"{self.core_config.server.name} | {self.nav_name}",
|
title=f"{self.core_config.server.name} | {self.nav_name}",
|
||||||
game_list=self.environment.globals["game_list"],
|
game_list=self.environment.globals["game_list"],
|
||||||
|
@ -116,17 +116,17 @@ class Mai2Frontend(FE_Base):
|
||||||
playlog = await self.data.score.get_playlogs(user_id, index, 20)
|
playlog = await self.data.score.get_playlogs(user_id, index, 20)
|
||||||
playlog_with_title = []
|
playlog_with_title = []
|
||||||
for record in playlog:
|
for record in playlog:
|
||||||
music_chart = await self.data.static.get_music_chart(usr_sesh.maimai_version, record.musicId, record.level)
|
music_chart = await self.data.static.get_music_chart(usr_sesh.maimai_version, record.musicId, record.level)
|
||||||
if music_chart:
|
if music_chart:
|
||||||
difficultyNum=music_chart.chartId
|
difficultyNum = music_chart.chartId
|
||||||
difficulty=music_chart.difficulty
|
difficulty = music_chart.difficulty
|
||||||
artist=music_chart.artist
|
artist = music_chart.artist
|
||||||
title=music_chart.title
|
title = music_chart.title
|
||||||
else:
|
else:
|
||||||
difficultyNum=0
|
difficultyNum = 0
|
||||||
difficulty=0
|
difficulty = 0
|
||||||
artist="unknown"
|
artist = "unknown"
|
||||||
title="musicid: " + str(record.musicId)
|
title = "musicid: " + str(record.musicId)
|
||||||
playlog_with_title.append({
|
playlog_with_title.append({
|
||||||
"raw": record,
|
"raw": record,
|
||||||
"title": title,
|
"title": title,
|
||||||
|
@ -195,7 +195,7 @@ class Mai2Frontend(FE_Base):
|
||||||
return RedirectResponse("/gate/", 303)
|
return RedirectResponse("/gate/", 303)
|
||||||
|
|
||||||
form_data = await request.form()
|
form_data = await request.form()
|
||||||
new_name: str = form_data.get("new_name")
|
new_name: str = form_data.get("new_name")
|
||||||
new_name_full = ""
|
new_name_full = ""
|
||||||
|
|
||||||
if not new_name:
|
if not new_name:
|
||||||
|
@ -204,7 +204,7 @@ class Mai2Frontend(FE_Base):
|
||||||
if len(new_name) > 8:
|
if len(new_name) > 8:
|
||||||
return RedirectResponse("/gate/?e=8", 303)
|
return RedirectResponse("/gate/?e=8", 303)
|
||||||
|
|
||||||
for x in new_name: # FIXME: This will let some invalid characters through atm
|
for x in new_name: # FIXME: This will let some invalid characters through atm
|
||||||
o = ord(x)
|
o = ord(x)
|
||||||
try:
|
try:
|
||||||
if o == 0x20:
|
if o == 0x20:
|
||||||
|
@ -240,8 +240,8 @@ class Mai2Frontend(FE_Base):
|
||||||
form_data = await request.form()
|
form_data = await request.form()
|
||||||
maimai_version = form_data.get("version")
|
maimai_version = form_data.get("version")
|
||||||
self.logger.info(f"version change to: {maimai_version}")
|
self.logger.info(f"version change to: {maimai_version}")
|
||||||
if(maimai_version.isdigit()):
|
if (maimai_version.isdigit()):
|
||||||
usr_sesh.maimai_version=int(maimai_version)
|
usr_sesh.maimai_version = int(maimai_version)
|
||||||
encoded_sesh = self.encode_session(usr_sesh)
|
encoded_sesh = self.encode_session(usr_sesh)
|
||||||
self.logger.debug(f"Created session with JWT {encoded_sesh}")
|
self.logger.debug(f"Created session with JWT {encoded_sesh}")
|
||||||
resp.set_cookie("ARTEMIS_SESH", encoded_sesh)
|
resp.set_cookie("ARTEMIS_SESH", encoded_sesh)
|
||||||
|
@ -282,12 +282,12 @@ class Mai2Frontend(FE_Base):
|
||||||
})
|
})
|
||||||
|
|
||||||
resp = Response(template.render(
|
resp = Response(template.render(
|
||||||
title=f"{self.core_config.server.name} | {self.nav_name} Events",
|
title=f"{self.core_config.server.name} | {self.nav_name} Events",
|
||||||
game_list=self.environment.globals["game_list"],
|
game_list=self.environment.globals["game_list"],
|
||||||
sesh=vars(usr_sesh),
|
sesh=vars(usr_sesh),
|
||||||
version_list=Mai2Constants.VERSION_STRING,
|
version_list=Mai2Constants.VERSION_STRING,
|
||||||
events=evts
|
events=evts
|
||||||
), media_type="text/html; charset=utf-8")
|
), media_type="text/html; charset=utf-8")
|
||||||
|
|
||||||
if incoming_ver < 0:
|
if incoming_ver < 0:
|
||||||
encoded_sesh = self.encode_session(usr_sesh)
|
encoded_sesh = self.encode_session(usr_sesh)
|
||||||
|
@ -315,14 +315,14 @@ class Mai2Frontend(FE_Base):
|
||||||
return RedirectResponse("/game/mai2/events/", 303)
|
return RedirectResponse("/game/mai2/events/", 303)
|
||||||
|
|
||||||
return Response(template.render(
|
return Response(template.render(
|
||||||
title=f"{self.core_config.server.name} | {self.nav_name} Edit Event {evt_id}",
|
title=f"{self.core_config.server.name} | {self.nav_name} Edit Event {evt_id}",
|
||||||
game_list=self.environment.globals["game_list"],
|
game_list=self.environment.globals["game_list"],
|
||||||
sesh=vars(usr_sesh),
|
sesh=vars(usr_sesh),
|
||||||
user_id=usr_sesh.user_id,
|
user_id=usr_sesh.user_id,
|
||||||
version_list=Mai2Constants.VERSION_STRING,
|
version_list=Mai2Constants.VERSION_STRING,
|
||||||
cur_version=usr_sesh.maimai_version,
|
cur_version=usr_sesh.maimai_version,
|
||||||
event=event_id._asdict()
|
event=event_id._asdict()
|
||||||
), media_type="text/html; charset=utf-8")
|
), media_type="text/html; charset=utf-8")
|
||||||
|
|
||||||
async def update_event(self, request: Request) -> RedirectResponse:
|
async def update_event(self, request: Request) -> RedirectResponse:
|
||||||
usr_sesh = self.validate_session(request)
|
usr_sesh = self.validate_session(request)
|
||||||
|
@ -335,7 +335,7 @@ class Mai2Frontend(FE_Base):
|
||||||
form_data = await request.form()
|
form_data = await request.form()
|
||||||
print(form_data)
|
print(form_data)
|
||||||
event_id: int = form_data.get("evtId", None)
|
event_id: int = form_data.get("evtId", None)
|
||||||
new_enabled: bool = bool(form_data.get("evtEnabled", False))
|
new_enabled: bool = bool(form_data.get("evtEnabled", False))
|
||||||
try:
|
try:
|
||||||
new_start_date: datetime = datetime.strptime(form_data.get("evtStart", None), "%Y-%m-%dT%H:%M:%S")
|
new_start_date: datetime = datetime.strptime(form_data.get("evtStart", None), "%Y-%m-%dT%H:%M:%S")
|
||||||
except:
|
except:
|
||||||
|
@ -383,14 +383,14 @@ class Mai2Frontend(FE_Base):
|
||||||
return Response(status_code=404)
|
return Response(status_code=404)
|
||||||
|
|
||||||
if path.exists(f"{out_folder}"):
|
if path.exists(f"{out_folder}"):
|
||||||
print("path exists")
|
self.logger.info(f"Photo Path Exist.")
|
||||||
max_idx = 0
|
max_idx = 0
|
||||||
p = ImageFile.Parser()
|
p = ImageFile.Parser()
|
||||||
for _, _, files in walk("out_folder"):
|
for _, _, files in walk(f"{out_folder}"):
|
||||||
if not files:
|
if not files:
|
||||||
break
|
break
|
||||||
|
|
||||||
matcher = re.match("^(\d+)_(\d+)$", files[0])
|
matcher = re.match(r"^(\d+)_(\d+)\.bin$", files[0])
|
||||||
if not matcher:
|
if not matcher:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
@ -405,11 +405,12 @@ class Mai2Frontend(FE_Base):
|
||||||
return Response(status_code=500)
|
return Response(status_code=500)
|
||||||
|
|
||||||
for i in range(max_idx + 1):
|
for i in range(max_idx + 1):
|
||||||
with open(f"{out_folder}/{i}_{max_idx}", "rb") as f:
|
with open(f"{out_folder}/{i}_{max_idx}.bin", "rb") as f:
|
||||||
p.feed(f.read())
|
p.feed(f.read())
|
||||||
try:
|
try:
|
||||||
im = p.close()
|
im = p.close()
|
||||||
im.save(f"{out_folder}.jpeg")
|
im.save(f"{out_folder}.jpeg")
|
||||||
|
self.logger.info(f"{out_folder}.jpeg generated.")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error(f"{photo_id} failed PIL validation! - {e}")
|
self.logger.error(f"{photo_id} failed PIL validation! - {e}")
|
||||||
|
@ -417,7 +418,7 @@ class Mai2Frontend(FE_Base):
|
||||||
shutil.rmtree(out_folder)
|
shutil.rmtree(out_folder)
|
||||||
|
|
||||||
if path.exists(f"{out_folder}.jpeg"):
|
if path.exists(f"{out_folder}.jpeg"):
|
||||||
print(f"{out_folder}.jpeg exists")
|
self.logger.info(f"{out_folder}.jpeg exists")
|
||||||
return FileResponse(f"{out_folder}.jpeg")
|
return FileResponse(f"{out_folder}.jpeg")
|
||||||
|
|
||||||
return Response(status_code=404)
|
return Response(status_code=404)
|
||||||
|
|
Loading…
Reference in New Issue