learningview / core /secure_storage.py
ArrowDust's picture
LearnView Pro: Clean Production Build
408b7e6
Raw History Blame Contribute Delete
1.44 kB
import os
import asyncio
from config import DATA_PURGE_DELAY
from core.logger import log_debug, logger
class Shredder:
"""
Zero-Persistence Utility for Privacy Compliance.
Handles the deferred deletion of clinical artifacts.
"""
@staticmethod
async def deferred_purge(file_paths: list, delay: int = DATA_PURGE_DELAY):
"""
Independent self-destruct timer per session.
Ensures artifacts exist long enough for email dispatch but no longer.
"""
log_debug(f"🕒 Privacy: Shredder initialized. Waiting {delay}s for {len(file_paths)} files...")
# Non-blocking sleep allows the server to handle other requests
await asyncio.sleep(delay)
for path in file_paths:
if path and os.path.exists(path):
try:
# Overwrite check could be added here for military-grade shredding
os.remove(path)
log_debug(f"🛡️ Privacy: Shredded artifact -> {os.path.basename(path)}")
except Exception as e:
logger.error(f"❌ Shredder Error for {path}: {e}")
@staticmethod
def instant_purge(file_paths: list):
"""Immediate deletion for failed sessions or temporary intermediate files."""
for path in file_paths:
if path and os.path.exists(path):
os.remove(path)
shredder = Shredder()