171 lines
8.8 KiB
HTML
171 lines
8.8 KiB
HTML
{% extends "base.html" %}
|
||
{% block title %}Источники{% endblock %}
|
||
{% block content %}
|
||
<h4 class="text-xl font-semibold mb-4 flex items-center gap-2 flex-wrap">📡 Источники
|
||
<a href="/crawlers" class="btn btn-sm btn-outline">Статус краулеров →</a>
|
||
{% if find_enabled %}
|
||
<span class="text-sm text-neutral-500 font-normal">поисковых запросов за сутки: <b>{{ search_stats }}</b></span>
|
||
{% endif %}
|
||
</h4>
|
||
|
||
{% if did %}
|
||
<div class="alert alert-{{ 'success' if not did.startswith('error') else 'error' }} mb-4 text-sm">
|
||
{{ did }}
|
||
</div>
|
||
{% endif %}
|
||
|
||
<!-- Форма добавления -->
|
||
<div class="card card-outline mb-4 bg-white">
|
||
<div class="border-b border-neutral-200 px-4 py-2 font-bold">➕ Добавить источник</div>
|
||
<div class="card-content p-4">
|
||
<form method="post" action="/sources/add" class="flex flex-wrap items-end gap-2">
|
||
<div class="flex flex-col gap-1">
|
||
<label class="text-xs text-neutral-500 mb-0" for="add_slug">slug</label>
|
||
<input id="add_slug" type="text" name="slug" class="input input-sm w-40" placeholder="my_channel" required>
|
||
</div>
|
||
<div class="flex flex-col gap-1">
|
||
<label class="text-xs text-neutral-500 mb-0" for="add_name">Название</label>
|
||
<input id="add_name" type="text" name="name" class="input input-sm w-48" placeholder="My Channel">
|
||
</div>
|
||
<div class="flex flex-col gap-1">
|
||
<label class="text-xs text-neutral-500 mb-0" for="add_address">Address</label>
|
||
<input id="add_address" type="text" name="address" class="input input-sm w-72"
|
||
placeholder="@handle, t.me/name, https://t.me/name или https://.../rss">
|
||
</div>
|
||
<div>
|
||
<button type="button" class="btn btn-sm btn-outline" id="btn_fetch"
|
||
onclick="fetchSourcePreview()">🔎 Найти</button>
|
||
</div>
|
||
<div class="flex flex-col gap-1">
|
||
<label class="text-xs text-neutral-500 mb-0" for="add_crawler">crawler</label>
|
||
<select id="add_crawler" name="crawler" class="select select-sm w-32">
|
||
<option value="telegram">telegram</option>
|
||
<option value="rss">rss</option>
|
||
</select>
|
||
</div>
|
||
<div class="flex flex-col gap-1">
|
||
<label class="text-xs text-neutral-500 mb-0" for="add_direction">direction</label>
|
||
<input id="add_direction" type="text" name="direction" class="input input-sm w-32" placeholder="linux" list="dirs">
|
||
<datalist id="dirs">
|
||
{% for d in directions %}<option value="{{ d }}">{% endfor %}
|
||
</datalist>
|
||
</div>
|
||
<div class="flex flex-col gap-1">
|
||
<label class="text-xs text-neutral-500 mb-0" for="add_priority">priority</label>
|
||
<select id="add_priority" name="priority" class="select select-sm w-20">
|
||
<option value="P0">P0</option><option value="P1" selected>P1</option>
|
||
<option value="P2">P2</option><option value="P3">P3</option>
|
||
</select>
|
||
</div>
|
||
<div class="flex items-center gap-2 pb-2">
|
||
<input class="size-4" type="checkbox" name="enabled" id="add_en" checked>
|
||
<label class="text-sm mb-0" for="add_en">enabled</label>
|
||
</div>
|
||
<div><button class="btn btn-sm btn-primary">Добавить</button></div>
|
||
</form>
|
||
<script>
|
||
const addCrawler = document.querySelector('form[action="/sources/add"] select[name="crawler"]');
|
||
const addAddress = document.getElementById('add_address');
|
||
const addSlug = document.querySelector('form[action="/sources/add"] input[name="slug"]');
|
||
const addName = document.querySelector('form[action="/sources/add"] input[name="name"]');
|
||
|
||
if (addCrawler && addAddress) {
|
||
function toggleAddress() {
|
||
addAddress.placeholder = addCrawler.value === 'telegram'
|
||
? '@handle, t.me/name, https://t.me/name'
|
||
: 'https://.../rss или http://...';
|
||
}
|
||
addCrawler.addEventListener('change', toggleAddress);
|
||
toggleAddress();
|
||
}
|
||
|
||
async function fetchSourcePreview() {
|
||
const addr = addAddress.value.trim();
|
||
if (!addr) { alert('Введите адрес'); return; }
|
||
try {
|
||
const resp = await fetch(`/sources/preview?address=${encodeURIComponent(addr)}&crawler=${addCrawler.value}`);
|
||
const data = await resp.json();
|
||
if (data.error) { alert(data.error); return; }
|
||
if (data.slug) addSlug.value = data.slug;
|
||
if (data.name) { addName.value = data.name; }
|
||
else if (addName.value === '') addName.placeholder = 'Название не найдено — введите вручную';
|
||
} catch (e) { alert('Ошибка запроса: ' + e); }
|
||
}
|
||
</script>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- Таблица источников -->
|
||
<div class="card card-outline bg-white">
|
||
<div class="border-b border-neutral-200 px-4 py-2 flex items-center gap-2 flex-wrap">
|
||
<b>🗂️ Таблица ({{ sources|length }})</b>
|
||
<span class="text-neutral-500 text-sm">источник истины: sources.yaml (правки пишутся в yaml + БД)</span>
|
||
</div>
|
||
<div class="overflow-x-auto">
|
||
<table class="table table-sm table-hover">
|
||
<thead class="bg-neutral-100">
|
||
<tr>
|
||
<th>slug</th><th>Название</th><th>crawler</th><th>direction</th><th>lang</th>
|
||
<th>priority</th><th>enabled</th><th class="text-right">статус</th><th>послед. запуск</th><th class="text-right">действия</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
{% for s in sources %}
|
||
<tr class="{{ 'text-neutral-500' if not s['enabled'] }}">
|
||
<td><code class="text-xs">{{ s['slug'] }}</code></td>
|
||
<td>
|
||
<form method="post" action="/sources/{{ s['id'] }}/edit" class="flex items-center gap-1">
|
||
<input type="text" name="name" value="{{ s['name'] or '' }}" class="input input-sm source-name w-[170px]">
|
||
<button class="btn btn-sm btn-outline">💾</button>
|
||
</form>
|
||
</td>
|
||
<td><span class="badge badge-neutral">{{ s['crawler'] }}</span>
|
||
{% if s['crawler'] == 'rss' and s['feed_url'] %}<br><small class="text-neutral-500">{{ s['feed_url'] }}</small>{% endif %}
|
||
{% if s['crawler'] == 'telegram' and s['channel'] %}<br><small class="text-neutral-500">{{ s['channel'] }}</small>{% endif %}
|
||
</td>
|
||
<td>{{ s['direction'] or '—' }}
|
||
{% if s['error_count'] %}<br><small class="text-red-600">{{ s['error_count'] }} err</small>{% endif %}
|
||
</td>
|
||
<td>{{ s['lang'] or 'ru' }}</td>
|
||
<td>
|
||
<form method="post" action="/sources/{{ s['id'] }}/edit" class="inline-block">
|
||
<select name="priority" class="select select-sm w-auto" onchange="this.form.submit()">
|
||
{% for p in ['P0','P1','P2','P3'] %}
|
||
<option value="{{ p }}" {{ 'selected' if s['priority'] == p else '' }}>P{{ loop.index0 }}</option>
|
||
{% endfor %}
|
||
</select>
|
||
</form>
|
||
</td>
|
||
<td>
|
||
<span class="badge {{ 'badge-success' if s['enabled'] else 'badge-neutral' }}">
|
||
{{ 'вкл' if s['enabled'] else 'пауза' }}
|
||
</span>
|
||
</td>
|
||
<td class="text-right">
|
||
{% if s['status'] == 'dead' %}<span class="badge badge-error">dead</span>
|
||
{% elif s['status'] == 'alive' %}<span class="badge badge-success">alive</span>
|
||
{% elif s['status'] == 'new' %}<span class="badge badge-info">new</span>
|
||
{% else %}<span class="badge badge-neutral">{{ s['status'] }}</span>{% endif %}
|
||
{% if s['enabled'] == 0 %}<span class="badge badge-warning">пауза</span>{% endif %}
|
||
</td>
|
||
<td class="text-sm text-neutral-500">{{ s['last_fetch'] or '—' }}{% if s['last_error'] %}<br><span class="text-red-600">{{ s['last_error'][:40] }}</span>{% endif %}</td>
|
||
<td class="text-right whitespace-nowrap">
|
||
<form method="post" action="/sources/{{ s['id'] }}/toggle" class="inline-block">
|
||
<button class="btn btn-sm btn-outline {{ 'text-amber-600' if s['enabled'] else 'text-green-600' }}"
|
||
title="{{ 'Пауза' if s['enabled'] else 'Возобновить' }}">
|
||
{{ '⏸' if s['enabled'] else '▶' }}
|
||
</button>
|
||
</form>
|
||
<form method="post" action="/sources/{{ s['id'] }}/delete" class="inline-block"
|
||
onsubmit="return confirm('Удалить источник {{ s['slug'] }}? Это уберёт его из sources.yaml и БД (посты останутся).')">
|
||
<button class="btn btn-sm btn-outline text-red-600" title="Удалить">🗑</button>
|
||
</form>
|
||
</td>
|
||
</tr>
|
||
{% endfor %}
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
</div>
|
||
{% endblock %}
|