mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-26 03:21:05 +00:00
Adds more urls
This commit is contained in:
parent
818e5bd0fa
commit
cea458acdd
4 changed files with 109 additions and 25 deletions
31
fedireads/activity.py
Normal file
31
fedireads/activity.py
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
''' Handle user activity '''
|
||||||
|
from fedireads import models
|
||||||
|
from fedireads.openlibrary import get_or_create_book
|
||||||
|
from fedireads.sanitize_html import InputHtmlParser
|
||||||
|
|
||||||
|
|
||||||
|
def create_review(user, possible_book, name, content, rating):
|
||||||
|
''' a book review has been added '''
|
||||||
|
# throws a value error if the book is not found
|
||||||
|
book = get_or_create_book(possible_book)
|
||||||
|
|
||||||
|
# sanitize review html
|
||||||
|
import pdb;pdb.set_trace()
|
||||||
|
parser = InputHtmlParser()
|
||||||
|
parser.feed(content)
|
||||||
|
content = parser.get_output()
|
||||||
|
|
||||||
|
# no ratings outside of 0-5
|
||||||
|
rating = rating if 0 <= rating <= 5 else 0
|
||||||
|
|
||||||
|
review = models.Review.objects.create(
|
||||||
|
user=user,
|
||||||
|
book=book,
|
||||||
|
name=name,
|
||||||
|
rating=rating,
|
||||||
|
content=content,
|
||||||
|
)
|
||||||
|
|
||||||
|
return review
|
||||||
|
|
||||||
|
|
|
@ -12,30 +12,7 @@ import requests
|
||||||
from fedireads import models
|
from fedireads import models
|
||||||
from fedireads import outgoing
|
from fedireads import outgoing
|
||||||
from fedireads.activity import create_review
|
from fedireads.activity import create_review
|
||||||
from fedireads.openlibrary import get_or_create_book
|
|
||||||
from fedireads.remote_user import get_or_create_remote_user
|
from fedireads.remote_user import get_or_create_remote_user
|
||||||
from fedireads.sanitize_html import InputHtmlParser
|
|
||||||
|
|
||||||
|
|
||||||
def webfinger(request):
|
|
||||||
''' allow other servers to ask about a user '''
|
|
||||||
resource = request.GET.get('resource')
|
|
||||||
if not resource and not resource.startswith('acct:'):
|
|
||||||
return HttpResponseBadRequest()
|
|
||||||
ap_id = resource.replace('acct:', '')
|
|
||||||
user = models.User.objects.filter(username=ap_id).first()
|
|
||||||
if not user:
|
|
||||||
return HttpResponseNotFound('No account found')
|
|
||||||
return JsonResponse({
|
|
||||||
'subject': 'acct:%s' % (user.username),
|
|
||||||
'links': [
|
|
||||||
{
|
|
||||||
'rel': 'self',
|
|
||||||
'type': 'application/activity+json',
|
|
||||||
'href': user.actor
|
|
||||||
}
|
|
||||||
]
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
|
|
|
@ -3,7 +3,7 @@ from django.conf.urls.static import static
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.urls import path, re_path
|
from django.urls import path, re_path
|
||||||
|
|
||||||
from fedireads import incoming, outgoing, views, settings
|
from fedireads import incoming, outgoing, views, settings, wellknown
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
|
@ -17,7 +17,11 @@ urlpatterns = [
|
||||||
re_path(r'^user/(?P<username>\w+)/followers/?$', incoming.get_followers),
|
re_path(r'^user/(?P<username>\w+)/followers/?$', incoming.get_followers),
|
||||||
re_path(r'^user/(?P<username>\w+)/following/?$', incoming.get_following),
|
re_path(r'^user/(?P<username>\w+)/following/?$', incoming.get_following),
|
||||||
# TODO: shelves need pages in the UI and for their activitypub Collection
|
# TODO: shelves need pages in the UI and for their activitypub Collection
|
||||||
re_path(r'^.well-known/webfinger/?$', incoming.webfinger),
|
|
||||||
|
# .well-known endpoints
|
||||||
|
re_path(r'^.well-known/webfinger/?$', wellknown.webfinger),
|
||||||
|
re_path(r'^.well-known/nodeinfo/?$', wellknown.nodeinfo),
|
||||||
|
re_path(r'^api/v1/instance/?$', wellknown.instance_info),
|
||||||
# TODO: re_path(r'^.well-known/host-meta/?$', incoming.host_meta),
|
# TODO: re_path(r'^.well-known/host-meta/?$', incoming.host_meta),
|
||||||
|
|
||||||
# ui views
|
# ui views
|
||||||
|
|
72
fedireads/wellknown.py
Normal file
72
fedireads/wellknown.py
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
''' responds to various requests to /.well-know '''
|
||||||
|
from django.http import HttpResponseBadRequest, HttpResponseNotFound
|
||||||
|
from django.http import JsonResponse
|
||||||
|
|
||||||
|
from fedireads import models
|
||||||
|
from fedireads.settings import DOMAIN
|
||||||
|
|
||||||
|
|
||||||
|
def webfinger(request):
|
||||||
|
''' allow other servers to ask about a user '''
|
||||||
|
if request.method != 'GET':
|
||||||
|
return HttpResponseNotFound()
|
||||||
|
|
||||||
|
resource = request.GET.get('resource')
|
||||||
|
if not resource and not resource.startswith('acct:'):
|
||||||
|
return HttpResponseBadRequest()
|
||||||
|
ap_id = resource.replace('acct:', '')
|
||||||
|
user = models.User.objects.filter(username=ap_id).first()
|
||||||
|
if not user:
|
||||||
|
return HttpResponseNotFound('No account found')
|
||||||
|
return JsonResponse({
|
||||||
|
'subject': 'acct:%s' % (user.username),
|
||||||
|
'links': [
|
||||||
|
{
|
||||||
|
'rel': 'self',
|
||||||
|
'type': 'application/activity+json',
|
||||||
|
'href': user.actor
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
def nodeinfo(request):
|
||||||
|
''' idk what this is, but mastodon asked for it '''
|
||||||
|
if request.method != 'GET':
|
||||||
|
return HttpResponseNotFound()
|
||||||
|
|
||||||
|
return JsonResponse({
|
||||||
|
'links': [
|
||||||
|
{
|
||||||
|
'rel': 'http://nodeinfo.diaspora.software/ns/schema/2.0',
|
||||||
|
'href': 'https://%s/nodeinfo/2.0' % DOMAIN
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
def instance_info(request):
|
||||||
|
''' what this place is TODO: should be settable/editable '''
|
||||||
|
if request.method != 'GET':
|
||||||
|
return HttpResponseNotFound()
|
||||||
|
|
||||||
|
user_count = models.User.objects.count()
|
||||||
|
status_count = models.Status.objects.count()
|
||||||
|
return JsonResponse({
|
||||||
|
'uri': DOMAIN,
|
||||||
|
'title': 'FediReads',
|
||||||
|
'short_description': 'Social reading, decentralized',
|
||||||
|
'description': '',
|
||||||
|
'email': 'mousereeve@riseup.net',
|
||||||
|
'version': '0.0.1',
|
||||||
|
'stats': {
|
||||||
|
'user_count': user_count,
|
||||||
|
'status_count': status_count,
|
||||||
|
},
|
||||||
|
'thumbnail': '', # TODO: logo thumbnail
|
||||||
|
'languages': [
|
||||||
|
'en'
|
||||||
|
],
|
||||||
|
'registrations': True,
|
||||||
|
'approval_required': False,
|
||||||
|
})
|
Loading…
Reference in a new issue