Files
vesti/openspec/changes/archive/2026-09-16-fix-sources-add-channel/design.md
T

55 lines
2.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
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.
# fix-sources-add-channel
## Дизайн
### 1. Форма добавления — поле channel (web/templates/sources.html)
Вставить после поля `url` (перед `crawler`), чтобы telegram-поля шли вместе:
```html
<div class="col-auto">
<label class="form-label mb-0 small">channel (telegram)</label>
<input type="text" name="channel" class="form-control form-control-sm"
placeholder="@handle или t.me/..." id="add_channel">
</div>
```
Поле обязательное только для telegram: маленький inline-скрипт в конце формы
переключает атрибут `required` при смене `select[name=crawler]`:
```html
<script>
const addCrawler = document.querySelector('form[action="/sources/add"] select[name="crawler"]');
const addChannel = document.getElementById('add_channel');
function toggleChannelRequired() {
addChannel.required = addCrawler.value === 'telegram';
}
addCrawler.addEventListener('change', toggleChannelRequired);
toggleChannelRequired();
</script>
```
### 2. Таблица — показ channel у telegram (web/templates/sources.html)
В колонке crawler (строки 91-93) добавить вывод channel для telegram,
по аналогии с feed_url для rss:
```html
<td><span class="badge text-bg-secondary">{{ s['crawler'] }}</span>
{% if s['crawler'] == 'rss' and s['feed_url'] %}<br><small class="text-muted">{{ s['feed_url'] }}</small>{% endif %}
{% if s['crawler'] == 'telegram' and s['channel'] %}<br><small class="text-muted">{{ s['channel'] }}</small>{% endif %}
</td>
```
### 3. Backend — без изменений
`web/app.py::_form_source` уже собирает `channel` (строка 877),
`sources/sources.py::_validate_source` уже проверяет (строка 218),
`db_source_to_yaml` уже пишет в yaml (строка 181). Правки только в шаблоне.
## Проверка
1. `openspec validate fix-sources-add-channel` — чисто.
2. Ручной тест через веб: добавить telegram-источник с channel → success;
без channel → браузер подсветит поле, серверная ошибка не нужна.
3. Рестарт `vesti-web`, проверить страницу /sources.