Skip to content
This repository has been archived by the owner on Jun 24, 2024. It is now read-only.

Commit

Permalink
wip, thumbor on one route, with params interpreted as thumbor
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandreJunod committed Nov 6, 2023
1 parent 097adfa commit 7144a75
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 10 deletions.
4 changes: 4 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ services:
networks:
- isolated
- default
- geocity_network

# Builder for the geocity_qgis image.
qgis:
Expand Down Expand Up @@ -113,3 +114,6 @@ networks:
# Use this for containers that should only be able to communicate with Django
isolated:
name: ${ISOLATED_NETWORK_NAME}
geocity_network:
name: geocity_network
driver: bridge
36 changes: 26 additions & 10 deletions geocity/apps/api/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import datetime
import os

import requests
from django.conf import settings
from django.contrib.auth.models import AnonymousUser, User
from django.db.models import F, Prefetch, Q
Expand Down Expand Up @@ -474,19 +475,34 @@ def get_queryset(self):


def image_display(request, form_id, image_name):
image_dir = settings.PRIVATE_MEDIA_ROOT
no_thumbor = request.GET.get("no_thumbor", False)
height = request.GET.get("height", None)
width = request.GET.get("width", None)
# query_params = request.query_params

image_path = os.path.join(
image_dir, f"permit_requests_uploads/{form_id}/{image_name}"
)
# print(query_params)

# TODO: Ajouter de la sécurité afin de savoir si l'image peut-être affichée ou non
if os.path.exists(image_path):
image_file = open(image_path, "rb")
response = FileResponse(image_file, content_type="image/jpeg")
return response
if no_thumbor:
image_dir = settings.PRIVATE_MEDIA_ROOT

image_path = os.path.join(
image_dir, f"permit_requests_uploads/{form_id}/{image_name}"
)

# TODO: Ajouter de la sécurité afin de savoir si l'image peut-être affichée ou non
if os.path.exists(image_path):
image_file = open(image_path, "rb")
response = FileResponse(image_file, content_type="image/jpeg")
return response
else:
return JsonResponse({"message": "Image non trouvée."}, status=404)
else:
return JsonResponse({"message": "Image non trouvée."}, status=404)
INTERNAL_WEB_ROOT_URL = "http://web:9000"
image_url = f"{INTERNAL_WEB_ROOT_URL}/agenda/image/display/permit_requests_uploads/{form_id}/{image_name}?no_thumbor=true"
thumbor_params = "300x200"
resp = requests.get(f"http://nginx-proxy/unsafe/{thumbor_params}/{image_url}")
thumbor_response = FileResponse(resp, content_type="image/jpeg")
return thumbor_response


class AgendaViewSet(viewsets.ReadOnlyModelViewSet):
Expand Down
6 changes: 6 additions & 0 deletions geocity/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@
"IP_WHITELIST",
"NETWORK_WHITELIST",
"LOGOUT_REDIRECT_HOSTNAME_WHITELIST",
"THUMBOR_SERVICE_URL",
),
}

Expand Down Expand Up @@ -411,6 +412,11 @@
"localhost,geocity.ch",
"Domaines autorisés à la redirection après logout",
),
"THUMBOR_SERVICE_URL": (
"http://host.docker.internal:8083",
"URL du service thumbor (https://github.com/thumbor/thumbor), recommandé pour l'optimisation des images du module Agenda",
str,
),
}

TEMPLATES = [
Expand Down

0 comments on commit 7144a75

Please sign in to comment.