From 72065c0d0df859319fdaad5b48c1d5eec79157d2 Mon Sep 17 00:00:00 2001 From: ewandor Date: Mon, 20 Mar 2023 14:30:43 +0100 Subject: [PATCH] Adding static meta data on signatures --- back/app/contract/print/__init__.py | 15 ++++++++++++++ .../contract/print/templates/opengraph.html | 10 ++++++++++ front/nginx.prod.conf | 19 ++++++++++++++++++ nginx/nginx.conf | 20 +++++++++++++++++++ 4 files changed, 64 insertions(+) create mode 100644 back/app/contract/print/templates/opengraph.html diff --git a/back/app/contract/print/__init__.py b/back/app/contract/print/__init__.py index bea1e56d..90a1e8eb 100644 --- a/back/app/contract/print/__init__.py +++ b/back/app/contract/print/__init__.py @@ -139,3 +139,18 @@ def retrieve_signature_png(filepath): base64_utf8_str = base64.b64encode(b_content).decode('utf-8') ext = filepath.split('.')[-1] return f'data:image/{ext};base64,{base64_utf8_str}' + + +@print_router.get("/opengraph/{signature_id}", response_class=HTMLResponse) +async def get_signature_opengraph(signature_id: str, request: Request) -> str: + contract = await Contract.find_by_signature_id(signature_id) + signature = contract.get_signature(signature_id) + template = templates.get_template("opengraph.html") + + signatory = signature.representative.label if signature.representative else signature.entity.label + + return template.render({ + "signatory": signatory, + "title": contract.label, + "origin_url": f"{request.url.scheme}://{request.url.hostname}" + }) diff --git a/back/app/contract/print/templates/opengraph.html b/back/app/contract/print/templates/opengraph.html new file mode 100644 index 00000000..34ce2bf5 --- /dev/null +++ b/back/app/contract/print/templates/opengraph.html @@ -0,0 +1,10 @@ + + + + + + + diff --git a/front/nginx.prod.conf b/front/nginx.prod.conf index fcb6d7d7..2cc4f73a 100644 --- a/front/nginx.prod.conf +++ b/front/nginx.prod.conf @@ -41,6 +41,25 @@ http { default_type text/javascript; } + location /contracts/signature/ { + set $is_robot 0; + if ($http_user_agent ~* "Discordbot|googlebot|bingbot|yandex|baiduspider|twitterbot|facebookexternalhit|rogerbot|linkedinbot|embedly|quora link preview|showyoubot|outbrain|pinterest\/0\.|pinterestbot|slackbot|vkShare|W3C_Validator|whatsapp") { + rewrite /contracts/signature/(.*) /api/v1/contract/print/opengraph/$1 last; + proxy_pass http://docker-back; + set $is_robot 1; + } + + if ($is_robot = 0) { + rewrite ^ /index.html?$args last; + } + + proxy_redirect off; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Host $server_name; + } + location /api/v1/ { proxy_pass http://docker-back/; proxy_redirect off; diff --git a/nginx/nginx.conf b/nginx/nginx.conf index 1cf30cc1..af42db3d 100644 --- a/nginx/nginx.conf +++ b/nginx/nginx.conf @@ -26,6 +26,26 @@ http { proxy_set_header X-Forwarded-Host $server_name; } + location /contracts/signature/ { + set $is_robot 0; + if ($http_user_agent ~* "Discordbot|googlebot|bingbot|yandex|baiduspider|twitterbot|facebookexternalhit|rogerbot|linkedinbot|embedly|quora link preview|showyoubot|outbrain|pinterest\/0\.|pinterestbot|slackbot|vkShare|W3C_Validator|whatsapp") { + rewrite /contracts/signature/(.*) /api/v1/contract/print/opengraph/$1 last; + proxy_pass http://docker-back; + break; + set $is_robot 1; + } + + if ($is_robot = 0) { + proxy_pass http://docker-front; + } + + proxy_redirect off; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Host $server_name; + } + location /api/v1/ { proxy_pass http://docker-back/; proxy_redirect off;