Compare commits
4 Commits
v1.4.2-rc.
...
v1.4.2-rc.
| Author | SHA1 | Date | |
|---|---|---|---|
| 25b8cbd79d | |||
| 042505d5a6 | |||
| 72f3d4a55e | |||
| e8ff0a0dcb |
@@ -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"))
|
||||||
|
|||||||
@@ -121,7 +121,22 @@ 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:
|
except Exception as heic_error:
|
||||||
|
# Log the magic bytes and save file for debugging (if in app context)
|
||||||
|
try:
|
||||||
|
magic = file_data[:12].hex() if len(file_data) >= 12 else file_data.hex()
|
||||||
|
current_app.logger.warning(
|
||||||
|
f'Media upload failed both Pillow and HEIC: filename="{filename}", '
|
||||||
|
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:
|
||||||
|
pass # Outside app context (e.g., tests)
|
||||||
raise ValueError(f"Invalid or corrupted image: {e}")
|
raise ValueError(f"Invalid or corrupted image: {e}")
|
||||||
else:
|
else:
|
||||||
raise ValueError(f"Invalid or corrupted image: {e}")
|
raise ValueError(f"Invalid or corrupted image: {e}")
|
||||||
@@ -155,7 +170,15 @@ 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")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user