Exclude blocked instances from linked instances in federated_instances response

This commit is contained in:
freamon 2024-10-29 10:33:59 +00:00
parent 57191c2c23
commit e2d3f6d23d

View file

@ -206,17 +206,18 @@ def lemmy_federated_instances():
linked = [] linked = []
allowed = [] allowed = []
blocked = [] blocked = []
for instance in AllowedInstances.query.all():
allowed.append({"id": instance.id, "domain": instance.domain, "published": utcnow(), "updated": utcnow()})
for instance in BannedInstances.query.all():
blocked.append({"id": instance.id, "domain": instance.domain, "published": utcnow(), "updated": utcnow()})
for instance in instances: for instance in instances:
instance_data = {"id": instance.id, "domain": instance.domain, "published": instance.created_at.isoformat(), "updated": instance.updated_at.isoformat()} instance_data = {"id": instance.id, "domain": instance.domain, "published": instance.created_at.isoformat(), "updated": instance.updated_at.isoformat()}
if instance.software: if instance.software:
instance_data['software'] = instance.software instance_data['software'] = instance.software
if instance.version: if instance.version:
instance_data['version'] = instance.version instance_data['version'] = instance.version
if not any(blocked_instance.get('domain') == instance.domain for blocked_instance in blocked):
linked.append(instance_data) linked.append(instance_data)
for instance in AllowedInstances.query.all():
allowed.append({"id": instance.id, "domain": instance.domain, "published": utcnow(), "updated": utcnow()})
for instance in BannedInstances.query.all():
blocked.append({"id": instance.id, "domain": instance.domain, "published": utcnow(), "updated": utcnow()})
return jsonify({ return jsonify({
"federated_instances": { "federated_instances": {
"linked": linked, "linked": linked,