Node.js based forum software built for the modern web
feat(federation): add hostname and type filtering to errors page
Julian Lam0366066445a7
diff --git a/public/language/en-GB/admin/settings/activitypub.json b/public/language/en-GB/admin/settings/activitypub.jsonindex 3c0322163a..8e7e327caa 100644--- a/public/language/en-GB/admin/settings/activitypub.json+++ b/public/language/en-GB/admin/settings/activitypub.json@@ -78,5 +78,7 @@"analytics.daily": "Daily","errors.intro": "The following %1 error(s) were recorded by this instance within the last 24 hours.",- "errors.payload-gone": "The payload for this error no longer exists."+ "errors.payload-gone": "The payload for this error no longer exists.",+ "errors.hostname": "Hostname",+ "errors.type": "Type"}\ No newline at end of filediff --git a/public/src/admin/federation/errors.js b/public/src/admin/federation/errors.jsindex edc626d06f..128359f7c4 100644--- a/public/src/admin/federation/errors.js+++ b/public/src/admin/federation/errors.js@@ -1,10 +1,45 @@'use strict';+import { get } from 'api';+export function init() {const errorsEl = document.getElementById('errors');if (errorsEl) {errorsEl.addEventListener('toggle', handleToggle, true);}++ const hostnameFilterEl = document.getElementById('hostnameFilter');+ const typeFilterEl = document.getElementById('typeFilter');++ if (hostnameFilterEl) {+ hostnameFilterEl.addEventListener('input', utils.debounce(handleFilterChange, 300));+ }+ if (typeFilterEl) {+ typeFilterEl.addEventListener('change', handleFilterChange);+ }+}++function handleFilterChange() {+ const hostnameFilterEl = document.getElementById('hostnameFilter');+ const typeFilterEl = document.getElementById('typeFilter');++ const params = {};+ if (hostnameFilterEl.value.trim()) {+ params.hostname = hostnameFilterEl.value.trim();+ }+ if (typeFilterEl.value) {+ params.type = typeFilterEl.value;+ }++ get(`/api${ajaxify.data.url}`, params).then(async (data) => {+ const html = await app.parseAndTranslate('admin/federation/errors', 'errors', { errors: data.errors });+ const errorsEl = document.getElementById('errors');+ if (errorsEl) {+ $(errorsEl).html(html);+ errorsEl.addEventListener('toggle', handleToggle, true);+ }+ $('#payload').text('');+ });}function handleToggle(e) {@@ -19,4 +54,6 @@ function handleToggle(e) {} else {payloadEl.innerText = '';}-}\ No newline at end of file+}++diff --git a/src/controllers/admin/federation.js b/src/controllers/admin/federation.jsindex 56adfe6584..a7ec9a8d2b 100644--- a/src/controllers/admin/federation.js+++ b/src/controllers/admin/federation.js@@ -110,6 +110,7 @@ federationController.analytics = async function (req, res) {};federationController.errors = async function (req, res) {+ const { hostname: filterHostname, type: filterType } = req.query;let errors = await db.getSortedSetRevRangeByScoreWithScores('ap.errors', 0, -1, Date.now(), '-inf');const errorObj = await db.getObjects(errors.map(({ value: id }) => `ap.errors:${id}`));errors = errors.map(({ value: id, score: timestamp }, idx) => {@@ -130,6 +131,13 @@ federationController.errors = async function (req, res) {// noop}+ if (filterHostname && hostname !== filterHostname) {+ return null;+ }+ if (filterType && type !== filterType) {+ return null;+ }+return {id: validator.escape(String(id || '')),type: validator.escape(String(type || '')),diff --git a/src/views/admin/federation/errors.tpl b/src/views/admin/federation/errors.tplindex 746eed3198..61f44b9d30 100644--- a/src/views/admin/federation/errors.tpl+++ b/src/views/admin/federation/errors.tpl@@ -4,7 +4,25 @@</div></div>-<p class="lead">[[admin/settings/activitypub:errors.intro, {errors.length}]]</p>+<div class="row border-bottom py-2 m-0 mb-3">+ <div class="col-12">+ <p class="lead">[[admin/settings/activitypub:errors.intro, {errors.length}]]</p>+ <div class="mb-3 row">+ <div class="col-6">+ <label class="form-label" for="hostnameFilter">[[admin/settings/activitypub:errors.hostname]]</label>+ <input class="form-control" id="hostnameFilter" placeholder="[[admin/settings/activitypub:errors.hostname]]" />+ </div>+ <div class="col-6">+ <label class="form-label" for="typeFilter">[[admin/settings/activitypub:errors.type]]</label>+ <select class="form-select" id="typeFilter">+ <option value="">All types</option>+ <option value="in">IN</option>+ <option value="out">OUT</option>+ </select>+ </div>+ </div>+ </div>+</div><div class="row flex-column-reverse flex-md-row"><div class="col-12 col-md-4" id="errors">