Files
offline-db/blueprints/social.py
google-labs-jules[bot] 77ea4bc6f9 ✨ FEATURE: Implemented Dynamic Trending and Social Comment Systems
- Added 'Trending Now' engine based on 7-day watch history.
- Built a secure comment section with spoiler support and XSS prevention.
- Created new 'social' blueprint and expanded database schema.
- Updated Home and Player UI for dynamic content integration.
2026-01-16 09:12:57 +00:00

66 lines
2.0 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from flask import Blueprint, request, jsonify, session
import db
from datetime import datetime
social_bp = Blueprint('social', __name__)
@social_bp.route("/api/comments/<int:mal_id>/<int:ep>")
def get_comments(mal_id, ep):
"""Bölüm yorumlarını getir."""
anime = db.get_anime_by_mal_id(mal_id)
if not anime:
return jsonify([])
comments = db.get_comments_by_episode(anime['id'], ep)
# JSON serileştirme için datetime'ları string'e çevir
for c in comments:
if isinstance(c['created_at'], datetime):
c['created_at'] = c['created_at'].isoformat()
return jsonify(comments)
@social_bp.route("/api/comments", methods=["POST"])
def post_comment():
"""Yeni yorum yap."""
if "user_id" not in session:
return jsonify({"error": "Lütfen önce giriş yapın"}), 401
data = request.get_json()
mal_id = data.get("mal_id")
ep = data.get("episode")
content = data.get("content")
is_spoiler = data.get("is_spoiler", False)
if not content or len(content.strip()) < 2:
return jsonify({"error": "Yorum çok kısa"}), 400
anime = db.get_anime_by_mal_id(mal_id)
if not anime:
return jsonify({"error": "Anime bulunamadı"}), 404
comment_id = db.add_comment(
user_id=session["user_id"],
anime_id=anime['id'],
episode_number=ep,
content=content,
is_spoiler=is_spoiler
)
if comment_id:
return jsonify({"success": True, "comment_id": comment_id})
else:
return jsonify({"error": "Yorum eklenemedi"}), 500
@social_bp.route("/api/comments/<int:comment_id>", methods=["DELETE"])
def delete_comment(comment_id):
"""Yorumu sil."""
if "user_id" not in session:
return jsonify({"error": "Yetkisiz işlem"}), 401
success = db.delete_comment(comment_id, session["user_id"])
if success:
return jsonify({"success": True})
else:
return jsonify({"error": "Yorum silinemedi veya yetkiniz yok"}), 403