diff --git a/backend/apimanager/media_views.py b/backend/apimanager/media_views.py index 12ee491..266ca68 100644 --- a/backend/apimanager/media_views.py +++ b/backend/apimanager/media_views.py @@ -7,6 +7,8 @@ from rest_framework.response import Response from rest_framework.parsers import MultiPartParser, FormParser from django.core.files.storage import default_storage from django.conf import settings +from PIL import Image +import io from .serializers import ( MediaSerializer @@ -15,6 +17,23 @@ from .serializers import ( class MediaUpload(APIView): parser_classes = (MultiPartParser, FormParser) + def reduce_image_quality(self, image, quality=20): + try: + img = Image.open(image) + img_io = io.BytesIO() + + # Handle different image modes + if img.mode in ("RGBA", "P"): + img = img.convert("RGB") + + img_format = img.format if img.format else 'JPEG' + img.save(img_io, format=img_format, quality=quality) + img_io.seek(0) + return img_io + except Exception as e: + print(f"Error reducing image quality: {e}") + return image + def post(self, request, *args, **kwargs): file_serializer = MediaSerializer(data=request.data) if file_serializer.is_valid(): @@ -29,12 +48,20 @@ class MediaUpload(APIView): file_path = f"{file_path_base}/{resource_type}/{resource_id}/media/{file_unique_slug+resource_id+f.name}" else: file_path = f"{file_path_base}/{resource_type}/media/{file_unique_slug+resource_id+f.name}" - default_storage.save(file_path, f) + + # Reduce image quality if the file is an image + if f.content_type.startswith('image'): + reduced_image = self.reduce_image_quality(f, quality=65) + default_storage.save(file_path, reduced_image) + else: + # Save non-image files directly + default_storage.save(file_path, f) return Response(file_serializer.data, status=status.HTTP_201_CREATED) else: return Response(file_serializer.errors, status=status.HTTP_400_BAD_REQUEST) + class ListMedia(APIView): def get(self, request, resource_type, resource_id, format=None): if resource_id != resource_type: diff --git a/backend/apimanager/publish_methods.py b/backend/apimanager/publish_methods.py index 86ee000..5fb2585 100644 --- a/backend/apimanager/publish_methods.py +++ b/backend/apimanager/publish_methods.py @@ -50,9 +50,10 @@ def github_deploy(): git_commands = {} git_commands["git_init"] = ['git', 'init'] git_commands["git_add"] = ['git', 'add', '.'] + git_commands["git_pull"] = ['git', 'pull'] git_commands["git_config_email"] = ['git', 'config', '--local', 'user.email'] git_commands["git_config_name"] = ['git', 'config', '--local', 'user.name'] - git_commands["git_commit"] = ['git', 'commit', '-m', '"Update website"'] + git_commands["git_commit"] = ['git', 'commit', '-m', 'Update website'] git_commands["git_branch"] = ['git', 'branch', '-m', 'main'] git_commands["git_add_url"] = ['git', 'remote', 'add', 'origin'] git_commands["git_push"] = ['git', 'push', '-u', 'origin', 'main'] @@ -60,9 +61,6 @@ def github_deploy(): data_location = f'{settings.BASE_DIR}/deploy/' deploy_location = settings.DEPLOY_CONFIG["DEPLOY_LOCATION"]+'/ghpages' - run_gh_build = ['npm', 'run', 'build:ghpages'] - - subprocess.run(run_gh_build, cwd=settings.DEPLOY_CONFIG["DEPLOY_LOCATION"].replace('/dist', ''), check=True, text=True, capture_output=True) create_404_page(deploy_location) copyData(data_location, deploy_location) diff --git a/frontend/viewable-ui/src/components/home.jsx b/frontend/viewable-ui/src/components/home.jsx index fe783d1..a823134 100755 --- a/frontend/viewable-ui/src/components/home.jsx +++ b/frontend/viewable-ui/src/components/home.jsx @@ -43,7 +43,7 @@ function HomePage(props) { - +
{introContent}