260 lines
9.4 KiB
HTML
260 lines
9.4 KiB
HTML
|
|
<!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>
|