photo_processor.py: извлекаем логин из email
This commit is contained in:
@@ -81,6 +81,30 @@ def get_crop_coordinates(image_bytes: bytes) -> tuple | None:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def _check_moderation_status(user_id: str) -> dict:
|
||||||
|
"""
|
||||||
|
Проверяет текущий статус модерации пользователя.
|
||||||
|
Возвращает {'status': 'ok', 'moderation_status': 'pending'|'published'|'none', ...}
|
||||||
|
"""
|
||||||
|
# Извлекаем логин из email (user_id@tcs.sibcem.ru -> user_id)
|
||||||
|
login = user_id.split('@')[0]
|
||||||
|
|
||||||
|
status_url = API_URL.replace("/upload/", "/status/")
|
||||||
|
try:
|
||||||
|
response = requests.get(
|
||||||
|
status_url,
|
||||||
|
params={"user_id": login},
|
||||||
|
headers={"X-API-Key": API_KEY},
|
||||||
|
timeout=30,
|
||||||
|
verify=False
|
||||||
|
)
|
||||||
|
response.raise_for_status()
|
||||||
|
return response.json()
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Ошибка проверки статуса модерации: {e}")
|
||||||
|
return {"status": "error", "reason": f"Ошибка проверки статуса: {str(e)}"}
|
||||||
|
|
||||||
|
|
||||||
def _upload_to_api(image_bytes: bytes, user_id: str, coords: tuple) -> dict:
|
def _upload_to_api(image_bytes: bytes, user_id: str, coords: tuple) -> dict:
|
||||||
"""
|
"""
|
||||||
Отправляет фото и координаты в Django API.
|
Отправляет фото и координаты в Django API.
|
||||||
@@ -122,6 +146,15 @@ def prepare_ad_photo(input_path: str, user_id: str, output_path: str = None, tar
|
|||||||
output_path и target_size больше не используются (оставлены для обратной совместимости).
|
output_path и target_size больше не используются (оставлены для обратной совместимости).
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
|
# Проверяем статус модерации перед отправкой
|
||||||
|
status = _check_moderation_status(user_id)
|
||||||
|
if status.get("status") == "ok" and status.get("moderation_status") == "pending":
|
||||||
|
photo_id = status.get("photo_id", "???")
|
||||||
|
return {
|
||||||
|
"success": False,
|
||||||
|
"error": f"У вас уже есть фото на модерации (ID: {photo_id}). Дождитесь решения модератора."
|
||||||
|
}
|
||||||
|
|
||||||
# 1. Читаем байты
|
# 1. Читаем байты
|
||||||
if isinstance(input_path, bytes):
|
if isinstance(input_path, bytes):
|
||||||
image_bytes = input_path
|
image_bytes = input_path
|
||||||
|
|||||||
Reference in New Issue
Block a user