From dec704f3c5f1b364fc9f26c88b9a1619f68a5eaa Mon Sep 17 00:00:00 2001 From: Charles Le Maux Date: Fri, 13 Sep 2024 04:00:14 +0200 Subject: [PATCH] [+] Standard server field getter --- firebase_manager.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/firebase_manager.py b/firebase_manager.py index 6db0a6d..cb73a4f 100644 --- a/firebase_manager.py +++ b/firebase_manager.py @@ -6,7 +6,7 @@ import firebase_admin import jwt from firebase_admin import auth, credentials, firestore from google.api_core.exceptions import Aborted, DataLoss, NotFound, OutOfRange, PermissionDenied, ResourceExhausted -from google.cloud.firestore_v1 import FieldFilter +from google.cloud.firestore_v1 import FieldFilter, DocumentReference import file_manager from generic_executor import mc_manager @@ -133,6 +133,21 @@ def create_server(user_id: str, server_name: str, version: str, port: int, frame "enableCommandBlock": "false"}) +def get_server_field(user_id: str, name: str, field_name: str) -> Union[str, bool, None]: + try: + server_doc: DocumentReference = firestore_database.document(f'users/{user_id}/servers/{name}') + doc = server_doc.get() + if doc.exists: + field = doc.to_dict().get(field_name) + return field + else: + return None + except (NotFound, PermissionDenied, Aborted, ResourceExhausted, + OutOfRange, DataLoss, TypeError, Exception, ValueError) as e: + log_exception_to_firestore(e, user_id, {"function": "get_server_field", "name": name, "field": field_name}) + return None + + def delete_server(user_id: str, server_name: str): user_ref = firestore_database.collection('users').document(user_id) servers_ref = user_ref.collection('servers')