minor fixes

This commit is contained in:
Michael Woods
2025-01-06 20:52:19 -05:00
parent 8be3c3683d
commit 0a2b1f5e37

View File

@@ -14,6 +14,7 @@ import uuid
from uuid import UUID from uuid import UUID
from packetserver.server.users import User, user_authorized from packetserver.server.users import User, user_authorized
from collections import namedtuple from collections import namedtuple
from traceback import format_exc
class Object(persistent.Persistent): class Object(persistent.Persistent):
def __init__(self, name: str = "", data: Union[bytes,bytearray,str] = None): def __init__(self, name: str = "", data: Union[bytes,bytearray,str] = None):
@@ -165,6 +166,7 @@ class Object(persistent.Persistent):
@classmethod @classmethod
def from_dict(cls, obj: dict) -> Self: def from_dict(cls, obj: dict) -> Self:
o = Object(name=obj['name']) o = Object(name=obj['name'])
if obj['uuid_bytes']:
o._uuid = UUID(bytes=obj['uuid_bytes']) o._uuid = UUID(bytes=obj['uuid_bytes'])
o.private = obj['private'] o.private = obj['private']
o.data = obj['data'] o.data = obj['data']
@@ -309,12 +311,14 @@ def handle_object_post(req: Request, conn: PacketServerConnection, db: ZODB.DB):
try: try:
obj = Object.from_dict(req.payload) obj = Object.from_dict(req.payload)
except: except:
logging.debug(f"Error parsing new object:\n{format_exc()}")
send_blank_response(conn, req, status_code=400) send_blank_response(conn, req, status_code=400)
return return
obj.write_new(db) obj.write_new(db)
username = ax25.Address(conn.remote_callsign).call.upper().strip() username = ax25.Address(conn.remote_callsign).call.upper().strip()
obj.chown(username, db) obj.chown(username, db)
send_blank_response(conn, req, 201, str(obj.uuid))
def object_root_handler(req: Request, conn: PacketServerConnection, db: ZODB.DB): def object_root_handler(req: Request, conn: PacketServerConnection, db: ZODB.DB):
logging.debug(f"{req} being processed by user_root_handler") logging.debug(f"{req} being processed by user_root_handler")