Update app.py
Browse files
app.py
CHANGED
|
@@ -27,22 +27,25 @@ def load_data():
|
|
| 27 |
data = json.load(file)
|
| 28 |
if not isinstance(data, dict):
|
| 29 |
logging.warning("Data is not in dict format, initializing empty database")
|
| 30 |
-
return {'posts': [], 'users': {}, 'general_chat': []}
|
| 31 |
if 'posts' not in data:
|
| 32 |
data['posts'] = []
|
| 33 |
if 'users' not in data:
|
| 34 |
data['users'] = {}
|
| 35 |
if 'general_chat' not in data:
|
| 36 |
data['general_chat'] = []
|
| 37 |
-
|
|
|
|
| 38 |
for user in data['users']:
|
| 39 |
if 'last_chat_visit' not in data['users'][user]:
|
| 40 |
data['users'][user]['last_chat_visit'] = '1970-01-01 00:00:00'
|
|
|
|
|
|
|
| 41 |
logging.info("Data loaded successfully")
|
| 42 |
return data
|
| 43 |
except Exception as e:
|
| 44 |
logging.error(f"Error loading data: {e}")
|
| 45 |
-
return {'posts': [], 'users': {}, 'general_chat': []}
|
| 46 |
|
| 47 |
def save_data(data):
|
| 48 |
try:
|
|
@@ -84,7 +87,7 @@ def download_db_from_hf():
|
|
| 84 |
logging.error(f"Error downloading database: {e}")
|
| 85 |
if not os.path.exists(DATA_FILE):
|
| 86 |
with open(DATA_FILE, 'w', encoding='utf-8') as f:
|
| 87 |
-
json.dump({'posts': [], 'users': {}, 'general_chat': []}, f)
|
| 88 |
|
| 89 |
def periodic_backup():
|
| 90 |
while True:
|
|
@@ -97,6 +100,17 @@ def get_unread_count(data, username):
|
|
| 97 |
last_visit = datetime.strptime(data['users'][username]['last_chat_visit'], '%Y-%m-%d %H:%M:%S')
|
| 98 |
return sum(1 for msg in data['general_chat'] if datetime.strptime(msg['time'], '%Y-%m-%d %H:%M:%S') > last_visit)
|
| 99 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
# Updated base style
|
| 101 |
BASE_STYLE = '''
|
| 102 |
:root {
|
|
@@ -368,11 +382,14 @@ NAV_HTML = '''
|
|
| 368 |
<a href="{{ url_for('profile') }}" class="nav-link"><span>👤</span> Profile ({{ username }})</a>
|
| 369 |
<a href="{{ url_for('upload') }}" class="nav-link"><span>⬆️</span> Upload</a>
|
| 370 |
<a href="{{ url_for('chat') }}" class="nav-link"><span>💬</span> Chat {% if unread_count > 0 %}<span class="badge">{{ unread_count }}</span>{% endif %}</a>
|
|
|
|
|
|
|
| 371 |
<a href="{{ url_for('logout') }}" class="nav-link logout-btn"><span>🚪</span> Logout</a>
|
| 372 |
{% else %}
|
| 373 |
<a href="{{ url_for('login') }}" class="nav-link"><span>🔑</span> Login</a>
|
| 374 |
<a href="{{ url_for('register') }}" class="nav-link"><span>✨</span> Register</a>
|
| 375 |
<a href="{{ url_for('chat') }}" class="nav-link"><span>💬</span> Chat (View Only)</a>
|
|
|
|
| 376 |
{% endif %}
|
| 377 |
</nav>
|
| 378 |
</aside>
|
|
@@ -390,7 +407,7 @@ def register():
|
|
| 390 |
flash('User already exists!')
|
| 391 |
return redirect(url_for('register'))
|
| 392 |
|
| 393 |
-
data['users'][username] = {'password': password, 'bio': '', 'link': '', 'avatar': None, 'last_chat_visit': '1970-01-01 00:00:00'}
|
| 394 |
save_data(data)
|
| 395 |
flash('Registration successful! Please log in.')
|
| 396 |
return redirect(url_for('login'))
|
|
@@ -399,6 +416,8 @@ def register():
|
|
| 399 |
username = session.get('username', None)
|
| 400 |
data = load_data()
|
| 401 |
unread_count = get_unread_count(data, username) if is_authenticated else 0
|
|
|
|
|
|
|
| 402 |
|
| 403 |
html = '''
|
| 404 |
<!DOCTYPE html>
|
|
@@ -488,7 +507,7 @@ def register():
|
|
| 488 |
</body>
|
| 489 |
</html>
|
| 490 |
'''
|
| 491 |
-
return render_template_string(html, is_authenticated=is_authenticated, username=username, unread_count=unread_count)
|
| 492 |
|
| 493 |
# Login
|
| 494 |
@app.route('/login', methods=['GET', 'POST'])
|
|
@@ -509,6 +528,8 @@ def login():
|
|
| 509 |
username = session.get('username', None)
|
| 510 |
data = load_data()
|
| 511 |
unread_count = get_unread_count(data, username) if is_authenticated else 0
|
|
|
|
|
|
|
| 512 |
|
| 513 |
html = '''
|
| 514 |
<!DOCTYPE html>
|
|
@@ -597,7 +618,7 @@ def login():
|
|
| 597 |
</body>
|
| 598 |
</html>
|
| 599 |
'''
|
| 600 |
-
return render_template_string(html, is_authenticated=is_authenticated, username=username, unread_count=unread_count)
|
| 601 |
|
| 602 |
# Logout
|
| 603 |
@app.route('/logout')
|
|
@@ -624,6 +645,8 @@ def feed():
|
|
| 624 |
is_authenticated = 'username' in session
|
| 625 |
username = session.get('username', None)
|
| 626 |
unread_count = get_unread_count(data, username) if is_authenticated else 0
|
|
|
|
|
|
|
| 627 |
|
| 628 |
search_query = request.form.get('search', '').strip().lower() if request.method == 'POST' else request.args.get('search', '').strip().lower()
|
| 629 |
if search_query:
|
|
@@ -802,7 +825,7 @@ def feed():
|
|
| 802 |
</body>
|
| 803 |
</html>
|
| 804 |
'''
|
| 805 |
-
return render_template_string(html, posts=posts, is_authenticated=is_authenticated, username=username, repo_id=REPO_ID, search_query=search_query, unread_count=unread_count)
|
| 806 |
|
| 807 |
# Post page
|
| 808 |
@app.route('/post/<post_id>', methods=['GET', 'POST'])
|
|
@@ -815,6 +838,8 @@ def post_page(post_id):
|
|
| 815 |
is_authenticated = 'username' in session
|
| 816 |
username = session.get('username', None)
|
| 817 |
unread_count = get_unread_count(data, username) if is_authenticated else 0
|
|
|
|
|
|
|
| 818 |
post['views'] = post.get('views', 0) + 1
|
| 819 |
save_data(data)
|
| 820 |
|
|
@@ -966,7 +991,7 @@ def post_page(post_id):
|
|
| 966 |
</body>
|
| 967 |
</html>
|
| 968 |
'''
|
| 969 |
-
return render_template_string(html, post=post, repo_id=REPO_ID, is_authenticated=is_authenticated, username=username, unread_count=unread_count)
|
| 970 |
|
| 971 |
# User profile
|
| 972 |
@app.route('/profile', methods=['GET', 'POST'])
|
|
@@ -980,6 +1005,8 @@ def profile():
|
|
| 980 |
user_posts = sorted([p for p in data['posts'] if p['uploader'] == username], key=lambda x: datetime.strptime(x['upload_date'], '%Y-%m-%d %H:%M:%S'), reverse=True)
|
| 981 |
is_authenticated = 'username' in session
|
| 982 |
unread_count = get_unread_count(data, username)
|
|
|
|
|
|
|
| 983 |
|
| 984 |
total_views = sum(post.get('views', 0) for post in user_posts)
|
| 985 |
total_likes = sum(len(post.get('likes', [])) for post in user_posts)
|
|
@@ -1225,7 +1252,7 @@ def profile():
|
|
| 1225 |
</body>
|
| 1226 |
</html>
|
| 1227 |
'''
|
| 1228 |
-
return render_template_string(html, username=username, user_posts=user_posts, total_views=total_views, total_likes=total_likes, bio=bio, link=link, avatar=avatar, repo_id=REPO_ID, is_authenticated=is_authenticated, unread_count=unread_count)
|
| 1229 |
|
| 1230 |
# Other user's profile
|
| 1231 |
@app.route('/profile/<username>')
|
|
@@ -1238,6 +1265,8 @@ def user_profile(username):
|
|
| 1238 |
is_authenticated = 'username' in session
|
| 1239 |
session_username = session.get('username', None)
|
| 1240 |
unread_count = get_unread_count(data, session_username) if is_authenticated else 0
|
|
|
|
|
|
|
| 1241 |
total_views = sum(post.get('views', 0) for post in user_posts)
|
| 1242 |
total_likes = sum(len(post.get('likes', [])) for post in user_posts)
|
| 1243 |
user_data = data['users'].get(username, {})
|
|
@@ -1430,7 +1459,7 @@ def user_profile(username):
|
|
| 1430 |
</body>
|
| 1431 |
</html>
|
| 1432 |
'''
|
| 1433 |
-
return render_template_string(html, username=username, user_posts=user_posts, total_views=total_views, total_likes=total_likes, bio=bio, link=link, avatar=avatar, repo_id=REPO_ID, is_authenticated=is_authenticated, unread_count=unread_count)
|
| 1434 |
|
| 1435 |
# Upload content
|
| 1436 |
@app.route('/upload', methods=['GET', 'POST'])
|
|
@@ -1442,6 +1471,8 @@ def upload():
|
|
| 1442 |
data = load_data()
|
| 1443 |
username = session.get('username', None)
|
| 1444 |
unread_count = get_unread_count(data, username)
|
|
|
|
|
|
|
| 1445 |
|
| 1446 |
if request.method == 'POST':
|
| 1447 |
title = request.form.get('title')
|
|
@@ -1592,9 +1623,9 @@ def upload():
|
|
| 1592 |
</body>
|
| 1593 |
</html>
|
| 1594 |
'''
|
| 1595 |
-
return render_template_string(html, username=username, is_authenticated=is_authenticated, unread_count=unread_count)
|
| 1596 |
|
| 1597 |
-
# General Chat
|
| 1598 |
@app.route('/chat', methods=['GET', 'POST'])
|
| 1599 |
def chat():
|
| 1600 |
data = load_data()
|
|
@@ -1603,11 +1634,12 @@ def chat():
|
|
| 1603 |
chat_messages = data['general_chat']
|
| 1604 |
|
| 1605 |
if is_authenticated:
|
| 1606 |
-
# Update last_chat_visit when user visits chat
|
| 1607 |
data['users'][username]['last_chat_visit'] = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
| 1608 |
save_data(data)
|
| 1609 |
|
| 1610 |
unread_count = get_unread_count(data, username) if is_authenticated else 0
|
|
|
|
|
|
|
| 1611 |
|
| 1612 |
if request.method == 'POST' and is_authenticated:
|
| 1613 |
message = request.form.get('message')
|
|
@@ -1765,6 +1797,541 @@ def chat():
|
|
| 1765 |
<h1>General Chat</h1>
|
| 1766 |
<div class="messages" id="messages">
|
| 1767 |
{% for message in chat_messages %}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1768 |
<div class="message">
|
| 1769 |
<a href="{{ url_for('user_profile', username=message['sender']) }}" class="sender">{{ message['sender'] }}</a>
|
| 1770 |
<span class="time">({{ message['time'] }})</span>:
|
|
@@ -1790,21 +2357,18 @@ def chat():
|
|
| 1790 |
</div>
|
| 1791 |
{% endfor %}
|
| 1792 |
</div>
|
| 1793 |
-
|
| 1794 |
-
<
|
| 1795 |
-
|
| 1796 |
-
|
| 1797 |
-
<
|
| 1798 |
-
|
| 1799 |
-
{
|
| 1800 |
-
|
| 1801 |
-
|
| 1802 |
-
|
| 1803 |
-
|
| 1804 |
-
|
| 1805 |
-
{% else %}
|
| 1806 |
-
<p style="margin-top: 15px;"><a href="{{ url_for('login') }}">Login</a> to send messages.</p>
|
| 1807 |
-
{% endif %}
|
| 1808 |
</div>
|
| 1809 |
<div class="modal" id="imageModal" onclick="closeModal(event)">
|
| 1810 |
<img id="modalImage" src="">
|
|
@@ -1837,15 +2401,18 @@ def chat():
|
|
| 1837 |
</body>
|
| 1838 |
</html>
|
| 1839 |
'''
|
| 1840 |
-
user_posts = [p for p in data['posts'] if p['uploader'] == username]
|
| 1841 |
return render_template_string(html,
|
| 1842 |
-
|
|
|
|
| 1843 |
username=username,
|
| 1844 |
is_authenticated=is_authenticated,
|
| 1845 |
repo_id=REPO_ID,
|
| 1846 |
posts=data['posts'],
|
| 1847 |
user_posts=user_posts,
|
| 1848 |
-
unread_count=unread_count
|
|
|
|
|
|
|
| 1849 |
|
| 1850 |
# Admin panel
|
| 1851 |
@app.route('/admhosto', methods=['GET', 'POST'])
|
|
@@ -1855,6 +2422,8 @@ def admin_panel():
|
|
| 1855 |
is_authenticated = 'username' in session
|
| 1856 |
username = session.get('username', None)
|
| 1857 |
unread_count = get_unread_count(data, username) if is_authenticated else 0
|
|
|
|
|
|
|
| 1858 |
|
| 1859 |
search_query = request.form.get('search', '').strip().lower() if request.method == 'POST' and 'search' in request.form else request.args.get('search', '').strip().lower()
|
| 1860 |
if search_query:
|
|
@@ -2042,7 +2611,7 @@ def admin_panel():
|
|
| 2042 |
</body>
|
| 2043 |
</html>
|
| 2044 |
'''
|
| 2045 |
-
return render_template_string(html, posts=posts, is_authenticated=is_authenticated, username=username, repo_id=REPO_ID, search_query=search_query, unread_count=unread_count)
|
| 2046 |
|
| 2047 |
if __name__ == '__main__':
|
| 2048 |
backup_thread = threading.Thread(target=periodic_backup, daemon=True)
|
|
|
|
| 27 |
data = json.load(file)
|
| 28 |
if not isinstance(data, dict):
|
| 29 |
logging.warning("Data is not in dict format, initializing empty database")
|
| 30 |
+
return {'posts': [], 'users': {}, 'general_chat': [], 'private_chats': {}}
|
| 31 |
if 'posts' not in data:
|
| 32 |
data['posts'] = []
|
| 33 |
if 'users' not in data:
|
| 34 |
data['users'] = {}
|
| 35 |
if 'general_chat' not in data:
|
| 36 |
data['general_chat'] = []
|
| 37 |
+
if 'private_chats' not in data:
|
| 38 |
+
data['private_chats'] = {} # Dictionary for private chats
|
| 39 |
for user in data['users']:
|
| 40 |
if 'last_chat_visit' not in data['users'][user]:
|
| 41 |
data['users'][user]['last_chat_visit'] = '1970-01-01 00:00:00'
|
| 42 |
+
if 'last_private_visit' not in data['users'][user]:
|
| 43 |
+
data['users'][user]['last_private_visit'] = '1970-01-01 00:00:00' # For private messages
|
| 44 |
logging.info("Data loaded successfully")
|
| 45 |
return data
|
| 46 |
except Exception as e:
|
| 47 |
logging.error(f"Error loading data: {e}")
|
| 48 |
+
return {'posts': [], 'users': {}, 'general_chat': [], 'private_chats': {}}
|
| 49 |
|
| 50 |
def save_data(data):
|
| 51 |
try:
|
|
|
|
| 87 |
logging.error(f"Error downloading database: {e}")
|
| 88 |
if not os.path.exists(DATA_FILE):
|
| 89 |
with open(DATA_FILE, 'w', encoding='utf-8') as f:
|
| 90 |
+
json.dump({'posts': [], 'users': {}, 'general_chat': [], 'private_chats': {}}, f)
|
| 91 |
|
| 92 |
def periodic_backup():
|
| 93 |
while True:
|
|
|
|
| 100 |
last_visit = datetime.strptime(data['users'][username]['last_chat_visit'], '%Y-%m-%d %H:%M:%S')
|
| 101 |
return sum(1 for msg in data['general_chat'] if datetime.strptime(msg['time'], '%Y-%m-%d %H:%M:%S') > last_visit)
|
| 102 |
|
| 103 |
+
def get_private_unread_count(data, username):
|
| 104 |
+
if username not in data['users']:
|
| 105 |
+
return 0
|
| 106 |
+
last_visit = datetime.strptime(data['users'][username]['last_private_visit'], '%Y-%m-%d %H:%M:%S')
|
| 107 |
+
unread = 0
|
| 108 |
+
for chat_key, messages in data['private_chats'].items():
|
| 109 |
+
users = chat_key.split('_')
|
| 110 |
+
if username in users:
|
| 111 |
+
unread += sum(1 for msg in messages if datetime.strptime(msg['time'], '%Y-%m-%d %H:%M:%S') > last_visit and msg['sender'] != username)
|
| 112 |
+
return unread
|
| 113 |
+
|
| 114 |
# Updated base style
|
| 115 |
BASE_STYLE = '''
|
| 116 |
:root {
|
|
|
|
| 382 |
<a href="{{ url_for('profile') }}" class="nav-link"><span>👤</span> Profile ({{ username }})</a>
|
| 383 |
<a href="{{ url_for('upload') }}" class="nav-link"><span>⬆️</span> Upload</a>
|
| 384 |
<a href="{{ url_for('chat') }}" class="nav-link"><span>💬</span> Chat {% if unread_count > 0 %}<span class="badge">{{ unread_count }}</span>{% endif %}</a>
|
| 385 |
+
<a href="{{ url_for('users') }}" class="nav-link"><span>👥</span> Users <span class="badge">{{ user_count }}</span></a>
|
| 386 |
+
<a href="{{ url_for('messages') }}" class="nav-link"><span>✉️</span> Messages {% if private_unread_count > 0 %}<span class="badge">{{ private_unread_count }}</span>{% endif %}</a>
|
| 387 |
<a href="{{ url_for('logout') }}" class="nav-link logout-btn"><span>🚪</span> Logout</a>
|
| 388 |
{% else %}
|
| 389 |
<a href="{{ url_for('login') }}" class="nav-link"><span>🔑</span> Login</a>
|
| 390 |
<a href="{{ url_for('register') }}" class="nav-link"><span>✨</span> Register</a>
|
| 391 |
<a href="{{ url_for('chat') }}" class="nav-link"><span>💬</span> Chat (View Only)</a>
|
| 392 |
+
<a href="{{ url_for('users') }}" class="nav-link"><span>👥</span> Users <span class="badge">{{ user_count }}</span></a>
|
| 393 |
{% endif %}
|
| 394 |
</nav>
|
| 395 |
</aside>
|
|
|
|
| 407 |
flash('User already exists!')
|
| 408 |
return redirect(url_for('register'))
|
| 409 |
|
| 410 |
+
data['users'][username] = {'password': password, 'bio': '', 'link': '', 'avatar': None, 'last_chat_visit': '1970-01-01 00:00:00', 'last_private_visit': '1970-01-01 00:00:00'}
|
| 411 |
save_data(data)
|
| 412 |
flash('Registration successful! Please log in.')
|
| 413 |
return redirect(url_for('login'))
|
|
|
|
| 416 |
username = session.get('username', None)
|
| 417 |
data = load_data()
|
| 418 |
unread_count = get_unread_count(data, username) if is_authenticated else 0
|
| 419 |
+
private_unread_count = get_private_unread_count(data, username) if is_authenticated else 0
|
| 420 |
+
user_count = len(data['users'])
|
| 421 |
|
| 422 |
html = '''
|
| 423 |
<!DOCTYPE html>
|
|
|
|
| 507 |
</body>
|
| 508 |
</html>
|
| 509 |
'''
|
| 510 |
+
return render_template_string(html, is_authenticated=is_authenticated, username=username, unread_count=unread_count, user_count=user_count, private_unread_count=private_unread_count)
|
| 511 |
|
| 512 |
# Login
|
| 513 |
@app.route('/login', methods=['GET', 'POST'])
|
|
|
|
| 528 |
username = session.get('username', None)
|
| 529 |
data = load_data()
|
| 530 |
unread_count = get_unread_count(data, username) if is_authenticated else 0
|
| 531 |
+
private_unread_count = get_private_unread_count(data, username) if is_authenticated else 0
|
| 532 |
+
user_count = len(data['users'])
|
| 533 |
|
| 534 |
html = '''
|
| 535 |
<!DOCTYPE html>
|
|
|
|
| 618 |
</body>
|
| 619 |
</html>
|
| 620 |
'''
|
| 621 |
+
return render_template_string(html, is_authenticated=is_authenticated, username=username, unread_count=unread_count, user_count=user_count, private_unread_count=private_unread_count)
|
| 622 |
|
| 623 |
# Logout
|
| 624 |
@app.route('/logout')
|
|
|
|
| 645 |
is_authenticated = 'username' in session
|
| 646 |
username = session.get('username', None)
|
| 647 |
unread_count = get_unread_count(data, username) if is_authenticated else 0
|
| 648 |
+
private_unread_count = get_private_unread_count(data, username) if is_authenticated else 0
|
| 649 |
+
user_count = len(data['users'])
|
| 650 |
|
| 651 |
search_query = request.form.get('search', '').strip().lower() if request.method == 'POST' else request.args.get('search', '').strip().lower()
|
| 652 |
if search_query:
|
|
|
|
| 825 |
</body>
|
| 826 |
</html>
|
| 827 |
'''
|
| 828 |
+
return render_template_string(html, posts=posts, is_authenticated=is_authenticated, username=username, repo_id=REPO_ID, search_query=search_query, unread_count=unread_count, user_count=user_count, private_unread_count=private_unread_count)
|
| 829 |
|
| 830 |
# Post page
|
| 831 |
@app.route('/post/<post_id>', methods=['GET', 'POST'])
|
|
|
|
| 838 |
is_authenticated = 'username' in session
|
| 839 |
username = session.get('username', None)
|
| 840 |
unread_count = get_unread_count(data, username) if is_authenticated else 0
|
| 841 |
+
private_unread_count = get_private_unread_count(data, username) if is_authenticated else 0
|
| 842 |
+
user_count = len(data['users'])
|
| 843 |
post['views'] = post.get('views', 0) + 1
|
| 844 |
save_data(data)
|
| 845 |
|
|
|
|
| 991 |
</body>
|
| 992 |
</html>
|
| 993 |
'''
|
| 994 |
+
return render_template_string(html, post=post, repo_id=REPO_ID, is_authenticated=is_authenticated, username=username, unread_count=unread_count, user_count=user_count, private_unread_count=private_unread_count)
|
| 995 |
|
| 996 |
# User profile
|
| 997 |
@app.route('/profile', methods=['GET', 'POST'])
|
|
|
|
| 1005 |
user_posts = sorted([p for p in data['posts'] if p['uploader'] == username], key=lambda x: datetime.strptime(x['upload_date'], '%Y-%m-%d %H:%M:%S'), reverse=True)
|
| 1006 |
is_authenticated = 'username' in session
|
| 1007 |
unread_count = get_unread_count(data, username)
|
| 1008 |
+
private_unread_count = get_private_unread_count(data, username)
|
| 1009 |
+
user_count = len(data['users'])
|
| 1010 |
|
| 1011 |
total_views = sum(post.get('views', 0) for post in user_posts)
|
| 1012 |
total_likes = sum(len(post.get('likes', [])) for post in user_posts)
|
|
|
|
| 1252 |
</body>
|
| 1253 |
</html>
|
| 1254 |
'''
|
| 1255 |
+
return render_template_string(html, username=username, user_posts=user_posts, total_views=total_views, total_likes=total_likes, bio=bio, link=link, avatar=avatar, repo_id=REPO_ID, is_authenticated=is_authenticated, unread_count=unread_count, user_count=user_count, private_unread_count=private_unread_count)
|
| 1256 |
|
| 1257 |
# Other user's profile
|
| 1258 |
@app.route('/profile/<username>')
|
|
|
|
| 1265 |
is_authenticated = 'username' in session
|
| 1266 |
session_username = session.get('username', None)
|
| 1267 |
unread_count = get_unread_count(data, session_username) if is_authenticated else 0
|
| 1268 |
+
private_unread_count = get_private_unread_count(data, session_username) if is_authenticated else 0
|
| 1269 |
+
user_count = len(data['users'])
|
| 1270 |
total_views = sum(post.get('views', 0) for post in user_posts)
|
| 1271 |
total_likes = sum(len(post.get('likes', [])) for post in user_posts)
|
| 1272 |
user_data = data['users'].get(username, {})
|
|
|
|
| 1459 |
</body>
|
| 1460 |
</html>
|
| 1461 |
'''
|
| 1462 |
+
return render_template_string(html, username=username, user_posts=user_posts, total_views=total_views, total_likes=total_likes, bio=bio, link=link, avatar=avatar, repo_id=REPO_ID, is_authenticated=is_authenticated, unread_count=unread_count, user_count=user_count, private_unread_count=private_unread_count)
|
| 1463 |
|
| 1464 |
# Upload content
|
| 1465 |
@app.route('/upload', methods=['GET', 'POST'])
|
|
|
|
| 1471 |
data = load_data()
|
| 1472 |
username = session.get('username', None)
|
| 1473 |
unread_count = get_unread_count(data, username)
|
| 1474 |
+
private_unread_count = get_private_unread_count(data, username)
|
| 1475 |
+
user_count = len(data['users'])
|
| 1476 |
|
| 1477 |
if request.method == 'POST':
|
| 1478 |
title = request.form.get('title')
|
|
|
|
| 1623 |
</body>
|
| 1624 |
</html>
|
| 1625 |
'''
|
| 1626 |
+
return render_template_string(html, username=username, is_authenticated=is_authenticated, unread_count=unread_count, user_count=user_count, private_unread_count=private_unread_count)
|
| 1627 |
|
| 1628 |
+
# General Chat
|
| 1629 |
@app.route('/chat', methods=['GET', 'POST'])
|
| 1630 |
def chat():
|
| 1631 |
data = load_data()
|
|
|
|
| 1634 |
chat_messages = data['general_chat']
|
| 1635 |
|
| 1636 |
if is_authenticated:
|
|
|
|
| 1637 |
data['users'][username]['last_chat_visit'] = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
| 1638 |
save_data(data)
|
| 1639 |
|
| 1640 |
unread_count = get_unread_count(data, username) if is_authenticated else 0
|
| 1641 |
+
private_unread_count = get_private_unread_count(data, username) if is_authenticated else 0
|
| 1642 |
+
user_count = len(data['users'])
|
| 1643 |
|
| 1644 |
if request.method == 'POST' and is_authenticated:
|
| 1645 |
message = request.form.get('message')
|
|
|
|
| 1797 |
<h1>General Chat</h1>
|
| 1798 |
<div class="messages" id="messages">
|
| 1799 |
{% for message in chat_messages %}
|
| 1800 |
+
<div class="message">
|
| 1801 |
+
<a href="{{ url_for('user_profile', username=message['sender']) }}" class="sender">{{ message['sender'] }}</a>
|
| 1802 |
+
<span class="time">({{ message['time'] }})</span>:
|
| 1803 |
+
{% if 'text' in message %}
|
| 1804 |
+
<p>{{ message['text'] }}</p>
|
| 1805 |
+
{% endif %}
|
| 1806 |
+
{% if 'file' in message %}
|
| 1807 |
+
{% if message['file_type'] == 'video' %}
|
| 1808 |
+
<video controls>
|
| 1809 |
+
<source src="https://huggingface.co/datasets/{{ repo_id }}/resolve/main/{{ message['file'] }}" type="video/mp4">
|
| 1810 |
+
</video>
|
| 1811 |
+
{% else %}
|
| 1812 |
+
<img src="https://huggingface.co/datasets/{{ repo_id }}/resolve/main/{{ message['file'] }}" alt="Chat file" onclick="openModal(this.src)">
|
| 1813 |
+
{% endif %}
|
| 1814 |
+
{% endif %}
|
| 1815 |
+
{% if 'post_id' in message %}
|
| 1816 |
+
{% with post = posts|selectattr('id', 'equalto', message['post_id'])|first %}
|
| 1817 |
+
{% if post %}
|
| 1818 |
+
<p>Shared: <a href="{{ url_for('post_page', post_id=message['post_id']) }}">{{ post['title'] }}</a></p>
|
| 1819 |
+
{% endif %}
|
| 1820 |
+
{% endwith %}
|
| 1821 |
+
{% endif %}
|
| 1822 |
+
</div>
|
| 1823 |
+
{% endfor %}
|
| 1824 |
+
</div>
|
| 1825 |
+
{% if is_authenticated %}
|
| 1826 |
+
<form method="POST" enctype="multipart/form-data" class="message-form">
|
| 1827 |
+
<textarea name="message" placeholder="Type a message" rows="2"></textarea>
|
| 1828 |
+
<input type="file" name="file" accept="video/*,image/*">
|
| 1829 |
+
<select name="post_id" class="post-select">
|
| 1830 |
+
<option value="">Share a post (optional)</option>
|
| 1831 |
+
{% for post in user_posts %}
|
| 1832 |
+
<option value="{{ post['id'] }}">{{ post['title'] }}</option>
|
| 1833 |
+
{% endfor %}
|
| 1834 |
+
</select>
|
| 1835 |
+
<button type="submit" class="btn">Send</button>
|
| 1836 |
+
</form>
|
| 1837 |
+
{% else %}
|
| 1838 |
+
<p style="margin-top: 15px;"><a href="{{ url_for('login') }}">Login</a> to send messages.</p>
|
| 1839 |
+
{% endif %}
|
| 1840 |
+
</div>
|
| 1841 |
+
<div class="modal" id="imageModal" onclick="closeModal(event)">
|
| 1842 |
+
<img id="modalImage" src="">
|
| 1843 |
+
</div>
|
| 1844 |
+
<script>
|
| 1845 |
+
function toggleSidebar() {
|
| 1846 |
+
document.getElementById('sidebar').classList.toggle('active');
|
| 1847 |
+
}
|
| 1848 |
+
function toggleTheme() {
|
| 1849 |
+
document.body.classList.toggle('dark');
|
| 1850 |
+
localStorage.setItem('theme', document.body.classList.contains('dark') ? 'dark' : 'light');
|
| 1851 |
+
}
|
| 1852 |
+
function openModal(src) {
|
| 1853 |
+
const modal = document.getElementById('imageModal');
|
| 1854 |
+
const modalImg = document.getElementById('modalImage');
|
| 1855 |
+
modal.style.display = 'flex';
|
| 1856 |
+
modalImg.src = src;
|
| 1857 |
+
}
|
| 1858 |
+
function closeModal(event) {
|
| 1859 |
+
if (event.target.tagName !== 'IMG') {
|
| 1860 |
+
document.getElementById('imageModal').style.display = 'none';
|
| 1861 |
+
}
|
| 1862 |
+
}
|
| 1863 |
+
window.onload = () => {
|
| 1864 |
+
if (localStorage.getItem('theme') === 'dark') document.body.classList.add('dark');
|
| 1865 |
+
const messagesDiv = document.getElementById('messages');
|
| 1866 |
+
messagesDiv.scrollTop = messagesDiv.scrollHeight;
|
| 1867 |
+
};
|
| 1868 |
+
</script>
|
| 1869 |
+
</body>
|
| 1870 |
+
</html>
|
| 1871 |
+
'''
|
| 1872 |
+
user_posts = [p for p in data['posts'] if p['uploader'] == username] if is_authenticated else []
|
| 1873 |
+
return render_template_string(html,
|
| 1874 |
+
chat_messages=chat_messages,
|
| 1875 |
+
username=username,
|
| 1876 |
+
is_authenticated=is_authenticated,
|
| 1877 |
+
repo_id=REPO_ID,
|
| 1878 |
+
posts=data['posts'],
|
| 1879 |
+
user_posts=user_posts,
|
| 1880 |
+
unread_count=unread_count,
|
| 1881 |
+
user_count=user_count,
|
| 1882 |
+
private_unread_count=private_unread_count)
|
| 1883 |
+
|
| 1884 |
+
# Users page
|
| 1885 |
+
@app.route('/users', methods=['GET'])
|
| 1886 |
+
def users():
|
| 1887 |
+
data = load_data()
|
| 1888 |
+
is_authenticated = 'username' in session
|
| 1889 |
+
username = session.get('username', None)
|
| 1890 |
+
unread_count = get_unread_count(data, username) if is_authenticated else 0
|
| 1891 |
+
private_unread_count = get_private_unread_count(data, username) if is_authenticated else 0
|
| 1892 |
+
user_count = len(data['users'])
|
| 1893 |
+
user_list = [(u, data['users'][u].get('avatar')) for u in data['users']]
|
| 1894 |
+
|
| 1895 |
+
html = '''
|
| 1896 |
+
<!DOCTYPE html>
|
| 1897 |
+
<html lang="en">
|
| 1898 |
+
<head>
|
| 1899 |
+
<meta charset="UTF-8">
|
| 1900 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 1901 |
+
<meta name="keywords" content="interracial porn, bbc porn, qos, queen of spades, big black cock">
|
| 1902 |
+
<title>Users - Content Hub</title>
|
| 1903 |
+
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;800&display=swap" rel="stylesheet">
|
| 1904 |
+
<style>
|
| 1905 |
+
''' + BASE_STYLE + '''
|
| 1906 |
+
.container {
|
| 1907 |
+
max-width: 900px;
|
| 1908 |
+
background: var(--card-bg-light);
|
| 1909 |
+
backdrop-filter: blur(15px);
|
| 1910 |
+
padding: 40px;
|
| 1911 |
+
border-radius: 20px;
|
| 1912 |
+
box-shadow: var(--shadow);
|
| 1913 |
+
}
|
| 1914 |
+
body.dark .container {
|
| 1915 |
+
background: var(--card-bg-dark);
|
| 1916 |
+
}
|
| 1917 |
+
h1 {
|
| 1918 |
+
font-size: 2.2em;
|
| 1919 |
+
font-weight: 800;
|
| 1920 |
+
margin-bottom: 25px;
|
| 1921 |
+
background: linear-gradient(135deg, var(--primary), var(--accent));
|
| 1922 |
+
-webkit-background-clip: text;
|
| 1923 |
+
color: transparent;
|
| 1924 |
+
}
|
| 1925 |
+
.user-grid {
|
| 1926 |
+
display: grid;
|
| 1927 |
+
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
|
| 1928 |
+
gap: 20px;
|
| 1929 |
+
}
|
| 1930 |
+
.user-item {
|
| 1931 |
+
background: var(--card-bg-light);
|
| 1932 |
+
backdrop-filter: blur(15px);
|
| 1933 |
+
padding: 15px;
|
| 1934 |
+
border-radius: 15px;
|
| 1935 |
+
box-shadow: var(--shadow);
|
| 1936 |
+
transition: var(--transition);
|
| 1937 |
+
display: flex;
|
| 1938 |
+
align-items: center;
|
| 1939 |
+
gap: 15px;
|
| 1940 |
+
}
|
| 1941 |
+
body.dark .user-item {
|
| 1942 |
+
background: var(--card-bg-dark);
|
| 1943 |
+
}
|
| 1944 |
+
.user-item:hover {
|
| 1945 |
+
transform: translateY(-5px);
|
| 1946 |
+
}
|
| 1947 |
+
.user-avatar {
|
| 1948 |
+
width: 60px;
|
| 1949 |
+
height: 60px;
|
| 1950 |
+
border-radius: 50%;
|
| 1951 |
+
object-fit: cover;
|
| 1952 |
+
box-shadow: var(--shadow);
|
| 1953 |
+
}
|
| 1954 |
+
.user-info {
|
| 1955 |
+
flex-grow: 1;
|
| 1956 |
+
}
|
| 1957 |
+
.user-info a {
|
| 1958 |
+
color: var(--primary);
|
| 1959 |
+
font-weight: 600;
|
| 1960 |
+
text-decoration: none;
|
| 1961 |
+
}
|
| 1962 |
+
.user-info a:hover {
|
| 1963 |
+
color: var(--accent);
|
| 1964 |
+
}
|
| 1965 |
+
.message-btn {
|
| 1966 |
+
background: var(--secondary);
|
| 1967 |
+
padding: 8px 16px;
|
| 1968 |
+
font-size: 0.9em;
|
| 1969 |
+
}
|
| 1970 |
+
.message-btn:hover {
|
| 1971 |
+
background: #00b8c5;
|
| 1972 |
+
}
|
| 1973 |
+
</style>
|
| 1974 |
+
</head>
|
| 1975 |
+
<body>
|
| 1976 |
+
<button class="menu-btn" onclick="toggleSidebar()">☰</button>
|
| 1977 |
+
''' + NAV_HTML + '''
|
| 1978 |
+
<button class="theme-toggle" onclick="toggleTheme()">🌙</button>
|
| 1979 |
+
<div class="container">
|
| 1980 |
+
<h1>Users ({{ user_count }})</h1>
|
| 1981 |
+
<div class="user-grid">
|
| 1982 |
+
{% for user, avatar in user_list %}
|
| 1983 |
+
{% if user != username %}
|
| 1984 |
+
<div class="user-item">
|
| 1985 |
+
{% if avatar %}
|
| 1986 |
+
<img src="https://huggingface.co/datasets/{{ repo_id }}/resolve/main/{{ avatar }}" alt="{{ user }} Avatar" class="user-avatar">
|
| 1987 |
+
{% else %}
|
| 1988 |
+
<div class="user-avatar" style="background: var(--primary);"></div>
|
| 1989 |
+
{% endif %}
|
| 1990 |
+
<div class="user-info">
|
| 1991 |
+
<a href="{{ url_for('user_profile', username=user) }}">{{ user }}</a>
|
| 1992 |
+
{% if is_authenticated %}
|
| 1993 |
+
<br><a href="{{ url_for('private_chat', recipient=user) }}" class="btn message-btn">Send Message</a>
|
| 1994 |
+
{% endif %}
|
| 1995 |
+
</div>
|
| 1996 |
+
</div>
|
| 1997 |
+
{% endif %}
|
| 1998 |
+
{% endfor %}
|
| 1999 |
+
</div>
|
| 2000 |
+
</div>
|
| 2001 |
+
<script>
|
| 2002 |
+
function toggleSidebar() {
|
| 2003 |
+
document.getElementById('sidebar').classList.toggle('active');
|
| 2004 |
+
}
|
| 2005 |
+
function toggleTheme() {
|
| 2006 |
+
document.body.classList.toggle('dark');
|
| 2007 |
+
localStorage.setItem('theme', document.body.classList.contains('dark') ? 'dark' : 'light');
|
| 2008 |
+
}
|
| 2009 |
+
window.onload = () => {
|
| 2010 |
+
if (localStorage.getItem('theme') === 'dark') document.body.classList.add('dark');
|
| 2011 |
+
};
|
| 2012 |
+
</script>
|
| 2013 |
+
</body>
|
| 2014 |
+
</html>
|
| 2015 |
+
'''
|
| 2016 |
+
return render_template_string(html, user_list=user_list, username=username, is_authenticated=is_authenticated, repo_id=REPO_ID, unread_count=unread_count, user_count=user_count, private_unread_count=private_unread_count)
|
| 2017 |
+
|
| 2018 |
+
# Messages page (list of private dialogs)
|
| 2019 |
+
@app.route('/messages', methods=['GET'])
|
| 2020 |
+
def messages():
|
| 2021 |
+
if 'username' not in session:
|
| 2022 |
+
flash('Login to view messages!')
|
| 2023 |
+
return redirect(url_for('login'))
|
| 2024 |
+
|
| 2025 |
+
data = load_data()
|
| 2026 |
+
username = session['username']
|
| 2027 |
+
is_authenticated = 'username' in session
|
| 2028 |
+
unread_count = get_unread_count(data, username)
|
| 2029 |
+
private_unread_count = get_private_unread_count(data, username)
|
| 2030 |
+
user_count = len(data['users'])
|
| 2031 |
+
|
| 2032 |
+
dialogs = {}
|
| 2033 |
+
for chat_key, messages in data['private_chats'].items():
|
| 2034 |
+
user1, user2 = chat_key.split('_')
|
| 2035 |
+
other_user = user1 if user2 == username else user2
|
| 2036 |
+
last_message = messages[-1] if messages else None
|
| 2037 |
+
unread = sum(1 for msg in messages if datetime.strptime(msg['time'], '%Y-%m-%d %H:%M:%S') > datetime.strptime(data['users'][username]['last_private_visit'], '%Y-%m-%d %H:%M:%S') and msg['sender'] != username)
|
| 2038 |
+
dialogs[other_user] = {'last_message': last_message, 'unread': unread}
|
| 2039 |
+
|
| 2040 |
+
html = '''
|
| 2041 |
+
<!DOCTYPE html>
|
| 2042 |
+
<html lang="en">
|
| 2043 |
+
<head>
|
| 2044 |
+
<meta charset="UTF-8">
|
| 2045 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 2046 |
+
<meta name="keywords" content="interracial porn, bbc porn, qos, queen of spades, big black cock">
|
| 2047 |
+
<title>Messages - Content Hub</title>
|
| 2048 |
+
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;800&display=swap" rel="stylesheet">
|
| 2049 |
+
<style>
|
| 2050 |
+
''' + BASE_STYLE + '''
|
| 2051 |
+
.container {
|
| 2052 |
+
max-width: 900px;
|
| 2053 |
+
background: var(--card-bg-light);
|
| 2054 |
+
backdrop-filter: blur(15px);
|
| 2055 |
+
padding: 40px;
|
| 2056 |
+
border-radius: 20px;
|
| 2057 |
+
box-shadow: var(--shadow);
|
| 2058 |
+
}
|
| 2059 |
+
body.dark .container {
|
| 2060 |
+
background: var(--card-bg-dark);
|
| 2061 |
+
}
|
| 2062 |
+
h1 {
|
| 2063 |
+
font-size: 2.2em;
|
| 2064 |
+
font-weight: 800;
|
| 2065 |
+
margin-bottom: 25px;
|
| 2066 |
+
background: linear-gradient(135deg, var(--primary), var(--accent));
|
| 2067 |
+
-webkit-background-clip: text;
|
| 2068 |
+
color: transparent;
|
| 2069 |
+
}
|
| 2070 |
+
.dialog-list {
|
| 2071 |
+
display: flex;
|
| 2072 |
+
flex-direction: column;
|
| 2073 |
+
gap: 15px;
|
| 2074 |
+
}
|
| 2075 |
+
.dialog-item {
|
| 2076 |
+
background: var(--card-bg-light);
|
| 2077 |
+
backdrop-filter: blur(15px);
|
| 2078 |
+
padding: 15px;
|
| 2079 |
+
border-radius: 15px;
|
| 2080 |
+
box-shadow: var(--shadow);
|
| 2081 |
+
transition: var(--transition);
|
| 2082 |
+
display: flex;
|
| 2083 |
+
justify-content: space-between;
|
| 2084 |
+
align-items: center;
|
| 2085 |
+
}
|
| 2086 |
+
body.dark .dialog-item {
|
| 2087 |
+
background: var(--card-bg-dark);
|
| 2088 |
+
}
|
| 2089 |
+
.dialog-item:hover {
|
| 2090 |
+
transform: translateY(-5px);
|
| 2091 |
+
}
|
| 2092 |
+
.dialog-info a {
|
| 2093 |
+
color: var(--primary);
|
| 2094 |
+
font-weight: 600;
|
| 2095 |
+
text-decoration: none;
|
| 2096 |
+
}
|
| 2097 |
+
.dialog-info a:hover {
|
| 2098 |
+
color: var(--accent);
|
| 2099 |
+
}
|
| 2100 |
+
.dialog-unread {
|
| 2101 |
+
background: var(--secondary);
|
| 2102 |
+
color: white;
|
| 2103 |
+
padding: 4px 8px;
|
| 2104 |
+
border-radius: 12px;
|
| 2105 |
+
font-size: 0.8em;
|
| 2106 |
+
font-weight: 700;
|
| 2107 |
+
}
|
| 2108 |
+
</style>
|
| 2109 |
+
</head>
|
| 2110 |
+
<body>
|
| 2111 |
+
<button class="menu-btn" onclick="toggleSidebar()">☰</button>
|
| 2112 |
+
''' + NAV_HTML + '''
|
| 2113 |
+
<button class="theme-toggle" onclick="toggleTheme()">🌙</button>
|
| 2114 |
+
<div class="container">
|
| 2115 |
+
<h1>Messages</h1>
|
| 2116 |
+
<div class="dialog-list">
|
| 2117 |
+
{% for other_user, info in dialogs.items() %}
|
| 2118 |
+
<div class="dialog-item">
|
| 2119 |
+
<div class="dialog-info">
|
| 2120 |
+
<a href="{{ url_for('private_chat', recipient=other_user) }}">{{ other_user }}</a>
|
| 2121 |
+
{% if info.last_message %}
|
| 2122 |
+
<p style="font-size: 0.9em; color: rgba(0, 0, 0, 0.6);">{{ info.last_message['time'] }}:
|
| 2123 |
+
{% if 'text' in info.last_message %}{{ info.last_message['text']|truncate(30) }}{% elif 'file' in info.last_message %}File{% elif 'post_id' in info.last_message %}Post{% endif %}</p>
|
| 2124 |
+
{% endif %}
|
| 2125 |
+
</div>
|
| 2126 |
+
{% if info.unread > 0 %}
|
| 2127 |
+
<span class="dialog-unread">{{ info.unread }}</span>
|
| 2128 |
+
{% endif %}
|
| 2129 |
+
</div>
|
| 2130 |
+
{% endfor %}
|
| 2131 |
+
{% if not dialogs %}
|
| 2132 |
+
<p style="font-size: 1.1em;">No messages yet.</p>
|
| 2133 |
+
{% endif %}
|
| 2134 |
+
</div>
|
| 2135 |
+
</div>
|
| 2136 |
+
<script>
|
| 2137 |
+
function toggleSidebar() {
|
| 2138 |
+
document.getElementById('sidebar').classList.toggle('active');
|
| 2139 |
+
}
|
| 2140 |
+
function toggleTheme() {
|
| 2141 |
+
document.body.classList.toggle('dark');
|
| 2142 |
+
localStorage.setItem('theme', document.body.classList.contains('dark') ? 'dark' : 'light');
|
| 2143 |
+
}
|
| 2144 |
+
window.onload = () => {
|
| 2145 |
+
if (localStorage.getItem('theme') === 'dark') document.body.classList.add('dark');
|
| 2146 |
+
};
|
| 2147 |
+
</script>
|
| 2148 |
+
</body>
|
| 2149 |
+
</html>
|
| 2150 |
+
'''
|
| 2151 |
+
return render_template_string(html, dialogs=dialogs, username=username, is_authenticated=is_authenticated, repo_id=REPO_ID, unread_count=unread_count, user_count=user_count, private_unread_count=private_unread_count)
|
| 2152 |
+
|
| 2153 |
+
# Private Chat
|
| 2154 |
+
@app.route('/chat/<recipient>', methods=['GET', 'POST'])
|
| 2155 |
+
def private_chat(recipient):
|
| 2156 |
+
if 'username' not in session:
|
| 2157 |
+
flash('Login to chat!')
|
| 2158 |
+
return redirect(url_for('login'))
|
| 2159 |
+
|
| 2160 |
+
data = load_data()
|
| 2161 |
+
username = session['username']
|
| 2162 |
+
if recipient not in data['users']:
|
| 2163 |
+
return "User not found", 404
|
| 2164 |
+
|
| 2165 |
+
is_authenticated = 'username' in session
|
| 2166 |
+
unread_count = get_unread_count(data, username)
|
| 2167 |
+
private_unread_count = get_private_unread_count(data, username)
|
| 2168 |
+
user_count = len(data['users'])
|
| 2169 |
+
|
| 2170 |
+
# Update last_private_visit
|
| 2171 |
+
data['users'][username]['last_private_visit'] = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
| 2172 |
+
save_data(data)
|
| 2173 |
+
|
| 2174 |
+
chat_key = f"{min(username, recipient)}_{max(username, recipient)}"
|
| 2175 |
+
if chat_key not in data['private_chats']:
|
| 2176 |
+
data['private_chats'][chat_key] = []
|
| 2177 |
+
private_messages = data['private_chats'][chat_key]
|
| 2178 |
+
|
| 2179 |
+
if request.method == 'POST':
|
| 2180 |
+
message = request.form.get('message')
|
| 2181 |
+
file = request.files.get('file')
|
| 2182 |
+
post_id = request.form.get('post_id')
|
| 2183 |
+
|
| 2184 |
+
message_data = {
|
| 2185 |
+
'sender': username,
|
| 2186 |
+
'time': datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
| 2187 |
+
}
|
| 2188 |
+
|
| 2189 |
+
if message:
|
| 2190 |
+
message_data['text'] = message
|
| 2191 |
+
|
| 2192 |
+
if file and file.filename:
|
| 2193 |
+
filename = secure_filename(file.filename)
|
| 2194 |
+
temp_path = os.path.join('uploads', filename)
|
| 2195 |
+
os.makedirs('uploads', exist_ok=True)
|
| 2196 |
+
file.save(temp_path)
|
| 2197 |
+
|
| 2198 |
+
file_type = 'video' if filename.lower().endswith(('.mp4', '.mov', '.avi')) else 'photo'
|
| 2199 |
+
api = HfApi()
|
| 2200 |
+
file_path = f"chat_files/private/{chat_key}/{filename}"
|
| 2201 |
+
api.upload_file(
|
| 2202 |
+
path_or_fileobj=temp_path,
|
| 2203 |
+
path_in_repo=file_path,
|
| 2204 |
+
repo_id=REPO_ID,
|
| 2205 |
+
repo_type="dataset",
|
| 2206 |
+
token=HF_TOKEN_WRITE,
|
| 2207 |
+
commit_message=f"Uploaded private chat file by {username} to {recipient}"
|
| 2208 |
+
)
|
| 2209 |
+
message_data['file'] = file_path
|
| 2210 |
+
message_data['file_type'] = file_type
|
| 2211 |
+
if os.path.exists(temp_path):
|
| 2212 |
+
os.remove(temp_path)
|
| 2213 |
+
|
| 2214 |
+
if post_id:
|
| 2215 |
+
post = next((p for p in data['posts'] if p['id'] == post_id and p['uploader'] == username), None)
|
| 2216 |
+
if post:
|
| 2217 |
+
message_data['post_id'] = post_id
|
| 2218 |
+
|
| 2219 |
+
if 'text' in message_data or 'file' in message_data or 'post_id' in message_data:
|
| 2220 |
+
data['private_chats'][chat_key].append(message_data)
|
| 2221 |
+
save_data(data)
|
| 2222 |
+
|
| 2223 |
+
return redirect(url_for('private_chat', recipient=recipient))
|
| 2224 |
+
|
| 2225 |
+
html = '''
|
| 2226 |
+
<!DOCTYPE html>
|
| 2227 |
+
<html lang="en">
|
| 2228 |
+
<head>
|
| 2229 |
+
<meta charset="UTF-8">
|
| 2230 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 2231 |
+
<meta name="keywords" content="interracial porn, bbc porn, qos, queen of spades, big black cock">
|
| 2232 |
+
<title>Chat with {{ recipient }} - Content Hub</title>
|
| 2233 |
+
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;800&display=swap" rel="stylesheet">
|
| 2234 |
+
<style>
|
| 2235 |
+
''' + BASE_STYLE + '''
|
| 2236 |
+
.container {
|
| 2237 |
+
max-width: 900px;
|
| 2238 |
+
background: var(--card-bg-light);
|
| 2239 |
+
backdrop-filter: blur(15px);
|
| 2240 |
+
padding: 40px;
|
| 2241 |
+
border-radius: 20px;
|
| 2242 |
+
box-shadow: var(--shadow);
|
| 2243 |
+
}
|
| 2244 |
+
body.dark .container {
|
| 2245 |
+
background: var(--card-bg-dark);
|
| 2246 |
+
}
|
| 2247 |
+
h1 {
|
| 2248 |
+
font-size: 2.2em;
|
| 2249 |
+
font-weight: 800;
|
| 2250 |
+
margin-bottom: 25px;
|
| 2251 |
+
background: linear-gradient(135deg, var(--primary), var(--accent));
|
| 2252 |
+
-webkit-background-clip: text;
|
| 2253 |
+
color: transparent;
|
| 2254 |
+
}
|
| 2255 |
+
.messages {
|
| 2256 |
+
max-height: 500px;
|
| 2257 |
+
overflow-y: auto;
|
| 2258 |
+
padding: 15px;
|
| 2259 |
+
background: var(--glass-bg);
|
| 2260 |
+
border-radius: 15px;
|
| 2261 |
+
margin-bottom: 20px;
|
| 2262 |
+
scroll-behavior: smooth;
|
| 2263 |
+
}
|
| 2264 |
+
.message {
|
| 2265 |
+
padding: 12px 18px;
|
| 2266 |
+
background: var(--card-bg-light);
|
| 2267 |
+
border-radius: 12px;
|
| 2268 |
+
margin-bottom: 12px;
|
| 2269 |
+
font-size: 1em;
|
| 2270 |
+
transition: var(--transition);
|
| 2271 |
+
}
|
| 2272 |
+
body.dark .message {
|
| 2273 |
+
background: var(--card-bg-dark);
|
| 2274 |
+
}
|
| 2275 |
+
.message:hover {
|
| 2276 |
+
transform: translateY(-2px);
|
| 2277 |
+
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
|
| 2278 |
+
}
|
| 2279 |
+
.message .sender {
|
| 2280 |
+
color: var(--primary);
|
| 2281 |
+
font-weight: 600;
|
| 2282 |
+
text-decoration: none;
|
| 2283 |
+
cursor: pointer;
|
| 2284 |
+
}
|
| 2285 |
+
.message .sender:hover {
|
| 2286 |
+
color: var(--accent);
|
| 2287 |
+
}
|
| 2288 |
+
.message .time {
|
| 2289 |
+
font-size: 0.85em;
|
| 2290 |
+
color: rgba(0, 0, 0, 0.6);
|
| 2291 |
+
margin-left: 10px;
|
| 2292 |
+
}
|
| 2293 |
+
body.dark .message .time {
|
| 2294 |
+
color: rgba(255, 255, 255, 0.6);
|
| 2295 |
+
}
|
| 2296 |
+
.message img, .message video {
|
| 2297 |
+
max-width: 280px;
|
| 2298 |
+
max-height: 280px;
|
| 2299 |
+
border-radius: 10px;
|
| 2300 |
+
margin-top: 10px;
|
| 2301 |
+
display: block;
|
| 2302 |
+
}
|
| 2303 |
+
.message a {
|
| 2304 |
+
color: var(--primary);
|
| 2305 |
+
text-decoration: none;
|
| 2306 |
+
}
|
| 2307 |
+
.message a:hover {
|
| 2308 |
+
color: var(--accent);
|
| 2309 |
+
}
|
| 2310 |
+
.message-form {
|
| 2311 |
+
margin-top: 20px;
|
| 2312 |
+
display: flex;
|
| 2313 |
+
flex-direction: column;
|
| 2314 |
+
gap: 12px;
|
| 2315 |
+
}
|
| 2316 |
+
.post-select {
|
| 2317 |
+
padding: 12px;
|
| 2318 |
+
border-radius: 12px;
|
| 2319 |
+
background: var(--glass-bg);
|
| 2320 |
+
color: var(--text-light);
|
| 2321 |
+
}
|
| 2322 |
+
body.dark .post-select {
|
| 2323 |
+
color: var(--text-dark);
|
| 2324 |
+
}
|
| 2325 |
+
</style>
|
| 2326 |
+
</head>
|
| 2327 |
+
<body>
|
| 2328 |
+
<button class="menu-btn" onclick="toggleSidebar()">☰</button>
|
| 2329 |
+
''' + NAV_HTML + '''
|
| 2330 |
+
<button class="theme-toggle" onclick="toggleTheme()">🌙</button>
|
| 2331 |
+
<div class="container">
|
| 2332 |
+
<h1>Chat with {{ recipient }}</h1>
|
| 2333 |
+
<div class="messages" id="messages">
|
| 2334 |
+
{% for message in private_messages %}
|
| 2335 |
<div class="message">
|
| 2336 |
<a href="{{ url_for('user_profile', username=message['sender']) }}" class="sender">{{ message['sender'] }}</a>
|
| 2337 |
<span class="time">({{ message['time'] }})</span>:
|
|
|
|
| 2357 |
</div>
|
| 2358 |
{% endfor %}
|
| 2359 |
</div>
|
| 2360 |
+
<form method="POST" enctype="multipart/form-data" class="message-form">
|
| 2361 |
+
<textarea name="message" placeholder="Type a message" rows="2"></textarea>
|
| 2362 |
+
<input type="file" name="file" accept="video/*,image/*">
|
| 2363 |
+
<select name="post_id" class="post-select">
|
| 2364 |
+
<option value="">Share a post (optional)</option>
|
| 2365 |
+
{% for post in user_posts %}
|
| 2366 |
+
<option value="{{ post['id'] }}">{{ post['title'] }}</option>
|
| 2367 |
+
{% endfor %}
|
| 2368 |
+
</select>
|
| 2369 |
+
<button type="submit" class="btn">Send</button>
|
| 2370 |
+
</form>
|
| 2371 |
+
<a href="{{ url_for('messages') }}" class="btn" style="margin-top: 15px;">Back to Messages</a>
|
|
|
|
|
|
|
|
|
|
| 2372 |
</div>
|
| 2373 |
<div class="modal" id="imageModal" onclick="closeModal(event)">
|
| 2374 |
<img id="modalImage" src="">
|
|
|
|
| 2401 |
</body>
|
| 2402 |
</html>
|
| 2403 |
'''
|
| 2404 |
+
user_posts = [p for p in data['posts'] if p['uploader'] == username]
|
| 2405 |
return render_template_string(html,
|
| 2406 |
+
private_messages=private_messages,
|
| 2407 |
+
recipient=recipient,
|
| 2408 |
username=username,
|
| 2409 |
is_authenticated=is_authenticated,
|
| 2410 |
repo_id=REPO_ID,
|
| 2411 |
posts=data['posts'],
|
| 2412 |
user_posts=user_posts,
|
| 2413 |
+
unread_count=unread_count,
|
| 2414 |
+
user_count=user_count,
|
| 2415 |
+
private_unread_count=private_unread_count)
|
| 2416 |
|
| 2417 |
# Admin panel
|
| 2418 |
@app.route('/admhosto', methods=['GET', 'POST'])
|
|
|
|
| 2422 |
is_authenticated = 'username' in session
|
| 2423 |
username = session.get('username', None)
|
| 2424 |
unread_count = get_unread_count(data, username) if is_authenticated else 0
|
| 2425 |
+
private_unread_count = get_private_unread_count(data, username) if is_authenticated else 0
|
| 2426 |
+
user_count = len(data['users'])
|
| 2427 |
|
| 2428 |
search_query = request.form.get('search', '').strip().lower() if request.method == 'POST' and 'search' in request.form else request.args.get('search', '').strip().lower()
|
| 2429 |
if search_query:
|
|
|
|
| 2611 |
</body>
|
| 2612 |
</html>
|
| 2613 |
'''
|
| 2614 |
+
return render_template_string(html, posts=posts, is_authenticated=is_authenticated, username=username, repo_id=REPO_ID, search_query=search_query, unread_count=unread_count, user_count=user_count, private_unread_count=private_unread_count)
|
| 2615 |
|
| 2616 |
if __name__ == '__main__':
|
| 2617 |
backup_thread = threading.Thread(target=periodic_backup, daemon=True)
|