File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1919from sqlalchemy .orm import Session
2020
2121from ..infra .config import conversation_workspace
22+ from ..infra .db import commit_now
2223from ..models import Conversation , ConversationFile , User , new_id
23- from .. models . db import commit_now
24+ from .access import get_owned
2425from .errors import InvalidRequest , NotFound , PayloadTooLarge
2526
2627MAX_UPLOAD_BYTES = 100 * 1024 * 1024
@@ -87,9 +88,14 @@ async def store_upload(
8788
8889def delete_upload (db : Session , conversation : Conversation , file_id : str ) -> None :
8990 """Forget an upload and unlink it from the workspace."""
90- row = db .get (ConversationFile , file_id )
91- if row is None or row .conversation_id != conversation .id :
92- raise NotFound ("file not found" )
91+ row = get_owned (
92+ db ,
93+ ConversationFile ,
94+ file_id ,
95+ owner_field = "conversation_id" ,
96+ owner_value = conversation .id ,
97+ detail = "file not found" ,
98+ )
9399 with contextlib .suppress (OSError ):
94100 Path (row .path ).unlink ()
95101 db .delete (row )
You can’t perform that action at this time.
0 commit comments