Open-source AI data analyst platform extracted from internal repo. Includes data sync engine, Keboola adapter, Flask web portal, server deployment scripts, and configuration templates.
35 lines
919 B
Python
35 lines
919 B
Python
"""
|
|
Notification image serving module.
|
|
|
|
Serves chart PNG images generated by notification runners.
|
|
Images are stored in /tmp/ by the notify-runner process.
|
|
"""
|
|
|
|
import logging
|
|
import re
|
|
from pathlib import Path
|
|
|
|
from flask import Blueprint, abort, send_file
|
|
|
|
from .config import Config
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
images_bp = Blueprint("images", __name__)
|
|
|
|
VALID_FILENAME_PATTERN = re.compile(r"^[a-zA-Z0-9_\-]+\.png$")
|
|
|
|
|
|
@images_bp.route("/api/notifications/images/<filename>")
|
|
def serve_notification_image(filename: str):
|
|
"""Serve a notification chart image from the temp directory."""
|
|
if not VALID_FILENAME_PATTERN.match(filename):
|
|
abort(404)
|
|
|
|
file_path = Path(Config.NOTIFICATION_IMAGES_DIR) / filename
|
|
if not file_path.is_file():
|
|
abort(404)
|
|
|
|
response = send_file(file_path, mimetype="image/png")
|
|
response.headers["Cache-Control"] = "no-cache"
|
|
return response
|