From 4ccdd29b9ed9a5825b04a7a341e74f6ef1bf426b Mon Sep 17 00:00:00 2001 From: NarayanBavisetti Date: Fri, 10 May 2024 19:02:57 +0530 Subject: [PATCH] chore: added a ypy package --- apiserver/plane/api/views/base.py | 1 - apiserver/plane/app/views/page/base.py | 30 +++++++++++++++++-- .../plane/authentication/views/app/github.py | 1 - .../plane/authentication/views/app/google.py | 1 - .../authentication/views/space/github.py | 1 - .../plane/authentication/views/space/magic.py | 1 - apiserver/requirements/base.txt | 4 ++- 7 files changed, 30 insertions(+), 9 deletions(-) diff --git a/apiserver/plane/api/views/base.py b/apiserver/plane/api/views/base.py index 1f6bd70af..ecb24f1eb 100644 --- a/apiserver/plane/api/views/base.py +++ b/apiserver/plane/api/views/base.py @@ -1,5 +1,4 @@ # Python imports -from urllib.parse import urlparse import zoneinfo diff --git a/apiserver/plane/app/views/page/base.py b/apiserver/plane/app/views/page/base.py index b3ba4f622..0f8b6fc98 100644 --- a/apiserver/plane/app/views/page/base.py +++ b/apiserver/plane/app/views/page/base.py @@ -1,5 +1,6 @@ # Python imports import json +import y_py as Y import base64 from datetime import datetime from django.core.serializers.json import DjangoJSONEncoder @@ -9,7 +10,7 @@ from django.db import connection from django.db.models import Exists, OuterRef, Q from django.utils.decorators import method_decorator from django.views.decorators.gzip import gzip_page -from django.http import StreamingHttpResponse, HttpResponse +from django.http import StreamingHttpResponse # Third party imports from rest_framework import status @@ -417,11 +418,34 @@ class PagesDescriptionViewSet(BaseViewSet): page = Page.objects.get( pk=pk, workspace__slug=slug, project_id=project_id ) + base64_data = request.data.get("description_yjs") if base64_data: - binary_data = base64.b64decode(base64_data) - page.description_yjs = binary_data + # Decode the base64 data to bytes + new_binary_data = base64.b64decode(base64_data) + + # Load the existing data into a YDoc + existing_doc = Y.YDoc() + if page.description_yjs: + Y.apply_update(existing_doc, page.description_yjs) + + # Load the new data into a separate YDoc + new_doc = Y.YDoc() + Y.apply_update(new_doc, new_binary_data) + + # Merge the new data into the existing data + # This will automatically resolve any conflicts + new_state_vector = Y.encode_state_vector(new_doc) + diff = Y.encode_state_as_update(existing_doc, new_state_vector) + Y.apply_update(existing_doc, diff) + + # Encode the updated state as binary data + updated_binary_data = Y.encode_state_as_update(existing_doc) + + # Store the updated binary data + page.description_yjs = updated_binary_data + page.description_html = request.data.get("description_html") page.save() return Response({"message": "Updated successfully"}) else: diff --git a/apiserver/plane/authentication/views/app/github.py b/apiserver/plane/authentication/views/app/github.py index e7184b16e..48b7e09d9 100644 --- a/apiserver/plane/authentication/views/app/github.py +++ b/apiserver/plane/authentication/views/app/github.py @@ -2,7 +2,6 @@ import uuid from urllib.parse import urlencode, urljoin # Django import -from django.core.exceptions import ImproperlyConfigured from django.http import HttpResponseRedirect from django.views import View diff --git a/apiserver/plane/authentication/views/app/google.py b/apiserver/plane/authentication/views/app/google.py index 19c59691c..6a9e7d96b 100644 --- a/apiserver/plane/authentication/views/app/google.py +++ b/apiserver/plane/authentication/views/app/google.py @@ -3,7 +3,6 @@ import uuid from urllib.parse import urlencode, urljoin # Django import -from django.core.exceptions import ImproperlyConfigured from django.http import HttpResponseRedirect from django.views import View diff --git a/apiserver/plane/authentication/views/space/github.py b/apiserver/plane/authentication/views/space/github.py index 192f0d039..5db4a2b40 100644 --- a/apiserver/plane/authentication/views/space/github.py +++ b/apiserver/plane/authentication/views/space/github.py @@ -3,7 +3,6 @@ import uuid from urllib.parse import urlencode, urljoin # Django import -from django.core.exceptions import ImproperlyConfigured from django.http import HttpResponseRedirect from django.views import View diff --git a/apiserver/plane/authentication/views/space/magic.py b/apiserver/plane/authentication/views/space/magic.py index 390f6021d..9eca2d436 100644 --- a/apiserver/plane/authentication/views/space/magic.py +++ b/apiserver/plane/authentication/views/space/magic.py @@ -2,7 +2,6 @@ from urllib.parse import urlencode, urljoin # Django imports -from django.core.exceptions import ImproperlyConfigured, ValidationError from django.core.validators import validate_email from django.http import HttpResponseRedirect from django.views import View diff --git a/apiserver/requirements/base.txt b/apiserver/requirements/base.txt index a6bd2ab50..790a52c2d 100644 --- a/apiserver/requirements/base.txt +++ b/apiserver/requirements/base.txt @@ -60,4 +60,6 @@ zxcvbn==4.4.28 # timezone pytz==2024.1 # jwt -PyJWT==2.8.0 \ No newline at end of file +PyJWT==2.8.0 +# real-time +y-py==0.6.2 \ No newline at end of file