mirror of
https://github.com/hubHarmony/servii-backend.git
synced 2024-11-17 21:40:31 +00:00
[+] Standard server field getter
This commit is contained in:
parent
8b90dc2c3d
commit
dec704f3c5
@ -6,7 +6,7 @@ import firebase_admin
|
|||||||
import jwt
|
import jwt
|
||||||
from firebase_admin import auth, credentials, firestore
|
from firebase_admin import auth, credentials, firestore
|
||||||
from google.api_core.exceptions import Aborted, DataLoss, NotFound, OutOfRange, PermissionDenied, ResourceExhausted
|
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
|
import file_manager
|
||||||
from generic_executor import mc_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"})
|
"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):
|
def delete_server(user_id: str, server_name: str):
|
||||||
user_ref = firestore_database.collection('users').document(user_id)
|
user_ref = firestore_database.collection('users').document(user_id)
|
||||||
servers_ref = user_ref.collection('servers')
|
servers_ref = user_ref.collection('servers')
|
||||||
|
Loading…
Reference in New Issue
Block a user