37 lines
1.2 KiB
Python
37 lines
1.2 KiB
Python
import os
|
|
import mimetypes
|
|
from flask import Blueprint, jsonify, send_file
|
|
from .auth import token_required
|
|
|
|
perfil = Blueprint('perfil', __name__)
|
|
|
|
def get_protected_image_path(filename):
|
|
# Definindo o caminho base UNC corretamente, sem modificá-lo
|
|
base_directory = r"\\10.10.253.56\\Backend\\itguys\\ambiente_python\\repositorio_img"
|
|
|
|
# Concatene o caminho do arquivo com base_directory
|
|
file_path = os.path.join(base_directory, filename)
|
|
print(f"Caminho gerado para a imagem: {file_path}")
|
|
|
|
# Verifique se o caminho de file_path está dentro do diretório base_directory
|
|
if os.path.commonpath([base_directory, file_path]) == base_directory:
|
|
return file_path
|
|
else:
|
|
return None
|
|
|
|
@perfil.route('/repositorio_img/<path:filename>', methods=['GET'])
|
|
@token_required
|
|
def get_profile_picture(data, filename):
|
|
file_path = get_protected_image_path(filename)
|
|
|
|
if file_path and os.path.isfile(file_path):
|
|
mimetype, _ = mimetypes.guess_type(file_path)
|
|
if not mimetype:
|
|
mimetype = 'application/octet-stream'
|
|
return send_file(file_path, mimetype=mimetype)
|
|
else:
|
|
return jsonify({'msg': 'Imagem não encontrada ou acesso não permitido'}), 404
|
|
|
|
|
|
|