Files
crm.clientright.ru/crm_extensions/file_storage/test_sse_browser.html
Fedor 9245768987 🚀 CRM Files Migration & Real-time Features
 Features:
- Migrated ALL files to new S3 structure (Projects, Contacts, Accounts, HelpDesk, Invoice, etc.)
- Added Nextcloud folder buttons to ALL modules
- Fixed Nextcloud editor integration
- WebSocket server for real-time updates
- Redis Pub/Sub integration
- File path manager for organized storage
- Redis caching for performance (Functions.php)

📁 New Structure:
Documents/Project/ProjectName_ID/file_docID.ext
Documents/Contacts/FirstName_LastName_ID/file_docID.ext
Documents/Accounts/AccountName_ID/file_docID.ext

🔧 Technical:
- FilePathManager for standardized paths
- S3StorageService integration
- WebSocket server (Node.js + Docker)
- Redis cache for getBasicModuleInfo()
- Predis library for Redis connectivity

📝 Scripts:
- Migration scripts for all modules
- Test pages for WebSocket/SSE/Polling
- Documentation (MIGRATION_*.md, REDIS_*.md)

🎯 Result: 15,000+ files migrated successfully!
2025-10-24 19:59:28 +03:00

260 lines
9.4 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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.

<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>🧪 Тест SSE Синхронизации</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 800px;
margin: 0 auto;
padding: 20px;
background-color: #f5f5f5;
}
.container {
background: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.status {
padding: 10px;
margin: 10px 0;
border-radius: 4px;
font-weight: bold;
}
.connected { background-color: #d4edda; color: #155724; }
.disconnected { background-color: #f8d7da; color: #721c24; }
.connecting { background-color: #fff3cd; color: #856404; }
.log {
background-color: #f8f9fa;
border: 1px solid #dee2e6;
padding: 10px;
margin: 10px 0;
border-radius: 4px;
max-height: 300px;
overflow-y: auto;
font-family: monospace;
font-size: 12px;
}
button {
background-color: #007bff;
color: white;
border: none;
padding: 10px 20px;
border-radius: 4px;
cursor: pointer;
margin: 5px;
}
button:hover { background-color: #0056b3; }
button:disabled { background-color: #6c757d; cursor: not-allowed; }
.test-section {
margin: 20px 0;
padding: 15px;
border: 1px solid #dee2e6;
border-radius: 4px;
}
</style>
</head>
<body>
<div class="container">
<h1>🧪 Тест SSE Синхронизации Файлов</h1>
<div class="test-section">
<h3>📡 Статус подключения</h3>
<div id="connectionStatus" class="status connecting">🟡 Подключение...</div>
<button onclick="connectSSE()">Подключиться</button>
<button onclick="disconnectSSE()">Отключиться</button>
</div>
<div class="test-section">
<h3>📝 Лог событий</h3>
<div id="eventLog" class="log">Ожидание событий...</div>
<button onclick="clearLog()">Очистить лог</button>
</div>
<div class="test-section">
<h3>🧪 Тестовые события</h3>
<button onclick="sendTestEvent('file_created')">Тест: Файл создан</button>
<button onclick="sendTestEvent('file_updated')">Тест: Файл обновлен</button>
<button onclick="sendTestEvent('file_deleted')">Тест: Файл удален</button>
<button onclick="sendTestEvent('folder_renamed')">Тест: Папка переименована</button>
</div>
<div class="test-section">
<h3>🔧 Отладка</h3>
<button onclick="testWebhook()">Тест Webhook</button>
<button onclick="checkFiles()">Проверить файлы</button>
<button onclick="showInfo()">Показать информацию</button>
</div>
</div>
<script>
let eventSource = null;
let isConnected = false;
function connectSSE() {
if (eventSource) {
eventSource.close();
}
log('🔄 Подключение к SSE...');
updateStatus('connecting', '🟡 Подключение...');
try {
eventSource = new EventSource('/crm_extensions/file_storage/api/sse_live.php');
eventSource.onopen = function(event) {
log('✅ SSE подключение установлено');
updateStatus('connected', '🟢 Подключено');
isConnected = true;
};
eventSource.onmessage = function(event) {
try {
const data = JSON.parse(event.data);
log('📨 Получено событие: ' + JSON.stringify(data, null, 2));
handleEvent(data);
} catch (error) {
log('❌ Ошибка парсинга: ' + error.message);
}
};
eventSource.onerror = function(event) {
log('❌ Ошибка SSE: ' + JSON.stringify(event));
updateStatus('disconnected', '🔴 Ошибка подключения');
isConnected = false;
};
} catch (error) {
log('❌ Ошибка создания SSE: ' + error.message);
updateStatus('disconnected', '🔴 Ошибка подключения');
}
}
function disconnectSSE() {
if (eventSource) {
eventSource.close();
eventSource = null;
log('🔌 SSE отключен');
updateStatus('disconnected', '🔴 Отключено');
isConnected = false;
}
}
function handleEvent(data) {
switch (data.type) {
case 'file_created':
log('📄 Файл создан: ' + data.data.fileName);
break;
case 'file_updated':
log('📝 Файл обновлен: ' + data.data.fileName);
break;
case 'file_deleted':
log('🗑️ Файл удален: ' + data.data.fileName);
break;
case 'folder_renamed':
log('📁 Папка переименована: ' + data.data.oldPath + ' → ' + data.data.newPath);
break;
case 'heartbeat':
log('💓 Heartbeat');
break;
default:
log('❓ Неизвестное событие: ' + data.type);
}
}
function sendTestEvent(type) {
const testData = {
action: type,
file_path: 'crm2/CRM_Active_Files/Documents/Project_123/test_file_456.pdf',
project_id: '123',
file_size: 1024
};
log('📤 Отправка тестового события: ' + type);
fetch('/crm_extensions/file_storage/api/nextcloud_webhook_simple.php', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(testData)
})
.then(response => response.json())
.then(data => {
log('✅ Webhook ответ: ' + JSON.stringify(data));
})
.catch(error => {
log('❌ Ошибка webhook: ' + error.message);
});
}
function testWebhook() {
log('🧪 Тестирование webhook...');
sendTestEvent('file_created');
}
function checkFiles() {
log('🔍 Проверка файлов...');
const files = [
'/tmp/crm_sse_events.json',
'/var/log/crm_nextcloud_webhook.log'
];
files.forEach(file => {
fetch('/crm_extensions/file_storage/api/check_file.php?file=' + encodeURIComponent(file))
.then(response => response.text())
.then(data => {
log('📁 ' + file + ': ' + data);
})
.catch(error => {
log('❌ Ошибка проверки ' + file + ': ' + error.message);
});
});
}
function showInfo() {
const info = {
userAgent: navigator.userAgent,
url: window.location.href,
timestamp: new Date().toISOString(),
sseSupported: typeof EventSource !== 'undefined'
};
log(' Информация: ' + JSON.stringify(info, null, 2));
}
function updateStatus(type, message) {
const status = document.getElementById('connectionStatus');
status.className = 'status ' + type;
status.textContent = message;
}
function log(message) {
const logDiv = document.getElementById('eventLog');
const timestamp = new Date().toLocaleTimeString();
logDiv.innerHTML += '[' + timestamp + '] ' + message + '\n';
logDiv.scrollTop = logDiv.scrollHeight;
}
function clearLog() {
document.getElementById('eventLog').innerHTML = '';
}
// Автоматическое подключение при загрузке
window.addEventListener('load', function() {
log('🚀 Страница загружена, подключение к SSE...');
connectSSE();
});
// Отключение при закрытии страницы
window.addEventListener('beforeunload', function() {
disconnectSSE();
});
</script>
</body>
</html>