Refactor caching and Telegram integration
- Updated configuration to enforce Redis caching for notified articles, removing memory cache options. - Enhanced wallamonitor.py to load Redis cache settings and handle errors more effectively. - Implemented new API endpoints for clearing Redis cache and retrieving Telegram forum topics. - Improved frontend components to support fetching and displaying available Telegram threads. - Added functionality for clearing cache from the UI, ensuring better management of notified articles.
This commit is contained in:
@@ -69,5 +69,17 @@ export default {
|
||||
const response = await api.get('/config');
|
||||
return response.data;
|
||||
},
|
||||
|
||||
// Telegram
|
||||
async getTelegramThreads() {
|
||||
const response = await api.get('/telegram/threads');
|
||||
return response.data;
|
||||
},
|
||||
|
||||
// Cache
|
||||
async clearCache() {
|
||||
const response = await api.delete('/cache');
|
||||
return response.data;
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -6,6 +6,9 @@
|
||||
<button @click="showGeneralModal = true" class="btn btn-secondary">
|
||||
⚙️ Configuración General
|
||||
</button>
|
||||
<button @click="handleClearCache" class="btn btn-secondary">
|
||||
🗑️ Limpiar Caché
|
||||
</button>
|
||||
<button @click="showAddModal = true" class="btn btn-primary">
|
||||
+ Añadir Worker
|
||||
</button>
|
||||
@@ -226,8 +229,47 @@
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 mb-1">Thread ID (Telegram)</label>
|
||||
<input v-model.number="workerForm.thread_id" type="number" class="input" />
|
||||
<div class="flex gap-2">
|
||||
<input v-model.number="workerForm.thread_id" type="number" class="input flex-1" placeholder="Ej: 8" />
|
||||
<button
|
||||
type="button"
|
||||
@click="loadTelegramThreads"
|
||||
:disabled="loadingThreads"
|
||||
class="btn btn-secondary text-sm whitespace-nowrap"
|
||||
>
|
||||
{{ loadingThreads ? 'Cargando...' : '📋 Obtener Threads' }}
|
||||
</button>
|
||||
</div>
|
||||
<p class="text-xs text-gray-500 mt-1">Opcional: ID del hilo donde enviar notificaciones</p>
|
||||
|
||||
<!-- Lista de threads disponibles -->
|
||||
<div v-if="availableThreads.length > 0" class="mt-2 p-2 bg-gray-50 rounded border border-gray-200 max-h-40 overflow-y-auto">
|
||||
<p class="text-xs font-medium text-gray-700 mb-2">Threads disponibles:</p>
|
||||
<div
|
||||
v-for="thread in availableThreads"
|
||||
:key="thread.id"
|
||||
@click="selectThread(thread.id)"
|
||||
class="flex items-center justify-between p-2 mb-1 bg-white rounded border border-gray-200 cursor-pointer hover:bg-gray-50 transition-colors"
|
||||
>
|
||||
<div class="flex-1">
|
||||
<span class="text-sm font-medium text-gray-900">{{ thread.name }}</span>
|
||||
<span class="text-xs text-gray-500 ml-2">ID: {{ thread.id }}</span>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
@click.stop="selectThread(thread.id)"
|
||||
class="text-xs text-primary-600 hover:text-primary-700 font-medium"
|
||||
>
|
||||
Usar
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Mensaje informativo si no hay threads -->
|
||||
<div v-if="threadsMessage" class="mt-2 p-2 bg-blue-50 border border-blue-200 rounded">
|
||||
<p class="text-xs text-blue-800">{{ threadsMessage }}</p>
|
||||
<p v-if="threadsInfo" class="text-xs text-blue-700 mt-1">{{ threadsInfo }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -458,6 +500,11 @@ const generalForm = ref({
|
||||
description_exclude_text: '',
|
||||
});
|
||||
|
||||
const availableThreads = ref([]);
|
||||
const loadingThreads = ref(false);
|
||||
const threadsMessage = ref('');
|
||||
const threadsInfo = ref('');
|
||||
|
||||
async function loadWorkers() {
|
||||
loading.value = true;
|
||||
try {
|
||||
@@ -474,6 +521,40 @@ async function loadWorkers() {
|
||||
}
|
||||
}
|
||||
|
||||
async function loadTelegramThreads() {
|
||||
loadingThreads.value = true;
|
||||
availableThreads.value = [];
|
||||
threadsMessage.value = '';
|
||||
threadsInfo.value = '';
|
||||
|
||||
try {
|
||||
const result = await api.getTelegramThreads();
|
||||
|
||||
if (result.success && result.threads && result.threads.length > 0) {
|
||||
availableThreads.value = result.threads;
|
||||
threadsMessage.value = '';
|
||||
threadsInfo.value = '';
|
||||
} else {
|
||||
availableThreads.value = [];
|
||||
threadsMessage.value = result.message || 'No se pudieron obtener los threads automáticamente';
|
||||
threadsInfo.value = result.info || '';
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error cargando threads de Telegram:', error);
|
||||
availableThreads.value = [];
|
||||
threadsMessage.value = 'Error al obtener threads de Telegram. Verifica que el bot y el canal estén configurados correctamente.';
|
||||
threadsInfo.value = 'Para obtener el Thread ID manualmente: 1. Haz clic derecho en el tema/hilo en Telegram 2. Selecciona "Copiar enlace del tema" 3. El número al final de la URL es el Thread ID (ej: t.me/c/1234567890/8 → Thread ID = 8)';
|
||||
} finally {
|
||||
loadingThreads.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function selectThread(threadId) {
|
||||
workerForm.value.thread_id = threadId;
|
||||
// Opcional: limpiar la lista después de seleccionar
|
||||
// availableThreads.value = [];
|
||||
}
|
||||
|
||||
function editWorker(worker, index) {
|
||||
editingWorker.value = { worker, index };
|
||||
workerForm.value = {
|
||||
@@ -649,6 +730,23 @@ async function deleteWorker(name) {
|
||||
}
|
||||
}
|
||||
|
||||
async function handleClearCache() {
|
||||
if (!confirm('¿Estás seguro de que quieres limpiar toda la caché de Redis?\n\nEsto eliminará todos los artículos notificados de todas las instancias. Esta acción no se puede deshacer.')) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await api.clearCache();
|
||||
const message = result.count > 0
|
||||
? `✓ Caché limpiada exitosamente: ${result.count} artículos eliminados`
|
||||
: 'La caché ya estaba vacía';
|
||||
alert(message);
|
||||
} catch (error) {
|
||||
console.error('Error limpiando caché:', error);
|
||||
alert('Error al limpiar la caché: ' + (error.response?.data?.error || error.message));
|
||||
}
|
||||
}
|
||||
|
||||
function handleWSMessage(event) {
|
||||
const data = event.detail;
|
||||
if (data.type === 'workers_updated') {
|
||||
|
||||
Reference in New Issue
Block a user