Merge pull request #29

+fetch file names function added
This commit is contained in:
charleslemaux 2024-09-11 00:43:55 +02:00 committed by GitHub
commit 3f154b93e4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
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):