mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-13 11:46:35 +00:00
Merge pull request #300 from mouse-reeve/main
fixing federation of images bugs, finally
This commit is contained in:
commit
de95b60b0b
5 changed files with 41 additions and 20 deletions
|
@ -84,7 +84,7 @@ class Connector(AbstractConnector):
|
||||||
if not response.ok:
|
if not response.ok:
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
|
|
||||||
image_name = str(uuid4()) + cover_url.split('.')[-1]
|
image_name = str(uuid4()) + '.' + cover_url.split('.')[-1]
|
||||||
image_content = ContentFile(response.content)
|
image_content = ContentFile(response.content)
|
||||||
return [image_name, image_content]
|
return [image_name, image_content]
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,6 @@ def inbox(request, username):
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
def shared_inbox(request):
|
def shared_inbox(request):
|
||||||
''' incoming activitypub events '''
|
''' incoming activitypub events '''
|
||||||
# TODO: should this be functionally different from the non-shared inbox??
|
|
||||||
if request.method == 'GET':
|
if request.method == 'GET':
|
||||||
return HttpResponseNotFound()
|
return HttpResponseNotFound()
|
||||||
|
|
||||||
|
@ -217,6 +216,11 @@ def handle_create(activity):
|
||||||
# we really oughtn't even be sending in this case
|
# we really oughtn't even be sending in this case
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# deduplicate incoming activities
|
||||||
|
status_id = activity['object']['id']
|
||||||
|
if models.Status.objects.filter(remote_id=status_id).count():
|
||||||
|
return
|
||||||
|
|
||||||
status = status_builder.create_status(activity['object'])
|
status = status_builder.create_status(activity['object'])
|
||||||
|
|
||||||
# create a notification if this is a reply
|
# create a notification if this is a reply
|
||||||
|
|
|
@ -75,6 +75,16 @@ class Status(OrderedCollectionPageMixin, BookWyrmModel):
|
||||||
))
|
))
|
||||||
return tags
|
return tags
|
||||||
|
|
||||||
|
@property
|
||||||
|
def ap_status_image(self):
|
||||||
|
''' attach a book cover, if relevent '''
|
||||||
|
if hasattr(self, 'book'):
|
||||||
|
return self.book.ap_cover
|
||||||
|
if self.mention_books.first():
|
||||||
|
return self.mention_books.first().ap_cover
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
shared_mappings = [
|
shared_mappings = [
|
||||||
ActivityMapping('url', 'remote_id', lambda x: None),
|
ActivityMapping('url', 'remote_id', lambda x: None),
|
||||||
ActivityMapping('id', 'remote_id'),
|
ActivityMapping('id', 'remote_id'),
|
||||||
|
@ -100,6 +110,7 @@ class Status(OrderedCollectionPageMixin, BookWyrmModel):
|
||||||
pure_activity_mappings = shared_mappings + [
|
pure_activity_mappings = shared_mappings + [
|
||||||
ActivityMapping('name', 'ap_pure_name'),
|
ActivityMapping('name', 'ap_pure_name'),
|
||||||
ActivityMapping('content', 'ap_pure_content'),
|
ActivityMapping('content', 'ap_pure_content'),
|
||||||
|
ActivityMapping('attachment', 'ap_status_image'),
|
||||||
]
|
]
|
||||||
|
|
||||||
activity_serializer = activitypub.Note
|
activity_serializer = activitypub.Note
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from bookwyrm import activitypub, books_manager, models
|
from bookwyrm import activitypub, books_manager, models
|
||||||
from bookwyrm.books_manager import get_or_create_book
|
|
||||||
from bookwyrm.sanitize_html import InputHtmlParser
|
from bookwyrm.sanitize_html import InputHtmlParser
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -60,23 +60,7 @@ def home_tab(request, tab):
|
||||||
except ValueError:
|
except ValueError:
|
||||||
page = 1
|
page = 1
|
||||||
|
|
||||||
max_books = 5
|
suggested_books = get_suggested_books(request.user)
|
||||||
book_count = 0
|
|
||||||
preset_shelves = ['reading', 'read', 'to-read']
|
|
||||||
suggested_books = []
|
|
||||||
for preset in preset_shelves:
|
|
||||||
limit = max_books - book_count
|
|
||||||
shelf = request.user.shelf_set.get(identifier=preset)
|
|
||||||
|
|
||||||
shelf_books = shelf.shelfbook_set.order_by(
|
|
||||||
'-updated_date'
|
|
||||||
).all()[:limit]
|
|
||||||
shelf_preview = {
|
|
||||||
'name': shelf.name,
|
|
||||||
'books': [s.book for s in shelf_books]
|
|
||||||
}
|
|
||||||
suggested_books.append(shelf_preview)
|
|
||||||
book_count += len(shelf_preview['books'])
|
|
||||||
|
|
||||||
activities = get_activity_feed(request.user, tab)
|
activities = get_activity_feed(request.user, tab)
|
||||||
|
|
||||||
|
@ -100,6 +84,29 @@ def home_tab(request, tab):
|
||||||
return TemplateResponse(request, 'feed.html', data)
|
return TemplateResponse(request, 'feed.html', data)
|
||||||
|
|
||||||
|
|
||||||
|
def get_suggested_books(user, max_books=5):
|
||||||
|
''' helper to get a user's recent books '''
|
||||||
|
book_count = 0
|
||||||
|
preset_shelves = ['reading', 'read', 'to-read']
|
||||||
|
suggested_books = []
|
||||||
|
for preset in preset_shelves:
|
||||||
|
limit = max_books - book_count
|
||||||
|
shelf = user.shelf_set.get(identifier=preset)
|
||||||
|
|
||||||
|
shelf_books = shelf.shelfbook_set.order_by(
|
||||||
|
'-updated_date'
|
||||||
|
).all()[:limit]
|
||||||
|
if not shelf_books:
|
||||||
|
continue
|
||||||
|
shelf_preview = {
|
||||||
|
'name': shelf.name,
|
||||||
|
'books': [s.book for s in shelf_books]
|
||||||
|
}
|
||||||
|
suggested_books.append(shelf_preview)
|
||||||
|
book_count += len(shelf_preview['books'])
|
||||||
|
return suggested_books
|
||||||
|
|
||||||
|
|
||||||
def get_activity_feed(user, filter_level, model=models.Status):
|
def get_activity_feed(user, filter_level, model=models.Status):
|
||||||
''' get a filtered queryset of statuses '''
|
''' get a filtered queryset of statuses '''
|
||||||
# status updates for your follow network
|
# status updates for your follow network
|
||||||
|
|
Loading…
Reference in a new issue