From: Enju Aihara <9839590-EnjuAihara@users.noreply.gitlab.com> Date: Thu, 14 Apr 2022 18:26:19 +0000 (+0200) Subject: API now only returns block levels that are used X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=eec20e4659caa58f42bba2158e0d25bc6366319d;p=fba.git API now only returns block levels that are used --- diff --git a/api.py b/api.py index c6b9a33..0b01a25 100644 --- a/api.py +++ b/api.py @@ -26,37 +26,20 @@ def blocked(domain: str): blocks = c.fetchall() conn.close() - result = { - "reject": [], - "media_removal": [], - "federated_timeline_removal": [], - "media_nsfw": [], - "quarantined_instances": [], - "report_removal": [], - "followers_only": [], - "accept": [], - "avatar_removal": [], - "banner_removal": [], - "reject_deletes": [], - } - - reasons = { - "reject": {}, - "media_removal": {}, - "federated_timeline_removal": {}, - "media_nsfw": {}, - "quarantined_instances": {}, - "report_removal": {}, - "followers_only": {}, - "accept": {}, - "avatar_removal": {}, - "banner_removal": {}, - "reject_deletes": {}, - } + result = {} + reasons = {} for domain, block_level, reason in blocks: - result[block_level].append(domain) - reasons[block_level][domain] = reason - - return result | {"reasons": reasons} + if block_level in result: + result[block_level].append(domain) + else: + result[block_level] = [domain] + + if reason != "": + if block_level in reasons: + reasons[block_level][domain] = reason + else: + reasons[block_level] = {domain: reason} + + return {"blocks": result, "reasons": reasons}