feat(assets): Added new blueprint for sended images on api
This commit is contained in:
1 parent
0bf45f3386
commit
be3df1780b
2 files changed
+18
No files matched your search
@@ -0,0 +1,16 @@
|
|||||||
|
import os
|
||||||
|
from flask import Blueprint, send_from_directory, current_app, abort
|
||||||
|
|
||||||
|
assets_bp = Blueprint('assets', __name__)
|
||||||
|
|
||||||
|
# Маршрут поддерживает вложенные пути, например: /image/categories/main0.png
|
||||||
|
@assets_bp.route('/image/<path:filename>')
|
||||||
|
def serve_image(filename):
|
||||||
|
# Определяем абсолютный путь к папке assets относительно корня проекта
|
||||||
|
assets_path = os.path.join(current_app.root_path, 'assets')
|
||||||
|
|
||||||
|
# Проверяем наличие файла перед отправкой (опционально, send_from_directory сделает это сам)
|
||||||
|
if not os.path.exists(os.path.join(assets_path, filename)):
|
||||||
|
abort(404)
|
||||||
|
|
||||||
|
return send_from_directory(assets_path, filename)
|
||||||
@@ -7,6 +7,7 @@ from utils.loadDotENV import initializeENV
|
|||||||
from api.categories import api_category
|
from api.categories import api_category
|
||||||
from api.product import api_product
|
from api.product import api_product
|
||||||
from api.email import api_email
|
from api.email import api_email
|
||||||
|
from api.assets import assets_bp
|
||||||
from werkzeug.middleware.proxy_fix import ProxyFix
|
from werkzeug.middleware.proxy_fix import ProxyFix
|
||||||
|
|
||||||
# Инициализация
|
# Инициализация
|
||||||
@@ -22,6 +23,7 @@ CORS(app)
|
|||||||
app.register_blueprint(api_category)
|
app.register_blueprint(api_category)
|
||||||
app.register_blueprint(api_product)
|
app.register_blueprint(api_product)
|
||||||
app.register_blueprint(api_email)
|
app.register_blueprint(api_email)
|
||||||
|
app.register_blueprint(assets_bp)
|
||||||
|
|
||||||
app.wsgi_app = ProxyFix(app.wsgi_app, x_proto=1, x_host=1)
|
app.wsgi_app = ProxyFix(app.wsgi_app, x_proto=1, x_host=1)
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user