✨(backend) serve documents/{id}/formatted-content/ from yhub

The formatted-content endpoint was using the `document.content` to fetch
the ydoc from s3, we want to move from this usage to using yhub to
retrieve the content, so yhub is becoming our source of thruth.
This commit is contained in:
Manuel Raynaud
2026-09-22 16:00:51 +02:00
parent 2408690380
commit 3e10ba1b9f
3 changed files with 77 additions and 5 deletions
+13 -5
View File
@@ -2,7 +2,6 @@
# pylint: disable=too-many-lines
import base64
import ipaddress
import json
import logging
@@ -2452,15 +2451,24 @@ class DocumentViewSet(
"Invalid format. Must be one of: json, markdown, html"
)
# Get the base64 content from the document
# Get the content from the collaboration server, it is the source of
# truth for it
try:
update = YHubService(user=request.user).get_ydoc(document)
except YHubError as e:
logger.error("Error getting content for document %s: %s", pk, e)
return drf_response.Response(
{"error": "Failed to get document content"},
status=status.HTTP_500_INTERNAL_SERVER_ERROR,
)
content = None
base64_content = document.content
if base64_content is not None:
if update is not None:
# Convert using the y-provider service
try:
yprovider = Converter()
result = yprovider.convert(
base64.b64decode(base64_content),
update,
mime_types.YJS,
{
"markdown": mime_types.MARKDOWN,