mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-02-02 16:21:32 -08:00
api/v1/instance/domain_blocks endpoint
This commit is contained in:
parent
54be336b77
commit
2d6ec1aabd
2 changed files with 35 additions and 1 deletions
|
@ -21,7 +21,7 @@ from app.activitypub.util import public_key, users_total, active_half_year, acti
|
|||
update_post_from_activity, undo_vote, undo_downvote
|
||||
from app.utils import gibberish, get_setting, is_image_url, allowlist_html, html_to_markdown, render_template, \
|
||||
domain_from_url, markdown_to_html, community_membership, ap_datetime, markdown_to_text, ip_address, can_downvote, \
|
||||
can_upvote, can_create_post, awaken_dormant_instance, shorten_string, can_create_post_reply
|
||||
can_upvote, can_create_post, awaken_dormant_instance, shorten_string, can_create_post_reply, sha256_digest
|
||||
import werkzeug.exceptions
|
||||
|
||||
|
||||
|
@ -116,6 +116,24 @@ def nodeinfo2():
|
|||
return jsonify(nodeinfo_data)
|
||||
|
||||
|
||||
@bp.route('/api/v1/instance/domain_blocks')
|
||||
@cache.cached(timeout=600)
|
||||
def domain_blocks():
|
||||
use_allowlist = get_setting('use_allowlist', False)
|
||||
if use_allowlist:
|
||||
return jsonify([])
|
||||
else:
|
||||
retval = []
|
||||
for domain in BannedInstances.query.all():
|
||||
retval.append({
|
||||
'domain': domain.domain,
|
||||
'digest': sha256_digest(domain.domain),
|
||||
'severity': 'suspend',
|
||||
'comment': domain.reason if domain.reason else ''
|
||||
})
|
||||
return jsonify(retval)
|
||||
|
||||
|
||||
@bp.route('/api/v3/site')
|
||||
#@cache.cached(timeout=600)
|
||||
def lemmy_site():
|
||||
|
|
16
app/utils.py
16
app/utils.py
|
@ -1,5 +1,6 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import hashlib
|
||||
import random
|
||||
import urllib
|
||||
from collections import defaultdict
|
||||
|
@ -705,3 +706,18 @@ def theme_list():
|
|||
theme_settings = json.loads(file_get_contents(f'app/templates/themes/{dir}/{dir}.json'))
|
||||
result.append((dir, theme_settings['name']))
|
||||
return result
|
||||
|
||||
|
||||
def sha256_digest(input_string):
|
||||
"""
|
||||
Compute the SHA-256 hash digest of a given string.
|
||||
|
||||
Args:
|
||||
- input_string: The string to compute the hash digest for.
|
||||
|
||||
Returns:
|
||||
- A hexadecimal string representing the SHA-256 hash digest.
|
||||
"""
|
||||
sha256_hash = hashlib.sha256()
|
||||
sha256_hash.update(input_string.encode('utf-8'))
|
||||
return sha256_hash.hexdigest()
|
||||
|
|
Loading…
Add table
Reference in a new issue