@@ -136,21 +136,35 @@ def initialize_handlers(self):
136136 async def get_document (
137137 self : YDocExtension ,
138138 * ,
139- path : str ,
140- content_type : Literal ["notebook" , "file" ],
141- file_format : Literal ["json" , "text" ],
139+ path : str | None = None ,
140+ content_type : str | None = None ,
141+ file_format : Literal ["json" , "text" ] | None = None ,
142+ document_id : str | None = None ,
142143 copy : bool = True ,
143144 ) -> YBaseDoc | None :
144145 """Get a view of the shared model for the matching document.
145146
147+ You need to provide either a ``document_id`` or the ``path``,
148+ the ``content_type`` and the ``file_format``.
149+
146150 If `copy=True`, the returned shared model is a fork, meaning that any changes
147151 made to it will not be propagated to the shared model used by the application.
148152 """
149- file_id_manager = self .serverapp .web_app .settings ["file_id_manager" ]
150- file_id = file_id_manager .index (path )
151-
152- encoded_path = encode_file_path (file_format , content_type , file_id )
153- room_id = room_id_from_encoded_path (encoded_path )
153+ error_msg = "You need to provide either a ``document_id`` or the ``path``, the ``content_type`` and the ``file_format``."
154+ if document_id is None :
155+ if path is None or content_type is None or file_format is None :
156+ raise ValueError (error_msg )
157+
158+ file_id_manager = self .serverapp .web_app .settings ["file_id_manager" ]
159+ file_id = file_id_manager .index (path )
160+
161+ encoded_path = encode_file_path (file_format , content_type , file_id )
162+ room_id = room_id_from_encoded_path (encoded_path )
163+
164+ elif path is not None or content_type is not None or file_format is not None :
165+ raise ValueError (error_msg )
166+ else :
167+ room_id = document_id
154168
155169 try :
156170 room = await self .ywebsocket_server .get_room (room_id )
@@ -164,7 +178,7 @@ async def get_document(
164178 fork_ydoc = Doc ()
165179 fork_ydoc .apply_update (update )
166180
167- return YDOCS .get (content_type , YDOCS ["file" ])(fork_ydoc )
181+ return YDOCS .get (room . file_type , YDOCS ["file" ])(fork_ydoc )
168182 else :
169183 return room ._document
170184
0 commit comments