Spaces:
Sleeping
Sleeping
Download core/secure_storage.py from clabs/learningview: direct link, hf CLI and curl.
- Browser
- Download file 1.44 kB
-
https://huggingface.co/spaces/clabs/learningview/resolve/main/core/secure_storage.py
- Command line
-
hf download hf://spaces/clabs/learningview/core/secure_storage.py
-
curl -L -o secure_storage.py https://huggingface.co/spaces/clabs/learningview/resolve/main/core/secure_storage.py
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. | |
| """ | |
| 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}") | |
| 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() |