Webhost: add file downloads to the room api endpoint (#2780)

This commit is contained in:
Aaron Wagener 2024-04-10 22:05:52 -05:00 committed by GitHub
parent 0ba6d90bb8
commit 5d4ed00452
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 5 deletions

View File

@ -2,8 +2,9 @@
from typing import List, Tuple from typing import List, Tuple
from uuid import UUID from uuid import UUID
from flask import Blueprint, abort from flask import Blueprint, abort, url_for
import worlds.Files
from .. import cache from .. import cache
from ..models import Room, Seed from ..models import Room, Seed
@ -21,12 +22,30 @@ def room_info(room: UUID):
room = Room.get(id=room) room = Room.get(id=room)
if room is None: if room is None:
return abort(404) return abort(404)
def supports_apdeltapatch(game: str):
return game in worlds.Files.AutoPatchRegister.patch_types
downloads = []
for slot in sorted(room.seed.slots):
if slot.data and not supports_apdeltapatch(slot.game):
slot_download = {
"slot": slot.player_id,
"download": url_for("download_slot_file", room_id=room.id, player_id=slot.player_id)
}
downloads.append(slot_download)
elif slot.data:
slot_download = {
"slot": slot.player_id,
"download": url_for("download_patch", patch_id=slot.id, room_id=room.id)
}
downloads.append(slot_download)
return { return {
"tracker": room.tracker, "tracker": room.tracker,
"players": get_players(room.seed), "players": get_players(room.seed),
"last_port": room.last_port, "last_port": room.last_port,
"last_activity": room.last_activity, "last_activity": room.last_activity,
"timeout": room.timeout "timeout": room.timeout,
"downloads": downloads,
} }

View File

@ -47,9 +47,6 @@
{% elif patch.game | supports_apdeltapatch %} {% elif patch.game | supports_apdeltapatch %}
<a href="{{ url_for("download_patch", patch_id=patch.id, room_id=room.id) }}" download> <a href="{{ url_for("download_patch", patch_id=patch.id, room_id=room.id) }}" download>
Download Patch File...</a> Download Patch File...</a>
{% elif patch.game == "Dark Souls III" %}
<a href="{{ url_for("download_slot_file", room_id=room.id, player_id=patch.player_id) }}" download>
Download JSON File...</a>
{% elif patch.game == "Final Fantasy Mystic Quest" %} {% elif patch.game == "Final Fantasy Mystic Quest" %}
<a href="{{ url_for("download_slot_file", room_id=room.id, player_id=patch.player_id) }}" download> <a href="{{ url_for("download_slot_file", room_id=room.id, player_id=patch.player_id) }}" download>
Download APMQ File...</a> Download APMQ File...</a>