diff --git a/confluent_server/confluent/httpapi.py b/confluent_server/confluent/httpapi.py index 04db394a..d040497c 100644 --- a/confluent_server/confluent/httpapi.py +++ b/confluent_server/confluent/httpapi.py @@ -1119,7 +1119,7 @@ async def resourcehandler_backend(req, make_response): for datum in _assemble_html(hdlr, resource, lquerydict, url, extension): pagecontent += datum - elif mimetype in ('application/octet-stream', 'image/png', 'image/jpeg'): + elif mimetype in ('application/octet-stream', 'image/*'): pagecontent = b'' async for datum in _assemble_binary(hdlr, resource, url, extension, mimetype): pagecontent += datum diff --git a/confluent_server/confluent/messages.py b/confluent_server/confluent/messages.py index 10f5f4fa..3f67689b 100644 --- a/confluent_server/confluent/messages.py +++ b/confluent_server/confluent/messages.py @@ -115,6 +115,9 @@ class ConfluentMessage(object): self.kvpairs = {} raise NotImplementedError("Must be subclassed!") + def binary(self, mimetype): + raise NotImplementedError("Binary data not available for this message") + def json(self): # This will create the canonical json representation of this message if hasattr(self, 'stripped') and self.stripped: @@ -2091,11 +2094,29 @@ class ScreenShot(ConfluentMessage): if isinstance(imgformat, bytes): imgformat = imgformat.decode() self.myargs = (imgdata, node, imgformat) - self.kvpairs = {node: {'image': {'imgformat': imgformat, 'imgdata': base64.b64encode(imgdata).decode()}}} + self._bynode = True def binary(self, mimetype): - if mimetype == 'application/octet-stream': - return self.myargs[0] + return self.myargs[0] + + def strip_node(self, node): + self._bynode = False + + def json(self): + imgdata, node, imgformat = self.myargs + if self._bynode: + self.kvpairs = {node: {'image': {'imgformat': imgformat, 'imgdata': base64.b64encode(imgdata).decode()}}} + else: + self.kvpairs = {'image': {'imgformat': imgformat, 'imgdata': base64.b64encode(imgdata).decode()}} + return super().json() + + def raw(self): + imgdata, node, imgformat = self.myargs + if self._bynode: + self.kvpairs = {node: {'image': {'imgformat': imgformat, 'imgdata': base64.b64encode(imgdata).decode()}}} + else: + self.kvpairs = {'image': {'imgformat': imgformat, 'imgdata': base64.b64encode(imgdata).decode()}} + return super().raw() class CryptedAttributes(Attributes):