@@ -136,21 +136,35 @@ def initialize_handlers(self):
136
136
async def get_document (
137
137
self : YDocExtension ,
138
138
* ,
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 ,
142
143
copy : bool = True ,
143
144
) -> YBaseDoc | None :
144
145
"""Get a view of the shared model for the matching document.
145
146
147
+ You need to provide either a ``document_id`` or the ``path``,
148
+ the ``content_type`` and the ``file_format``.
149
+
146
150
If `copy=True`, the returned shared model is a fork, meaning that any changes
147
151
made to it will not be propagated to the shared model used by the application.
148
152
"""
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
154
168
155
169
try :
156
170
room = await self .ywebsocket_server .get_room (room_id )
@@ -164,7 +178,7 @@ async def get_document(
164
178
fork_ydoc = Doc ()
165
179
fork_ydoc .apply_update (update )
166
180
167
- return YDOCS .get (content_type , YDOCS ["file" ])(fork_ydoc )
181
+ return YDOCS .get (room . file_type , YDOCS ["file" ])(fork_ydoc )
168
182
else :
169
183
return room ._document
170
184
0 commit comments