Skip to content

Commit

Permalink
feat: Add external Supabase URL support for generating file signed URL (
Browse files Browse the repository at this point in the history
#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):
  • Loading branch information
StanGirard authored Sep 10, 2024
1 parent 9e18514 commit 9cbb47f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)

0 comments on commit 9cbb47f

Please sign in to comment.