/api/sync/?only=books: nur der Bücher-Teil
Die Buch-Synchronisation der Apps braucht vom Schnappschuss nur Bücher, Fortschritt, Markierungen und Lesezeichen; der Podcast-Teil (jede je gespielte Folge) ist für ein Konto aus AntennaPod 11 MB groß und wurde bei jedem Abgleich mitgeladen – über mobile Daten Gigabytes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
886c526201
commit
3d659fc809
2 changed files with 20 additions and 1 deletions
|
|
@ -19,7 +19,11 @@ def sync_snapshot(request):
|
||||||
endpoints (e.g. GET /books/<id>/data/), which this same token also
|
endpoints (e.g. GET /books/<id>/data/), which this same token also
|
||||||
unlocks. Writes (progress, highlights, bookmarks, ...) go through those
|
unlocks. Writes (progress, highlights, bookmarks, ...) go through those
|
||||||
existing endpoints too, to reuse their merge semantics rather than
|
existing endpoints too, to reuse their merge semantics rather than
|
||||||
duplicating it here."""
|
duplicating it here.
|
||||||
|
|
||||||
|
?only=books: just the books' part. The apps' book sync needs nothing else,
|
||||||
|
and the podcast part is by far the biggest (every episode ever played:
|
||||||
|
megabytes for an account that moved over from AntennaPod)."""
|
||||||
if not request.user.is_authenticated:
|
if not request.user.is_authenticated:
|
||||||
return JsonResponse({'error': 'authentication required'}, status=401)
|
return JsonResponse({'error': 'authentication required'}, status=401)
|
||||||
|
|
||||||
|
|
@ -43,6 +47,15 @@ def sync_snapshot(request):
|
||||||
for bm in book_bookmarks:
|
for bm in book_bookmarks:
|
||||||
bm['updated_at'] = bm['updated_at'].isoformat()
|
bm['updated_at'] = bm['updated_at'].isoformat()
|
||||||
|
|
||||||
|
if request.GET.get('only') == 'books':
|
||||||
|
return JsonResponse({
|
||||||
|
'server_time': timezone.now().isoformat(),
|
||||||
|
'books': books,
|
||||||
|
'book_progress': book_progress,
|
||||||
|
'book_highlights': book_highlights,
|
||||||
|
'book_bookmarks': book_bookmarks,
|
||||||
|
})
|
||||||
|
|
||||||
podcast_feeds = list(
|
podcast_feeds = list(
|
||||||
PodcastFeed.objects.filter(user=user)
|
PodcastFeed.objects.filter(user=user)
|
||||||
.annotate(latest_episode_at=Max('episodes__pub_date'))
|
.annotate(latest_episode_at=Max('episodes__pub_date'))
|
||||||
|
|
|
||||||
|
|
@ -85,6 +85,12 @@ class SyncSnapshotTests(TestCase):
|
||||||
resp = self.client.get('/api/sync/')
|
resp = self.client.get('/api/sync/')
|
||||||
self.assertEqual(resp.status_code, 401)
|
self.assertEqual(resp.status_code, 401)
|
||||||
|
|
||||||
|
def test_only_books(self):
|
||||||
|
resp = self.client.get('/api/sync/?only=books', HTTP_AUTHORIZATION=f'Bearer {self.token.token}')
|
||||||
|
data = resp.json()
|
||||||
|
self.assertEqual(set(data), {'server_time', 'books', 'book_progress', 'book_highlights', 'book_bookmarks'})
|
||||||
|
self.assertEqual(data['book_highlights'][0]['ct'], 'hl-ct')
|
||||||
|
|
||||||
def test_snapshot_shape_and_data(self):
|
def test_snapshot_shape_and_data(self):
|
||||||
resp = self.client.get('/api/sync/', HTTP_AUTHORIZATION=f'Bearer {self.token.token}')
|
resp = self.client.get('/api/sync/', HTTP_AUTHORIZATION=f'Bearer {self.token.token}')
|
||||||
self.assertEqual(resp.status_code, 200)
|
self.assertEqual(resp.status_code, 200)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue