[WEB-4013] chore: correct live url #7014

This commit is contained in:
Nikhil
2025-05-06 01:21:53 +05:30
committed by GitHub
parent b4cc2d83fe
commit 0a01e0eb41
2 changed files with 30 additions and 11 deletions

View File

@@ -3,7 +3,7 @@ import uuid
import base64
import requests
from bs4 import BeautifulSoup
from urllib.parse import urljoin
# Django imports
from django.conf import settings
@@ -12,7 +12,7 @@ from plane.db.models import FileAsset, Page, Issue
from plane.utils.exception_logger import log_exception
from plane.settings.storage import S3Storage
from celery import shared_task
from plane.utils.url import get_url_components
from plane.utils.url import normalize_url_path
def get_entity_id_field(entity_type, entity_id):
@@ -69,17 +69,11 @@ def sync_with_external_service(entity_name, description_html):
"variant": "rich" if entity_name == "PAGE" else "document",
}
if not settings.LIVE_URL:
return {}
live_url = get_url_components(settings.LIVE_URL)
live_url = settings.LIVE_URL
if not live_url:
return {}
base_url = (
f"{live_url.get('scheme')}://{live_url.get('netloc')}{live_url.get('path')}"
)
url = urljoin(base_url, "convert-document/")
url = normalize_url_path(f"{live_url}/convert-document/")
response = requests.post(url, json=data, headers=None)
if response.status_code == 200:

View File

@@ -1,6 +1,7 @@
# Python imports
import re
from typing import Optional
from urllib.parse import urlparse
from urllib.parse import urlparse, urlunparse
def is_valid_url(url: str) -> bool:
@@ -52,3 +53,27 @@ def get_url_components(url: str) -> Optional[dict]:
"query": result.query,
"fragment": result.fragment,
}
def normalize_url_path(url: str) -> str:
"""
Normalize the path component of a URL by replacing multiple consecutive slashes with a single slash.
This function preserves the protocol, domain, query parameters, and fragments of the URL,
only modifying the path portion to ensure there are no duplicate slashes.
Args:
url (str): The input URL string to normalize.
Returns:
str: The normalized URL with redundant slashes in the path removed.
Example:
>>> normalize_url_path('https://example.com//foo///bar//baz?x=1#frag')
'https://example.com/foo/bar/baz?x=1#frag'
"""
parts = urlparse(url)
# Normalize the path
normalized_path = re.sub(r"/+", "/", parts.path)
# Reconstruct the URL
return urlunparse(parts._replace(path=normalized_path))