|
|
@ -3,7 +3,7 @@ import secrets |
|
|
import shutil |
|
|
import shutil |
|
|
import mimetypes |
|
|
import mimetypes |
|
|
import re |
|
|
import re |
|
|
from urllib.parse import urlparse |
|
|
|
|
|
|
|
|
from urllib.parse import urlparse, unquote |
|
|
|
|
|
|
|
|
from django.core.files.storage import default_storage |
|
|
from django.core.files.storage import default_storage |
|
|
from django.core.files.base import ContentFile |
|
|
from django.core.files.base import ContentFile |
|
|
@ -278,6 +278,8 @@ def file_location_media(path: str): |
|
|
if path.startswith("http"): |
|
|
if path.startswith("http"): |
|
|
path = exclude_host_from_url(path) |
|
|
path = exclude_host_from_url(path) |
|
|
|
|
|
|
|
|
|
|
|
path = unquote(path) |
|
|
|
|
|
|
|
|
if path.startswith(media_url + "/"): |
|
|
if path.startswith(media_url + "/"): |
|
|
path = path[len(media_url):] |
|
|
path = path[len(media_url):] |
|
|
|
|
|
|
|
|
@ -321,6 +323,8 @@ class FileFieldSerializer(serializers.CharField): |
|
|
return p |
|
|
return p |
|
|
if not isinstance(p, str): |
|
|
if not isinstance(p, str): |
|
|
return p |
|
|
return p |
|
|
|
|
|
|
|
|
|
|
|
p = unquote(p) |
|
|
|
|
|
|
|
|
# If /media/ is in the path, extract the relative path after the last /media/ |
|
|
# If /media/ is in the path, extract the relative path after the last /media/ |
|
|
if "/media/" in p: |
|
|
if "/media/" in p: |
|
|
@ -375,7 +379,7 @@ class FileFieldSerializer(serializers.CharField): |
|
|
if not os.path.exists(fpath): |
|
|
if not os.path.exists(fpath): |
|
|
raise serializers.ValidationError(f"File: '{fpath}' Does not exist") |
|
|
raise serializers.ValidationError(f"File: '{fpath}' Does not exist") |
|
|
|
|
|
|
|
|
rel = os.path.basename(data) |
|
|
|
|
|
|
|
|
rel = os.path.basename(unquote(data)) |
|
|
return File(open(fpath, "rb"), rel) |
|
|
return File(open(fpath, "rb"), rel) |
|
|
# return File(open(fpath, 'rb'), os.path.basename(data)) |
|
|
# return File(open(fpath, 'rb'), os.path.basename(data)) |
|
|
|
|
|
|
|
|
@ -521,7 +525,7 @@ class UploadChatMediaSerializer(serializers.Serializer): |
|
|
f"{settings.MEDIA_URL.rstrip('/')}/{thumb_rel.replace(os.sep, '/')}", |
|
|
f"{settings.MEDIA_URL.rstrip('/')}/{thumb_rel.replace(os.sep, '/')}", |
|
|
) |
|
|
) |
|
|
except Exception as e: |
|
|
except Exception as e: |
|
|
print(f"Failed to generate video thumbnail: {e}") |
|
|
|
|
|
|
|
|
print(f"Skipping video thumbnail generation: {e}") |
|
|
result["thumbnail_url"] = None |
|
|
result["thumbnail_url"] = None |
|
|
else: |
|
|
else: |
|
|
result["thumbnail_url"] = None |
|
|
result["thumbnail_url"] = None |
|
|
@ -608,7 +612,7 @@ class UploadTmpSerializer(serializers.Serializer): |
|
|
f"{settings.MEDIA_URL.rstrip('/')}/{thumb_rel.replace(os.sep, '/')}", |
|
|
f"{settings.MEDIA_URL.rstrip('/')}/{thumb_rel.replace(os.sep, '/')}", |
|
|
) |
|
|
) |
|
|
except Exception as e: |
|
|
except Exception as e: |
|
|
print("Failed to generate video thumbnail:", e) |
|
|
|
|
|
|
|
|
print("Skipping video thumbnail generation:", e) |
|
|
result["thumbnail_url"] = None |
|
|
result["thumbnail_url"] = None |
|
|
else: |
|
|
else: |
|
|
result["thumbnail_url"] = None |
|
|
result["thumbnail_url"] = None |
|
|
|