@@ -210,11 +210,11 @@ async def remove_crawls_from_collection(
210
210
return await self .get_collection_out (coll_id , org )
211
211
212
212
async def get_collection_raw (
213
- self , coll_id : UUID , public_only : bool = False
213
+ self , coll_id : UUID , public_or_unlisted_only : bool = False
214
214
) -> Dict [str , Any ]:
215
215
"""Get collection by id as dict from database"""
216
216
query : dict [str , object ] = {"_id" : coll_id }
217
- if public_only :
217
+ if public_or_unlisted_only :
218
218
query ["access" ] = {"$in" : ["public" , "unlisted" ]}
219
219
220
220
result = await self .collections .find_one (query )
@@ -224,17 +224,21 @@ async def get_collection_raw(
224
224
return result
225
225
226
226
async def get_collection (
227
- self , coll_id : UUID , public_only : bool = False
227
+ self , coll_id : UUID , public_or_unlisted_only : bool = False
228
228
) -> Collection :
229
229
"""Get collection by id"""
230
- result = await self .get_collection_raw (coll_id , public_only )
230
+ result = await self .get_collection_raw (coll_id , public_or_unlisted_only )
231
231
return Collection .from_dict (result )
232
232
233
233
async def get_collection_out (
234
- self , coll_id : UUID , org : Organization , resources = False , public_only = False
234
+ self ,
235
+ coll_id : UUID ,
236
+ org : Organization ,
237
+ resources = False ,
238
+ public_or_unlisted_only = False ,
235
239
) -> CollOut :
236
240
"""Get CollOut by id"""
237
- result = await self .get_collection_raw (coll_id , public_only )
241
+ result = await self .get_collection_raw (coll_id , public_or_unlisted_only )
238
242
239
243
if resources :
240
244
result ["resources" ] = await self .get_collection_crawl_resources (coll_id )
@@ -248,6 +252,26 @@ async def get_collection_out(
248
252
249
253
return CollOut .from_dict (result )
250
254
255
+ async def get_public_collection_out (
256
+ self , coll_id : UUID , org : Organization
257
+ ) -> CollOut :
258
+ """Get PublicCollOut by id"""
259
+ result = await self .get_collection_raw (coll_id )
260
+
261
+ if result .get ("access" ) != "public" :
262
+ raise HTTPException (status_code = 404 , detail = "collection_not_found" )
263
+
264
+ result ["resources" ] = await self .get_collection_crawl_resources (coll_id )
265
+
266
+ thumbnail = result .get ("thumbnail" )
267
+ if thumbnail :
268
+ image_file = ImageFile (** thumbnail )
269
+ result ["thumbnail" ] = await image_file .get_public_image_file_out (
270
+ org , self .storage_ops
271
+ )
272
+
273
+ return PublicCollOut .from_dict (result )
274
+
251
275
async def list_collections (
252
276
self ,
253
277
org : Organization ,
@@ -825,7 +849,7 @@ async def get_collection_public_replay(
825
849
org : Organization = Depends (org_public ),
826
850
):
827
851
coll = await colls .get_collection_out (
828
- coll_id , org , resources = True , public_only = True
852
+ coll_id , org , resources = True , public_or_unlisted_only = True
829
853
)
830
854
response .headers ["Access-Control-Allow-Origin" ] = "*"
831
855
response .headers ["Access-Control-Allow-Headers" ] = "*"
@@ -920,6 +944,24 @@ async def get_org_public_collections(
920
944
sort_direction = sortDirection ,
921
945
)
922
946
947
+ @app .get (
948
+ "/public-collections/{org_slug}/collections/{coll_id}" ,
949
+ tags = ["collections" ],
950
+ response_model = PublicCollOut ,
951
+ )
952
+ async def get_public_collection (
953
+ org_slug : str ,
954
+ coll_id : UUID ,
955
+ ):
956
+ try :
957
+ org = await colls .orgs .get_org_by_slug (org_slug )
958
+ # pylint: disable=broad-exception-caught
959
+ except Exception :
960
+ # pylint: disable=raise-missing-from
961
+ raise HTTPException (status_code = 404 , detail = "collection_not_found" )
962
+
963
+ return await colls .get_public_collection_out (coll_id , org )
964
+
923
965
@app .get (
924
966
"/orgs/{oid}/collections/{coll_id}/urls" ,
925
967
tags = ["collections" ],
0 commit comments