+fetch file names function added

This commit is contained in:
AntoninoP 2024-09-10 21:22:58 +02:00
parent 4daf2ed654
commit a5d9ff716d
2 changed files with 32 additions and 0 deletions

1
app.py
View File

@ -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,

View File

@ -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):