mirror of
https://github.com/suitenumerique/docs.git
synced 2026-09-24 18:45:13 +02:00
✨(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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user