File size: 1,440 Bytes
408b7e6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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()