comparison sat/plugins/plugin_xep_0363.py @ 3293:f5a5aa9fa73a

plugin XEP-0363: fixed fileHTTPUploadGetSlot
author Goffi <goffi@goffi.org>
date Tue, 09 Jun 2020 05:58:57 +0200
parents 9057713ab124
children 6505e5cc6ab9
comparison
equal deleted inserted replaced
3292:84f77f04aa08 3293:f5a5aa9fa73a
91 ) 91 )
92 host.bridge.addMethod( 92 host.bridge.addMethod(
93 "fileHTTPUploadGetSlot", 93 "fileHTTPUploadGetSlot",
94 ".plugin", 94 ".plugin",
95 in_sign="sisss", 95 in_sign="sisss",
96 out_sign="(ss)", 96 out_sign="(ssaa{ss})",
97 method=self._getSlot, 97 method=self._getSlot,
98 async_=True, 98 async_=True,
99 ) 99 )
100 host.plugins["UPLOAD"].register( 100 host.plugins["UPLOAD"].register(
101 "HTTP Upload", self.getHTTPUploadEntity, self.fileHTTPUpload 101 "HTTP Upload", self.getHTTPUploadEntity, self.fileHTTPUpload
270 """Get an upload slot 270 """Get an upload slot
271 271
272 This method can be used when uploading is done by the frontend 272 This method can be used when uploading is done by the frontend
273 @param filename(unicode): name of the file to upload 273 @param filename(unicode): name of the file to upload
274 @param size(int): size of the file (must be non null) 274 @param size(int): size of the file (must be non null)
275 @param upload_jid(jid.JID(), None, ''): HTTP upload capable entity 275 @param upload_jid(str, ''): HTTP upload capable entity
276 @param content_type(unicode, None): MIME type of the content 276 @param content_type(unicode, None): MIME type of the content
277 empty string or None to guess automatically 277 empty string or None to guess automatically
278 """ 278 """
279 client = self.host.getClient(profile_key) 279 client = self.host.getClient(profile_key)
280 filename = filename.replace("/", "_") 280 filename = filename.replace("/", "_")
281 return defer.ensureDeferred(self.getSlot( 281 d = defer.ensureDeferred(self.getSlot(
282 client, filename, size, content_type or None, upload_jid or None 282 client, filename, size, content_type or None, jid.JID(upload_jid) or None
283 )) 283 ))
284 d.addCallback(lambda slot: (slot.get, slot.put, slot.headers))
285 return d
284 286
285 async def getSlot(self, client, filename, size, content_type=None, upload_jid=None): 287 async def getSlot(self, client, filename, size, content_type=None, upload_jid=None):
286 """Get a slot (i.e. download/upload links) 288 """Get a slot (i.e. download/upload links)
287 289
288 @param filename(unicode): name to use for the upload 290 @param filename(unicode): name to use for the upload
302 304
303 if upload_jid is None: 305 if upload_jid is None:
304 try: 306 try:
305 upload_jid = client.http_upload_service 307 upload_jid = client.http_upload_service
306 except AttributeError: 308 except AttributeError:
307 found_entity = await self.getHTTPUploadEntity(profile=client.profile) 309 found_entity = await self.getHTTPUploadEntity(client)
308 return await self.getSlot( 310 return await self.getSlot(
309 client, filename, size, content_type, found_entity) 311 client, filename, size, content_type, found_entity)
310 else: 312 else:
311 if upload_jid is None: 313 if upload_jid is None:
312 raise exceptions.NotFound("No HTTP upload entity found") 314 raise exceptions.NotFound("No HTTP upload entity found")