Compare commits
5 Commits
v1.4.2-rc.
...
v1.4.2-rc.
| Author | SHA1 | Date | |
|---|---|---|---|
| 6682339a86 | |||
| d416463242 | |||
| 25b8cbd79d | |||
| 042505d5a6 | |||
| 72f3d4a55e |
@@ -12,9 +12,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
### Added
|
### Added
|
||||||
|
|
||||||
- HEIC/HEIF image format support for iPhone photo uploads
|
- HEIC/HEIF image format support for iPhone photo uploads
|
||||||
- Automatic HEIC to JPEG conversion (browsers cannot display HEIC)
|
- MPO (Multi-Picture Object) format support for iPhone depth/portrait photos
|
||||||
|
- Automatic HEIC/MPO to JPEG conversion (browsers cannot display these formats)
|
||||||
- Graceful error handling if pillow-heif library not installed
|
- Graceful error handling if pillow-heif library not installed
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Increased maximum input image dimensions from 4096x4096 to 12000x12000 to support modern phone cameras (48MP+); images are still optimized to smaller sizes for web delivery
|
||||||
|
|
||||||
### Dependencies
|
### Dependencies
|
||||||
|
|
||||||
- Added `pillow-heif` for HEIC image processing
|
- Added `pillow-heif` for HEIC image processing
|
||||||
|
|||||||
@@ -86,6 +86,10 @@ def load_config(app, config_override=None):
|
|||||||
app.config["FEED_CACHE_ENABLED"] = os.getenv("FEED_CACHE_ENABLED", "true").lower() == "true"
|
app.config["FEED_CACHE_ENABLED"] = os.getenv("FEED_CACHE_ENABLED", "true").lower() == "true"
|
||||||
app.config["FEED_CACHE_MAX_SIZE"] = int(os.getenv("FEED_CACHE_MAX_SIZE", "50"))
|
app.config["FEED_CACHE_MAX_SIZE"] = int(os.getenv("FEED_CACHE_MAX_SIZE", "50"))
|
||||||
|
|
||||||
|
# Upload limits (v1.4.2)
|
||||||
|
# Flask MAX_CONTENT_LENGTH limits request body size (matches media.py MAX_FILE_SIZE)
|
||||||
|
app.config["MAX_CONTENT_LENGTH"] = 50 * 1024 * 1024 # 50MB
|
||||||
|
|
||||||
# Metrics configuration (v1.1.2 Phase 1)
|
# Metrics configuration (v1.1.2 Phase 1)
|
||||||
app.config["METRICS_ENABLED"] = os.getenv("METRICS_ENABLED", "true").lower() == "true"
|
app.config["METRICS_ENABLED"] = os.getenv("METRICS_ENABLED", "true").lower() == "true"
|
||||||
app.config["METRICS_SLOW_QUERY_THRESHOLD"] = float(os.getenv("METRICS_SLOW_QUERY_THRESHOLD", "1.0"))
|
app.config["METRICS_SLOW_QUERY_THRESHOLD"] = float(os.getenv("METRICS_SLOW_QUERY_THRESHOLD", "1.0"))
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ ALLOWED_MIME_TYPES = {
|
|||||||
# Limits per Q&A and ADR-058 (updated in v1.4.0)
|
# Limits per Q&A and ADR-058 (updated in v1.4.0)
|
||||||
MAX_FILE_SIZE = 50 * 1024 * 1024 # 50MB (v1.4.0)
|
MAX_FILE_SIZE = 50 * 1024 * 1024 # 50MB (v1.4.0)
|
||||||
MAX_OUTPUT_SIZE = 10 * 1024 * 1024 # 10MB target after optimization (v1.4.0)
|
MAX_OUTPUT_SIZE = 10 * 1024 * 1024 # 10MB target after optimization (v1.4.0)
|
||||||
MAX_DIMENSION = 4096 # 4096x4096 max
|
MAX_DIMENSION = 12000 # 12000x12000 max input (v1.4.2 - supports modern phone cameras)
|
||||||
RESIZE_DIMENSION = 2048 # Auto-resize to 2048px (default)
|
RESIZE_DIMENSION = 2048 # Auto-resize to 2048px (default)
|
||||||
MIN_QUALITY = 70 # Minimum JPEG quality before rejection (v1.4.0)
|
MIN_QUALITY = 70 # Minimum JPEG quality before rejection (v1.4.0)
|
||||||
MIN_DIMENSION = 640 # Minimum dimension before rejection (v1.4.0)
|
MIN_DIMENSION = 640 # Minimum dimension before rejection (v1.4.0)
|
||||||
@@ -122,13 +122,19 @@ def validate_image(file_data: bytes, filename: str) -> Tuple[bytes, str, int, in
|
|||||||
# Mark as HEIF so conversion happens below
|
# Mark as HEIF so conversion happens below
|
||||||
img.format = 'HEIF'
|
img.format = 'HEIF'
|
||||||
except Exception as heic_error:
|
except Exception as heic_error:
|
||||||
# Log the magic bytes for debugging (if in app context)
|
# Log the magic bytes and save file for debugging (if in app context)
|
||||||
try:
|
try:
|
||||||
magic = file_data[:12].hex() if len(file_data) >= 12 else file_data.hex()
|
magic = file_data[:12].hex() if len(file_data) >= 12 else file_data.hex()
|
||||||
current_app.logger.warning(
|
current_app.logger.warning(
|
||||||
f'Media upload failed both Pillow and HEIC: filename="{filename}", '
|
f'Media upload failed both Pillow and HEIC: filename="{filename}", '
|
||||||
f'magic_bytes={magic}, pillow_error="{e}", heic_error="{heic_error}"'
|
f'magic_bytes={magic}, pillow_error="{e}", heic_error="{heic_error}"'
|
||||||
)
|
)
|
||||||
|
# Save failed file for analysis
|
||||||
|
debug_dir = Path(current_app.config.get('DATA_PATH', 'data')) / 'debug'
|
||||||
|
debug_dir.mkdir(parents=True, exist_ok=True)
|
||||||
|
debug_file = debug_dir / f"failed_{datetime.now().strftime('%Y%m%d_%H%M%S')}_{filename}"
|
||||||
|
debug_file.write_bytes(file_data)
|
||||||
|
current_app.logger.info(f'Saved failed upload for analysis: {debug_file}')
|
||||||
except RuntimeError:
|
except RuntimeError:
|
||||||
pass # Outside app context (e.g., tests)
|
pass # Outside app context (e.g., tests)
|
||||||
raise ValueError(f"Invalid or corrupted image: {e}")
|
raise ValueError(f"Invalid or corrupted image: {e}")
|
||||||
@@ -154,6 +160,18 @@ def validate_image(file_data: bytes, filename: str) -> Tuple[bytes, str, int, in
|
|||||||
file_data = output.getvalue()
|
file_data = output.getvalue()
|
||||||
img = Image.open(io.BytesIO(file_data))
|
img = Image.open(io.BytesIO(file_data))
|
||||||
|
|
||||||
|
# MPO (Multi-Picture Object) conversion (v1.4.2)
|
||||||
|
# MPO is used by iPhones for depth/portrait photos - extract primary image as JPEG
|
||||||
|
if img.format == 'MPO':
|
||||||
|
output = io.BytesIO()
|
||||||
|
# Convert to RGB if needed
|
||||||
|
if img.mode in ('RGBA', 'P'):
|
||||||
|
img = img.convert('RGB')
|
||||||
|
img.save(output, format='JPEG', quality=95)
|
||||||
|
output.seek(0)
|
||||||
|
file_data = output.getvalue()
|
||||||
|
img = Image.open(io.BytesIO(file_data))
|
||||||
|
|
||||||
# Check format is allowed
|
# Check format is allowed
|
||||||
if img.format:
|
if img.format:
|
||||||
format_lower = img.format.lower()
|
format_lower = img.format.lower()
|
||||||
@@ -164,11 +182,20 @@ def validate_image(file_data: bytes, filename: str) -> Tuple[bytes, str, int, in
|
|||||||
mime_type = 'image/jpeg'
|
mime_type = 'image/jpeg'
|
||||||
|
|
||||||
if mime_type not in ALLOWED_MIME_TYPES:
|
if mime_type not in ALLOWED_MIME_TYPES:
|
||||||
raise ValueError(f"Invalid image format. Accepted: JPEG, PNG, GIF, WebP")
|
# Log the detected format for debugging (v1.4.2)
|
||||||
|
try:
|
||||||
|
current_app.logger.warning(
|
||||||
|
f'Media upload rejected format: filename="{filename}", '
|
||||||
|
f'detected_format="{img.format}", mime_type="{mime_type}"'
|
||||||
|
)
|
||||||
|
except RuntimeError:
|
||||||
|
pass # Outside app context
|
||||||
|
raise ValueError(f"Invalid image format '{img.format}'. Accepted: JPEG, PNG, GIF, WebP")
|
||||||
else:
|
else:
|
||||||
raise ValueError("Could not determine image format")
|
raise ValueError("Could not determine image format")
|
||||||
|
|
||||||
# Check dimensions
|
# Check dimensions (v1.4.2: increased to 12000px to support modern phone cameras)
|
||||||
|
# Images will be resized by optimize_image() anyway
|
||||||
width, height = img.size
|
width, height = img.size
|
||||||
if max(width, height) > MAX_DIMENSION:
|
if max(width, height) > MAX_DIMENSION:
|
||||||
raise ValueError(f"Image dimensions too large. Maximum is {MAX_DIMENSION}x{MAX_DIMENSION} pixels")
|
raise ValueError(f"Image dimensions too large. Maximum is {MAX_DIMENSION}x{MAX_DIMENSION} pixels")
|
||||||
|
|||||||
@@ -127,8 +127,8 @@ class TestImageValidation:
|
|||||||
assert "File too large" in str(exc_info.value)
|
assert "File too large" in str(exc_info.value)
|
||||||
|
|
||||||
def test_dimensions_too_large(self):
|
def test_dimensions_too_large(self):
|
||||||
"""Test rejection of >4096px image (per ADR-058)"""
|
"""Test rejection of >12000px image (v1.4.2: increased from 4096)"""
|
||||||
large_image = create_test_image(5000, 5000, 'PNG')
|
large_image = create_test_image(13000, 13000, 'PNG')
|
||||||
|
|
||||||
with pytest.raises(ValueError) as exc_info:
|
with pytest.raises(ValueError) as exc_info:
|
||||||
validate_image(large_image, 'huge.png')
|
validate_image(large_image, 'huge.png')
|
||||||
|
|||||||
Reference in New Issue
Block a user