fix: Restore all files lost during destructive rebase
A previous `git pull --rebase origin main` dropped 177 local commits,
losing 3400+ files across admin-v2, backend, studio-v2, website,
klausur-service, and many other services. The partial restore attempt
(660295e2) only recovered some files.
This commit restores all missing files from pre-rebase ref 98933f5e
while preserving post-rebase additions (night-scheduler, night-mode UI,
NightModeWidget dashboard integration).
Restored features include:
- AI Module Sidebar (FAB), OCR Labeling, OCR Compare
- GPU Dashboard, RAG Pipeline, Magic Help
- Klausur-Korrektur (8 files), Abitur-Archiv (5+ files)
- Companion, Zeugnisse-Crawler, Screen Flow
- Full backend, studio-v2, website, klausur-service
- All compliance SDKs, agent-core, voice-service
- CI/CD configs, documentation, scripts
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
83
backend/ai_processor/utils.py
Normal file
83
backend/ai_processor/utils.py
Normal file
@@ -0,0 +1,83 @@
|
||||
"""
|
||||
AI Processor - Utility Functions
|
||||
|
||||
Image encoding and helper functions.
|
||||
"""
|
||||
|
||||
from pathlib import Path
|
||||
import base64
|
||||
import shutil
|
||||
import logging
|
||||
|
||||
from .config import BEREINIGT_DIR
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def encode_image_to_data_url(input_path: Path) -> str:
|
||||
"""
|
||||
Encode an image file to a data URL for API requests.
|
||||
|
||||
Args:
|
||||
input_path: Path to the image file
|
||||
|
||||
Returns:
|
||||
Data URL string (data:image/jpeg;base64,...)
|
||||
"""
|
||||
image_bytes = input_path.read_bytes()
|
||||
image_b64 = base64.b64encode(image_bytes).decode("utf-8")
|
||||
return f"data:image/jpeg;base64,{image_b64}"
|
||||
|
||||
|
||||
def encode_image_to_base64(input_path: Path) -> str:
|
||||
"""
|
||||
Encode an image file to base64 string.
|
||||
|
||||
Args:
|
||||
input_path: Path to the image file
|
||||
|
||||
Returns:
|
||||
Base64 encoded string
|
||||
"""
|
||||
image_bytes = input_path.read_bytes()
|
||||
return base64.b64encode(image_bytes).decode("utf-8")
|
||||
|
||||
|
||||
def dummy_process_scan(input_path: Path) -> Path:
|
||||
"""
|
||||
Simple copy to Bereinigt folder - kept as fallback.
|
||||
|
||||
Args:
|
||||
input_path: Path to input file
|
||||
|
||||
Returns:
|
||||
Path to copied file
|
||||
"""
|
||||
if not input_path.exists():
|
||||
raise FileNotFoundError(f"Eingabedatei nicht gefunden: {input_path}")
|
||||
new_name = input_path.stem + "_bereinigt" + input_path.suffix
|
||||
target = BEREINIGT_DIR / new_name
|
||||
shutil.copy2(input_path, target)
|
||||
return target
|
||||
|
||||
|
||||
def get_media_type(input_path: Path) -> str:
|
||||
"""
|
||||
Determine media type from file extension.
|
||||
|
||||
Args:
|
||||
input_path: Path to the file
|
||||
|
||||
Returns:
|
||||
MIME type string
|
||||
"""
|
||||
suffix = input_path.suffix.lower()
|
||||
media_types = {
|
||||
".jpg": "image/jpeg",
|
||||
".jpeg": "image/jpeg",
|
||||
".png": "image/png",
|
||||
".gif": "image/gif",
|
||||
".webp": "image/webp",
|
||||
".pdf": "application/pdf",
|
||||
}
|
||||
return media_types.get(suffix, "image/jpeg")
|
||||
Reference in New Issue
Block a user