forked from mirrors/bookwyrm
Safer set remote server
This commit is contained in:
parent
20f4eb74a3
commit
6b74f56381
1 changed files with 14 additions and 9 deletions
|
@ -9,7 +9,7 @@ from django.db import models
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
from bookwyrm import activitypub
|
from bookwyrm import activitypub
|
||||||
from bookwyrm.connectors import get_data
|
from bookwyrm.connectors import get_data, ConnectorException
|
||||||
from bookwyrm.models.shelf import Shelf
|
from bookwyrm.models.shelf import Shelf
|
||||||
from bookwyrm.models.status import Status, Review
|
from bookwyrm.models.status import Status, Review
|
||||||
from bookwyrm.settings import DOMAIN
|
from bookwyrm.settings import DOMAIN
|
||||||
|
@ -333,19 +333,24 @@ def get_or_create_remote_server(domain):
|
||||||
except FederatedServer.DoesNotExist:
|
except FederatedServer.DoesNotExist:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
try:
|
||||||
data = get_data('https://%s/.well-known/nodeinfo' % domain)
|
data = get_data('https://%s/.well-known/nodeinfo' % domain)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
nodeinfo_url = data.get('links')[0].get('href')
|
nodeinfo_url = data.get('links')[0].get('href')
|
||||||
except (TypeError, KeyError):
|
except (TypeError, KeyError):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
data = get_data(nodeinfo_url)
|
data = get_data(nodeinfo_url)
|
||||||
|
application_type = data.get('software', {}).get('name')
|
||||||
|
application_type = data.get('software', {}).get('version')
|
||||||
|
except ConnectorException:
|
||||||
|
application_type = application_version = None
|
||||||
|
|
||||||
|
|
||||||
server = FederatedServer.objects.create(
|
server = FederatedServer.objects.create(
|
||||||
server_name=domain,
|
server_name=domain,
|
||||||
application_type=data['software']['name'],
|
application_type=application_type,
|
||||||
application_version=data['software']['version'],
|
application_version=application_version,
|
||||||
)
|
)
|
||||||
return server
|
return server
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue