diff --git a/app.py b/app.py index 5ef04eb..4640025 100644 --- a/app.py +++ b/app.py @@ -90,6 +90,7 @@ route_handlers = { 'SetSubdomain': generic_executor.set_subdomain, 'FetchServers': generic_executor.fetch_servers, 'FetchLogs': generic_executor.fetch_logs, + 'FetchFilenames': generic_executor.fetch_players_status, 'FetchHistory': generic_executor.fetch_history, 'FetchPlayersStatus': generic_executor.fetch_players_status, 'AccountCreate': generic_executor.account_create, diff --git a/generic_executor.py b/generic_executor.py index f0fac3b..0cfdb67 100644 --- a/generic_executor.py +++ b/generic_executor.py @@ -120,6 +120,37 @@ def fetch_players_status(user: UserRecord, name: str) -> tuple[HTTPStatus, Union file_manager.log_error(type(e).__name__, str(e)) return HTTPStatus.INTERNAL_SERVER_ERROR, "Unknown error." +def fetch_file_names(user: UserRecord, name: str) -> tuple[HTTPStatus, Union[dict[str, list[str]], str]]: + user_id: str = user.uid + server_path: str = f"users/{user_id}/{name}" + plugins_dir: str = f"{server_path}/plugins" + datapacks_dir: str = f"{server_path}/world/datapacks" + + file_names = { + "plugins": [], + "datapacks": [] + } + + try: + #plugins + if os.path.exists(plugins_dir): + file_names["plugins"] = os.listdir(plugins_dir) + else: + return HTTPStatus.NOT_FOUND, f"Plugins directory not found for server '{name}'." + + #datapacks + if os.path.exists(datapacks_dir): + file_names["datapacks"] = os.listdir(datapacks_dir) + else: + return HTTPStatus.NOT_FOUND, f"Datapacks directory not found for server '{name}'." + + return HTTPStatus.OK, file_names + + except Exception as e: + file_manager.log_error(type(e).__name__, str(e)) + return HTTPStatus.INTERNAL_SERVER_ERROR, f"Error fetching file names: {str(e)}" + + def account_create(user: UserRecord) -> tuple[HTTPStatus, Union[str, None]]: if firebase_manager.user_field_exists(user.uid):