Update files

This commit is contained in:
glpshchn 2025-12-15 07:17:54 +03:00
parent 8f9a4ea72d
commit c39c26b52b
3 changed files with 28 additions and 13 deletions

View File

@ -286,9 +286,9 @@ router.put('/posts/:id', authenticateModerationFlexible, requireModerationAccess
post.content = content; post.content = content;
// Обновить хэштеги из контента, если hashtags не переданы явно // Обновить хэштеги из контента, если hashtags не переданы явно
if (hashtags !== undefined) { if (hashtags !== undefined) {
post.hashtags = Array.isArray(hashtags) post.hashtags = Array.isArray(hashtags)
? hashtags.map((tag) => tag.toLowerCase()) ? hashtags.map((tag) => tag.toLowerCase())
: post.hashtags; : post.hashtags;
} else { } else {
// Извлечь хэштеги из контента // Извлечь хэштеги из контента
const { extractHashtags } = require('../utils/hashtags'); const { extractHashtags } = require('../utils/hashtags');

View File

@ -371,8 +371,8 @@ router.put('/:id', authenticate, async (req, res) => {
// Если контент не пустой, валидируем его // Если контент не пустой, валидируем его
if (content && content.trim().length > 0) { if (content && content.trim().length > 0) {
if (!validatePostContent(content)) { if (!validatePostContent(content)) {
logSecurityEvent('INVALID_POST_CONTENT', req); logSecurityEvent('INVALID_POST_CONTENT', req);
return res.status(400).json({ error: 'Недопустимый контент поста' }); return res.status(400).json({ error: 'Недопустимый контент поста' });
} }
post.content = content.trim(); post.content = content.trim();
// Обновить хэштеги // Обновить хэштеги
@ -391,15 +391,15 @@ router.put('/:id', authenticate, async (req, res) => {
if (tags !== undefined) { if (tags !== undefined) {
let parsedTags = []; let parsedTags = [];
if (tags) { if (tags) {
try { try {
parsedTags = typeof tags === 'string' ? JSON.parse(tags) : tags; parsedTags = typeof tags === 'string' ? JSON.parse(tags) : tags;
} catch (e) { } catch (e) {
return res.status(400).json({ error: 'Неверный формат тегов' }); return res.status(400).json({ error: 'Неверный формат тегов' });
} }
if (!validateTags(parsedTags)) { if (!validateTags(parsedTags)) {
logSecurityEvent('INVALID_TAGS', req, { tags: parsedTags }); logSecurityEvent('INVALID_TAGS', req, { tags: parsedTags });
return res.status(400).json({ error: 'Недопустимые теги' }); return res.status(400).json({ error: 'Недопустимые теги' });
} }
} }

View File

@ -49,13 +49,28 @@ class RootNamespace(socketio.AsyncNamespace):
print(f"[WebSocket] Environ keys: {list(environ.keys()) if isinstance(environ, dict) else 'N/A'}") print(f"[WebSocket] Environ keys: {list(environ.keys()) if isinstance(environ, dict) else 'N/A'}")
logger.info(f"[WebSocket] Handshake to ROOT namespace: {sid}") logger.info(f"[WebSocket] Handshake to ROOT namespace: {sid}")
# Разрешаем подключение для handshake # Разрешаем подключение для handshake
# В AsyncNamespace не нужно возвращать True явно, но можно
return True return True
async def on_disconnect(self, sid):
"""Handle disconnection from root namespace"""
print(f"[WebSocket] Client disconnected from ROOT namespace: {sid}")
logger.info(f"[WebSocket] Client disconnected from ROOT namespace: {sid}")
# Регистрируем корневой namespace ПЕРЕД созданием ASGI app # Регистрируем корневой namespace ПЕРЕД созданием ASGI app
root_ns = RootNamespace('/') root_ns = RootNamespace('/')
sio.register_namespace(root_ns) sio.register_namespace(root_ns)
print(f"[WebSocket] ✅ Корневой namespace зарегистрирован: {root_ns.namespace}") print(f"[WebSocket] ✅ Корневой namespace зарегистрирован: {root_ns.namespace}")
# Также добавляем обработчик через декоратор для надежности
@sio.on('connect', namespace='/')
async def on_connect_root_decorator(sid, environ):
"""Handle client connection to root namespace (Socket.IO handshake) - декоратор"""
print(f"[WebSocket] 🔄 Handshake to ROOT namespace (decorator): {sid}")
logger.info(f"[WebSocket] Handshake to ROOT namespace (decorator): {sid}")
# Разрешаем подключение для handshake
return True
# Namespace handlers for /mod-chat # Namespace handlers for /mod-chat
@sio.on('connect', namespace='/mod-chat') @sio.on('connect', namespace='/mod-chat')
async def on_connect(sid, environ): async def on_connect(sid, environ):