feat(hosted_file): add GET /{hosted_file_id}/links endpoint

Returns all hosted_file_link records for a file with link_to_id resolved
to random strings (ID Vision compliant). Used by admin file management to
assess what objects reference a file before deletion.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Scott Idem
2026-06-18 17:17:18 -04:00
parent 50b1e00903
commit 2b1044eebb
2 changed files with 47 additions and 0 deletions

View File

@@ -370,6 +370,37 @@ async def check_hosted_file_obj_w_hash_action(
return mk_resp(data=False, status_code=404, response=response, status_message="No record found for this hash.")
@router.get('/{hosted_file_id}/links', response_model=Resp_Body_Base)
async def get_file_links_action(
hosted_file_id: str = Path(min_length=11, max_length=22),
account: AccountContext = Depends(get_account_context),
):
"""
Return all hosted_file_link records for a file, with link_to_id_random resolved.
Used by admin file management to show what objects a file is linked to.
"""
file_id_int = redis_lookup_id_random(record_id_random=hosted_file_id, table_name='hosted_file')
if not file_id_int:
raise HTTPException(status_code=404, detail="Hosted file not found.")
raw_links = get_hosted_file_link_rec_list(hosted_file_id=file_id_int)
if not raw_links:
return mk_resp(data=[])
links = []
for link in raw_links:
link_to_type = link.get('link_to_type')
link_to_id_int = link.get('link_to_id')
link_to_id_random = get_id_random(record_id=link_to_id_int, table_name=link_to_type) if link_to_type and link_to_id_int else None
links.append({
'link_to_type': link_to_type,
'link_to_id': link_to_id_random,
'link_to_id_random': link_to_id_random,
})
return mk_resp(data=links)
@router.delete('/{hosted_file_id}', response_model=Resp_Body_Base)
async def delete_file_action(
hosted_file_id: str = Path(min_length=11, max_length=22),