3232 SourceAssetLinkResponse ,
3333 SourceMediaItemLinkResponse ,
3434)
35+ from src .common .base_dto import (
36+ AspectRatioEnum ,
37+ GenerationModelEnum ,
38+ MimeTypeEnum ,
39+ )
3540from src .galleries .dto .gallery_search_dto import GallerySearchDto
41+ from src .images .dto .upscale_imagen_dto import UpscaleImagenDto
42+ from src .images .imagen_service import ImagenService
3643from src .images .repository .media_item_repository import MediaRepository
3744from src .source_assets .repository .source_asset_repository import (
3845 SourceAssetRepository ,
3946)
4047from src .users .user_model import UserModel , UserRoleEnum
4148from src .workspaces .repository .workspace_repository import WorkspaceRepository
4249from src .workspaces .schema .workspace_model import WorkspaceScopeEnum
43- from src .workspaces .workspace_auth_guard import workspace_auth_service
50+ from src .workspaces .workspace_auth_guard import WorkspaceAuth
4451
4552logger = logging .getLogger (__name__ )
4653
@@ -56,12 +63,16 @@ def __init__(
5663 source_asset_repo : SourceAssetRepository = Depends (),
5764 workspace_repo : WorkspaceRepository = Depends (),
5865 iam_signer_credentials : IamSignerCredentials = Depends (),
66+ workspace_auth : WorkspaceAuth = Depends (),
67+ imagen_service : ImagenService = Depends (),
5968 ):
6069 """Initializes the service with its dependencies."""
6170 self .media_repo = media_repo
6271 self .source_asset_repo = source_asset_repo
6372 self .workspace_repo = workspace_repo
6473 self .iam_signer_credentials = iam_signer_credentials
74+ self .workspace_auth = workspace_auth
75+ self .imagen_service = imagen_service
6576
6677 async def _enrich_source_asset_link (
6778 self , link : SourceAssetLink
@@ -70,7 +81,7 @@ async def _enrich_source_asset_link(
7081 Fetches the source asset document and generates a presigned URL for it.
7182 """
7283 asset_doc = await self .source_asset_repo .get_by_id (link .asset_id )
73-
84+
7485 if not asset_doc :
7586 return None
7687
@@ -171,6 +182,16 @@ async def _create_gallery_response(
171182 if uri
172183 ]
173184
185+ # 1.5 Create tasks for original media URLs
186+ all_original_gcs_uris = item .original_gcs_uris or []
187+ original_url_tasks = [
188+ asyncio .to_thread (
189+ self .iam_signer_credentials .generate_presigned_url , uri
190+ )
191+ for uri in all_original_gcs_uris
192+ if uri
193+ ]
194+
174195 # 2. Create tasks for thumbnail URLs
175196 thumbnail_tasks = [
176197 asyncio .to_thread (
@@ -199,11 +220,13 @@ async def _create_gallery_response(
199220 # 5. Gather all results concurrently
200221 (
201222 presigned_urls ,
223+ original_presigned_urls ,
202224 presigned_thumbnail_urls ,
203225 enriched_source_assets_with_nones ,
204226 enriched_source_media_items_with_nones ,
205227 ) = await asyncio .gather (
206228 asyncio .gather (* main_url_tasks ),
229+ asyncio .gather (* original_url_tasks ),
207230 asyncio .gather (* thumbnail_tasks ),
208231 asyncio .gather (* source_asset_tasks ),
209232 asyncio .gather (* source_media_item_tasks ),
@@ -220,6 +243,7 @@ async def _create_gallery_response(
220243 return MediaItemResponse (
221244 ** item .model_dump (exclude = {"source_assets" }),
222245 presigned_urls = presigned_urls ,
246+ original_presigned_urls = original_presigned_urls ,
223247 presigned_thumbnail_urls = presigned_thumbnail_urls ,
224248 enriched_source_assets = enriched_source_assets or None ,
225249 enriched_source_media_items = enriched_source_media_items or None ,
@@ -259,7 +283,7 @@ async def get_paginated_gallery(
259283 )
260284
261285 async def get_media_by_id (
262- self , item_id : int , current_user : UserModel
286+ self , item_id : str , current_user : UserModel
263287 ) -> Optional [MediaItemResponse ]:
264288 """
265289 Retrieves a single media item, performs an authorization check,
@@ -282,10 +306,13 @@ async def get_media_by_id(
282306 )
283307
284308 # Use the centralized authorization logic
285- await workspace_auth_service .authorize (
309+ await self . workspace_auth .authorize (
286310 workspace_id = item .workspace_id ,
287311 user = current_user ,
288- workspace_repo = self .workspace_repo ,
289312 )
290313
291314 return await self ._create_gallery_response (item )
315+
316+
317+
318+
0 commit comments