From 5d4ed0045206c7338b728992b06844bef0e22b9c Mon Sep 17 00:00:00 2001 From: Aaron Wagener Date: Wed, 10 Apr 2024 22:05:52 -0500 Subject: [PATCH] Webhost: add file downloads to the room api endpoint (#2780) --- WebHostLib/api/__init__.py | 23 +++++++++++++++++++++-- WebHostLib/templates/macros.html | 3 --- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/WebHostLib/api/__init__.py b/WebHostLib/api/__init__.py index 102c3a49f6aa..cfdbe25ff2fe 100644 --- a/WebHostLib/api/__init__.py +++ b/WebHostLib/api/__init__.py @@ -2,8 +2,9 @@ from typing import List, Tuple from uuid import UUID -from flask import Blueprint, abort +from flask import Blueprint, abort, url_for +import worlds.Files from .. import cache from ..models import Room, Seed @@ -21,12 +22,30 @@ def room_info(room: UUID): room = Room.get(id=room) if room is None: 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 { "tracker": room.tracker, "players": get_players(room.seed), "last_port": room.last_port, "last_activity": room.last_activity, - "timeout": room.timeout + "timeout": room.timeout, + "downloads": downloads, } diff --git a/WebHostLib/templates/macros.html b/WebHostLib/templates/macros.html index 9cb48009a427..7bbb894de090 100644 --- a/WebHostLib/templates/macros.html +++ b/WebHostLib/templates/macros.html @@ -47,9 +47,6 @@ {% elif patch.game | supports_apdeltapatch %} Download Patch File... - {% elif patch.game == "Dark Souls III" %} - - Download JSON File... {% elif patch.game == "Final Fantasy Mystic Quest" %} Download APMQ File...