Skip to content

Commit

Permalink
Make the replay file in the table be a download link
Browse files Browse the repository at this point in the history
  • Loading branch information
max-torch committed May 3, 2024
1 parent 506194a commit 3d6b0e6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 13 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,15 +580,26 @@ def update_table(total_games, start_date, end_date):
(start_date, end_date),
)
columns = [i[0] for i in cursor.description]
replay_server_base_url = "https://replays.wesnoth.org"
df = (
pd.DataFrame(cursor.fetchall(), columns=columns)
.map(lambda x: x[0] if type(x) is bytes else x)
.assign(
START_TIME=lambda x: pd.to_datetime(x["START_TIME"]),
END_TIME=lambda x: pd.to_datetime(x["END_TIME"]),
# Calculate the game duration in minutes.
GAME_DURATION=lambda x: (x["END_TIME"] - x["START_TIME"]).dt.total_seconds()
/ 60,
/ 60, # Calculate the game duration in minutes.
REPLAY_NAME=lambda x: "["
+ x["REPLAY_NAME"]
+ "]("
+ replay_server_base_url
+ "/"
+ x["INSTANCE_VERSION"].str.slice(0, 4)
+ "/"
+ x["END_TIME"].dt.strftime("%Y/%m/%d")
+ "/"
+ x["REPLAY_NAME"]
+ ")", # Markdown link to replay file download

This comment has been minimized.

Copy link
@soliton-

soliton- May 15, 2024

Member

While the replay filename is not entirely arbitrary this essentially concatenates arbitrary data to hopefully get the desired markdown syntax. In general this kind of injection should be avoided but probably can't here.

If there is a convenient way to properly generate a markdown link that would be preferable. Otherwise need to check what can happen in the worst case. Given that brackets are currently not allowed in a replay filename probably not too much.

Of course another option would be to just not generate markdown and leave the url as a plain string.

)
)
cursor.close()
Expand Down
2 changes: 1 addition & 1 deletion pages/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
dash_table.DataTable(
id="table",
columns=[
{"name": column, "id": column}
{"name": column, "id": column} if column != "REPLAY_NAME" else {"name": column, "id": column, "presentation": "markdown"}
for column in column_names
],
editable=True,
Expand Down

0 comments on commit 3d6b0e6

Please sign in to comment.