From 9cbb47f75aa261d74108be761d16c35a2e5bd298 Mon Sep 17 00:00:00 2001 From: Stan Girard Date: Tue, 10 Sep 2024 16:53:44 +0200 Subject: [PATCH] feat: Add external Supabase URL support for generating file signed URL (#3179) # Description Please include a summary of the changes and the related issue. Please also include relevant motivation and context. ## Checklist before requesting a review Please delete options that are not relevant. - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my code - [ ] I have commented hard-to-understand areas - [ ] I have ideally added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged ## Screenshots (if appropriate): --- .env.example | 1 + .../modules/upload/service/generate_file_signed_url.py | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.env.example b/.env.example index 4203018c00a0..da38f069983c 100644 --- a/.env.example +++ b/.env.example @@ -28,6 +28,7 @@ NEXT_PUBLIC_SHOW_TOKENS=false LOG_LEVEL=INFO SUPABASE_URL=http://host.docker.internal:54321 +EXTERNAL_SUPABASE_URL=http://localhost:54321 SUPABASE_SERVICE_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImV4cCI6MTk4MzgxMjk5Nn0.EGIM96RAZx35lJzdJsyH-qQwv8Hdp7fsn3W0YpN81IU PG_DATABASE_URL=postgresql://postgres:postgres@host.docker.internal:54322/postgres PG_DATABASE_ASYNC_URL=postgresql+asyncpg://postgres:postgres@host.docker.internal:54322/postgres diff --git a/backend/api/quivr_api/modules/upload/service/generate_file_signed_url.py b/backend/api/quivr_api/modules/upload/service/generate_file_signed_url.py index f4d228b1b9f3..3a3cb6f56fc8 100644 --- a/backend/api/quivr_api/modules/upload/service/generate_file_signed_url.py +++ b/backend/api/quivr_api/modules/upload/service/generate_file_signed_url.py @@ -2,11 +2,13 @@ from quivr_api.modules.dependencies import get_supabase_client from supabase.client import Client +import os logger = get_logger() SIGNED_URL_EXPIRATION_PERIOD_IN_SECONDS = 3600 - +EXTERNAL_SUPABASE_URL = os.getenv("EXTERNAL_SUPABASE_URL", None) +SUPABASE_URL = os.getenv("SUPABASE_URL", None) def generate_file_signed_url(path): supabase_client: Client = get_supabase_client() @@ -21,6 +23,9 @@ def generate_file_signed_url(path): }, ) logger.info("RESPONSE SIGNED URL", response) + # Replace in the response the supabase url by the external supabase url in the object signedURL + if EXTERNAL_SUPABASE_URL and SUPABASE_URL: + response["signedURL"] = response["signedURL"].replace(SUPABASE_URL, EXTERNAL_SUPABASE_URL) return response except Exception as e: logger.error(e)