MCPcopy Create free account
hub / github.com/dedsec1121fk/DedSec / _filestorage_size

Function _filestorage_size

Scripts/ButSystem.py:464–502  ·  view source on GitHub ↗

Return the size (bytes) of an uploaded FileStorage if possible. We prefer stream seeking because Content-Length is not always available for multipart parts on all clients.

(file_storage)

Source from the content-addressed store, hash-verified

462 if buffered:
463 print(f"STARTUP ERRORS FOUND: {len(buffered)}")
464 for item in buffered:
465 print("\n[ButSystem ERROR] " + item)
466 else:
467 print("ERROR MONITOR: No errors detected during startup.")
468 sys.stdout.flush()
469
470# ---------------------------
471# Crypto helpers (TEXT encryption only; binary files stored plaintext)
472# ---------------------------
473
474MAGIC = b"BUTSYS1"
475NONCE_LEN = 12
476TAG_LEN = 16
477HDR_LEN = len(MAGIC) + NONCE_LEN + TAG_LEN
478CHUNK = 4 * 1024 * 1024 # 4 MiB chunks for fast encrypted streaming (low RAM + good throughput)
479
480def load_or_create_master_key() -> bytes:
481 """load_or_create_master_key.
482
483Internal helper function.
484
485This docstring was added automatically to improve maintainability.
486
487Returns:
488 Varies.
489"""
490 if os.path.exists(MASTER_KEY_PATH):
491 raw = open(MASTER_KEY_PATH, "rb").read().strip()
492 key = base64.urlsafe_b64decode(raw)
493 if len(key) != 32:
494 raise RuntimeError("Invalid master key length.")
495 return key
496 key = os.urandom(32)
497 with open(MASTER_KEY_PATH, "wb") as f:
498 f.write(base64.urlsafe_b64encode(key))
499 try:
500 os.chmod(MASTER_KEY_PATH, 0o600)
501 except Exception:
502 pass
503 return key
504
505MASTER_KEY = load_or_create_master_key()

Callers 6

uploadFunction · 0.70
dm_sendFunction · 0.70
group_sendFunction · 0.70
_validate_report_uploadFunction · 0.70
discussion_sendFunction · 0.70
_story_store_uploadFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected