feat: Add Advoware History and Watcher services for document synchronization
- Implement AdvowareHistoryService for fetching and creating history entries. - Implement AdvowareWatcherService for file operations including listing, downloading, and uploading with Blake3 hash verification. - Introduce Blake3 utility functions for hash computation and verification. - Create document sync cron step to poll Redis for pending Aktennummern and emit sync events. - Develop document sync event handler to manage 3-way merge synchronization for Akten, including metadata updates and error handling.
This commit is contained in:
47
services/blake3_utils.py
Normal file
47
services/blake3_utils.py
Normal file
@@ -0,0 +1,47 @@
|
||||
"""
|
||||
Blake3 Hash Utilities
|
||||
|
||||
Provides Blake3 hash computation for file integrity verification.
|
||||
"""
|
||||
|
||||
from typing import Union
|
||||
|
||||
|
||||
def compute_blake3(content: bytes) -> str:
|
||||
"""
|
||||
Compute Blake3 hash of content.
|
||||
|
||||
Args:
|
||||
content: File bytes
|
||||
|
||||
Returns:
|
||||
Hex string (lowercase)
|
||||
|
||||
Raises:
|
||||
ImportError: If blake3 module not installed
|
||||
"""
|
||||
try:
|
||||
import blake3
|
||||
except ImportError:
|
||||
raise ImportError(
|
||||
"blake3 module not installed. Install with: pip install blake3"
|
||||
)
|
||||
|
||||
hasher = blake3.blake3()
|
||||
hasher.update(content)
|
||||
return hasher.hexdigest()
|
||||
|
||||
|
||||
def verify_blake3(content: bytes, expected_hash: str) -> bool:
|
||||
"""
|
||||
Verify Blake3 hash of content.
|
||||
|
||||
Args:
|
||||
content: File bytes
|
||||
expected_hash: Expected hex hash (lowercase)
|
||||
|
||||
Returns:
|
||||
True if hash matches, False otherwise
|
||||
"""
|
||||
computed = compute_blake3(content)
|
||||
return computed.lower() == expected_hash.lower()
|
||||
Reference in New Issue
Block a user