Add endpoint to see all the entries for a webhook

This commit is contained in:
Joakim Hellsén 2026-03-07 19:00:11 +01:00
commit 5215b80643
Signed by: Joakim Hellsén
SSH key fingerprint: SHA256:/9h/CsExpFp+PRhsfA0xznFx2CGfTT5R/kpuFfUgEQk
5 changed files with 555 additions and 193 deletions

View file

@ -1,154 +1,155 @@
{% extends "base.html" %}
{% block content %}
<!-- List all feeds -->
<ul>
<!-- Check if any feeds -->
{% if feeds %}
<p>
{{ feed_count.total }} feed{{'s' if feed_count.total > 1 else "" }}
<!-- How many broken feeds -->
<!-- Make broken feed text red if true. -->
{% if feed_count.broken %}
- <span class="text-danger">{{ feed_count.broken }} broken</span>
<!-- List all feeds -->
<ul>
<!-- Check if any feeds -->
{% if feeds %}
<p>
{{ feed_count.total }} feed{{'s' if feed_count.total > 1 else "" }}
<!-- How many broken feeds -->
<!-- Make broken feed text red if true. -->
{% if feed_count.broken %}
- <span class="text-danger">{{ feed_count.broken }} broken</span>
{% else %}
- {{ feed_count.broken }} broken
{% endif %}
<!-- How many enabled feeds -->
<!-- Make amount of enabled feeds yellow if some are disabled. -->
{% if feed_count.total != feed_count.updates_enabled %}
- <span class="text-warning">{{ feed_count.updates_enabled }} enabled</span>
{% else %}
- {{ feed_count.updates_enabled }} enabled
{% endif %}
<!-- How many entries -->
- {{ entry_count.total }} entries
<abbr title="Average entries per day for the past 1, 3 and 12 months">
({{ entry_count.averages[0]|round(1) }},
{{ entry_count.averages[1]|round(1) }},
{{ entry_count.averages[2]|round(1) }})
</abbr>
</p>
<!-- Loop through the webhooks and add the feeds grouped by domain -->
{% for hook_from_context in webhooks %}
<div class="p-2 mb-3 border border-dark">
<div class="d-flex justify-content-between align-items-center mb-3">
<h2 class="h5 mb-0">
<a class="text-muted" href="/webhooks">{{ hook_from_context.name }}</a>
</h2>
<a class="text-muted"
href="/webhook_entries?webhook_url={{ hook_from_context.url|encode_url }}">View Latest Entries</a>
</div>
<!-- Group feeds by domain within each webhook -->
{% set feeds_for_hook = [] %}
{% for feed_webhook in feeds %}
{% if hook_from_context.url == feed_webhook.webhook %}
{% set _ = feeds_for_hook.append(feed_webhook) %}
{% endif %}
{% endfor %}
{% if feeds_for_hook %}
<!-- Create a dictionary to hold feeds grouped by domain -->
{% set domains = {} %}
{% for feed_item in feeds_for_hook %}
{% set feed = feed_item.feed %}
{% set domain = feed_item.domain %}
{% if domain not in domains %}
{% set _ = domains.update({domain: []}) %}
{% endif %}
{% set _ = domains[domain].append(feed) %}
{% endfor %}
<!-- Display domains and their feeds -->
{% for domain, domain_feeds in domains.items() %}
<div class="card bg-dark border border-dark mb-2">
<div class="card-header">
<h3 class="h6 mb-0 text-white-50">{{ domain }} ({{ domain_feeds|length }})</h3>
</div>
<div class="card-body p-2">
<ul class="list-group list-unstyled mb-0">
{% for feed in domain_feeds %}
<li>
<a class="text-muted" href="/feed?feed_url={{ feed.url|encode_url }}">
{% if feed.title %}
{{ feed.title }}
{% else %}
{{ feed.url }}
{% endif %}
</a>
{% if not feed.updates_enabled %}<span class="text-warning">Disabled</span>{% endif %}
{% if feed.last_exception %}<span class="text-danger">({{ feed.last_exception.value_str }})</span>{% endif %}
</li>
{% endfor %}
</ul>
</div>
</div>
{% endfor %}
{% else %}
<p class="text-muted">No feeds associated with this webhook.</p>
{% endif %}
</div>
{% endfor %}
{% else %}
- {{ feed_count.broken }} broken
<p>
Hello there!
<br />
<br />
You need to add a webhook <a class="text-muted" href="/add_webhook">here</a> to get started. After that, you can
add feeds <a class="text-muted" href="/add">here</a>. You can find both of these links in the navigation bar
above.
<br />
<br />
If you have any questions or suggestions, feel free to contact me on <a class="text-muted" href="mailto:tlovinator@gmail.com">tlovinator@gmail.com</a> or TheLovinator#9276 on Discord.
<br />
<br />
Thanks!
</p>
{% endif %}
<!-- How many enabled feeds -->
<!-- Make amount of enabled feeds yellow if some are disabled. -->
{% if feed_count.total != feed_count.updates_enabled %}
- <span class="text-warning">{{ feed_count.updates_enabled }} enabled</span>
{% else %}
- {{ feed_count.updates_enabled }} enabled
{% endif %}
<!-- How many entries -->
- {{ entry_count.total }} entries
<abbr title="Average entries per day for the past 1, 3 and 12 months">
({{ entry_count.averages[0]|round(1) }},
{{ entry_count.averages[1]|round(1) }},
{{ entry_count.averages[2]|round(1) }})
</abbr>
</p>
<!-- Loop through the webhooks and add the feeds grouped by domain -->
{% for hook_from_context in webhooks %}
<div class="p-2 mb-3 border border-dark">
<h2 class="h5 mb-3">
<a class="text-muted" href="/webhooks">{{ hook_from_context.name }}</a>
</h2>
<!-- Group feeds by domain within each webhook -->
{% set feeds_for_hook = [] %}
{% for feed_webhook in feeds %}
{% if hook_from_context.url == feed_webhook.webhook %}
{% set _ = feeds_for_hook.append(feed_webhook) %}
{% endif %}
{% endfor %}
{% if feeds_for_hook %}
<!-- Create a dictionary to hold feeds grouped by domain -->
{% set domains = {} %}
{% for feed_item in feeds_for_hook %}
{% set feed = feed_item.feed %}
{% set domain = feed_item.domain %}
{% if domain not in domains %}
{% set _ = domains.update({domain: []}) %}
{% endif %}
{% set _ = domains[domain].append(feed) %}
{% endfor %}
<!-- Display domains and their feeds -->
{% for domain, domain_feeds in domains.items() %}
<div class="card bg-dark border border-dark mb-2">
<div class="card-header">
<h3 class="h6 mb-0 text-white-50">{{ domain }} ({{ domain_feeds|length }})</h3>
</div>
<div class="card-body p-2">
<ul class="list-group list-unstyled mb-0">
{% for feed in domain_feeds %}
<li>
<a class="text-muted" href="/feed?feed_url={{ feed.url|encode_url }}">
{% if feed.title %}{{ feed.title }}{% else %}{{ feed.url }}{% endif %}
<!-- Show feeds without webhooks -->
{% if broken_feeds %}
<div class="p-2 mb-2 border border-dark">
<ul class="list-group text-danger">
Feeds without webhook:
{% for broken_feed in broken_feeds %}
<a class="text-muted"
href="/feed?feed_url={{ broken_feed.url|encode_url }}">
{# Display username@youtube for YouTube feeds #}
{% if "youtube.com/feeds/videos.xml" in broken_feed.url %}
{% if "user=" in broken_feed.url %}
{{ broken_feed.url.split("user=")[1] }}@youtube
{% elif "channel_id=" in broken_feed.url %}
{{ broken_feed.title if broken_feed.title else broken_feed.url.split("channel_id=")[1] }}@youtube
{% else %}
{{ broken_feed.url }}
{% endif %}
{% else %}
{{ broken_feed.url }}
{% endif %}
</a>
{% if not feed.updates_enabled %}<span class="text-warning">Disabled</span>{% endif %}
{% if feed.last_exception %}<span
class="text-danger">({{ feed.last_exception.value_str }})</span>{% endif %}
</li>
{% endfor %}
</ul>
</div>
</div>
{% endfor %}
{% else %}
<p class="text-muted">No feeds associated with this webhook.</p>
{% endif %}
</div>
{% endfor %}
{% else %}
<p>
Hello there!
<br>
<br>
You need to add a webhook <a class="text-muted" href="/add_webhook">here</a> to get started. After that, you can
add feeds <a class="text-muted" href="/add">here</a>. You can find both of these links in the navigation bar
above.
<br>
<br>
If you have any questions or suggestions, feel free to contact me on <a class="text-muted"
href="mailto:tlovinator@gmail.com">tlovinator@gmail.com</a> or TheLovinator#9276 on Discord.
<br>
<br>
Thanks!
</p>
{% endif %}
<!-- Show feeds without webhooks -->
{% if broken_feeds %}
<div class="p-2 mb-2 border border-dark">
<ul class="list-group text-danger">
Feeds without webhook:
{% for broken_feed in broken_feeds %}
<a class="text-muted" href="/feed?feed_url={{ broken_feed.url|encode_url }}">
{# Display username@youtube for YouTube feeds #}
{% if "youtube.com/feeds/videos.xml" in broken_feed.url %}
{% if "user=" in broken_feed.url %}
{{ broken_feed.url.split("user=")[1] }}@youtube
{% elif "channel_id=" in broken_feed.url %}
{{ broken_feed.title if broken_feed.title else broken_feed.url.split("channel_id=")[1] }}@youtube
{% else %}
{{ broken_feed.url }}
{% endif %}
{% else %}
{{ broken_feed.url }}
{% endif %}
</a>
{% endfor %}
</ul>
</div>
{% endif %}
<!-- Show feeds that has no attached webhook -->
{% if feeds_without_attached_webhook %}
<div class="p-2 mb-2 border border-dark">
<ul class="list-group text-danger">
Feeds without attached webhook:
{% for feed in feeds_without_attached_webhook %}
<a class="text-muted" href="/feed?feed_url={{ feed.url|encode_url }}">
{# Display username@youtube for YouTube feeds #}
{% if "youtube.com/feeds/videos.xml" in feed.url %}
{% if "user=" in feed.url %}
{{ feed.url.split("user=")[1] }}@youtube
{% elif "channel_id=" in feed.url %}
{{ feed.title if feed.title else feed.url.split("channel_id=")[1] }}@youtube
{% else %}
{{ feed.url }}
{% endif %}
{% else %}
{{ feed.url }}
{% endif %}
</a>
{% endfor %}
</ul>
</div>
{% endif %}
</ul>
<!-- Show feeds that has no attached webhook -->
{% if feeds_without_attached_webhook %}
<div class="p-2 mb-2 border border-dark">
<ul class="list-group text-danger">
Feeds without attached webhook:
{% for feed in feeds_without_attached_webhook %}
<a class="text-muted" href="/feed?feed_url={{ feed.url|encode_url }}">
{# Display username@youtube for YouTube feeds #}
{% if "youtube.com/feeds/videos.xml" in feed.url %}
{% if "user=" in feed.url %}
{{ feed.url.split("user=")[1] }}@youtube
{% elif "channel_id=" in feed.url %}
{{ feed.title if feed.title else feed.url.split("channel_id=")[1] }}@youtube
{% else %}
{{ feed.url }}
{% endif %}
{% else %}
{{ feed.url }}
{% endif %}
</a>
{% endfor %}
</ul>
</div>
{% endif %}
</ul>
{% endblock content %}

View file

@ -0,0 +1,38 @@
{% extends "base.html" %}
{% block title %}
| {{ webhook_name }} - Latest Entries
{% endblock title %}
{% block content %}
<div class="card mb-3 border border-dark p-3 text-light">
<!-- Webhook Title -->
<h2>{{ webhook_name }} - Latest Entries ({{ total_entries }} total from {{ feeds_count }} feeds)</h2>
<!-- Webhook Info -->
<div class="mt-3">
<p class="text-muted">
<code>{{ webhook_url }}</code>
</p>
</div>
</div>
{# Rendered HTML content #}
{% if entries %}
<pre>{{ html|safe }}</pre>
{% if is_show_more_entries_button_visible and last_entry %}
<a class="btn btn-dark mt-3"
href="/webhook_entries?webhook_url={{ webhook_url|encode_url }}&starting_after={{ last_entry.feed.url|encode_url }}|{{ last_entry.id|encode_url }}">
Show more entries
</a>
{% endif %}
{% elif feeds_count == 0 %}
<div>
<p>
No feeds found for {{ webhook_name }}. <a href="/add" class="alert-link">Add feeds</a> to this webhook to see entries here.
</p>
</div>
{% else %}
<div>
<p>
No entries found for {{ webhook_name }}. <a href="/settings" class="alert-link">Update feeds</a> to fetch new entries.
</p>
</div>
{% endif %}
{% endblock content %}

View file

@ -1,55 +1,63 @@
{% extends "base.html" %}
{% block title %}
| Webhooks
| Webhooks
{% endblock title %}
{% block content %}
<div class="container my-4 text-light">
{% for hook in hooks_with_data %}
<div class="border border-dark mb-4 shadow-sm p-3">
<div class="text-muted">
<h4>{{ hook.custom_name }}</h4>
<ul class="list-unstyled">
<li>
<strong>
<abbr title="Name configured in Discord">
Discord name:</strong> {{ hook.name }}
</abbr>
</li>
<li>
<strong>Webhook:</strong>
<a class="text-muted"
href="{{ hook.url }}">{{ hook.url | replace("https://discord.com/api/webhooks", "") }}</a>
</li>
</ul>
<hr>
<form action="/modify_webhook" method="post" class="row g-3">
<input type="hidden" name="old_hook" value="{{ hook.url }}" />
<div class="col-md-8">
<label for="new_hook" class="form-label">Modify Webhook</label>
<input type="text" name="new_hook" id="new_hook" class="form-control border text-muted bg-dark"
placeholder="Enter new webhook URL" />
<div class="container my-4 text-light">
{% for hook in hooks_with_data %}
<div class="border border-dark mb-4 shadow-sm p-3">
<div class="text-muted">
<h4>{{ hook.custom_name }}</h4>
<ul class="list-unstyled">
<li>
<strong>
<abbr title="Name configured in Discord">
Discord name:</strong> {{ hook.name }}
</abbr>
</li>
<li>
<strong>Webhook:</strong>
<a class="text-muted" href="{{ hook.url }}">{{ hook.url | replace('https://discord.com/api/webhooks', '') }}</a>
</li>
</ul>
<hr />
<form action="/modify_webhook" method="post" class="row g-3">
<input type="hidden" name="old_hook" value="{{ hook.url }}" />
<div class="col-md-8">
<label for="new_hook" class="form-label">Modify Webhook</label>
<input type="text"
name="new_hook"
id="new_hook"
class="form-control border text-muted bg-dark"
placeholder="Enter new webhook URL" />
</div>
<div class="col-md-4 d-flex align-items-end">
<button type="submit" class="btn btn-primary w-100">Modify</button>
</div>
</form>
</div>
<div class="d-flex justify-content-between mt-2 gap-2">
<div>
<a href="/webhook_entries?webhook_url={{ hook.url|encode_url }}"
class="btn btn-info btn-sm">View Latest Entries</a>
</div>
<form action="/delete_webhook" method="post">
<input type="hidden" name="webhook_url" value="{{ hook.url }}" />
<button type="submit"
class="btn btn-danger"
onclick="return confirm('Are you sure you want to delete this webhook?');">
Delete
</button>
</form>
</div>
</div>
<div class="col-md-4 d-flex align-items-end">
<button type="submit" class="btn btn-primary w-100">Modify</button>
</div>
</form>
{% endfor %}
<div class="border border-dark p-3">
You can append <code>?thread_id=THREAD_ID</code> to the URL to send messages to a thread.
</div>
<br />
<div class="text-end">
<a class="btn btn-primary mb-3" href="/add_webhook">Add New Webhook</a>
</div>
</div>
<div class="d-flex justify-content-between mt-2">
<form action="/delete_webhook" method="post">
<input type="hidden" name="webhook_url" value="{{ hook.url }}" />
<button type="submit" class="btn btn-danger"
onclick="return confirm('Are you sure you want to delete this webhook?');">Delete</button>
</form>
</div>
</div>
{% endfor %}
<div class="border border-dark p-3">
You can append <code>?thread_id=THREAD_ID</code> to the URL to send messages to a thread.
</div>
<br>
<div class="text-end">
<a class="btn btn-primary mb-3" href="/add_webhook">Add New Webhook</a>
</div>
</div>
{% endblock content %}
{% endblock content %}