2
0
mirror of https://github.com/xcat2/confluent.git synced 2026-11-19 17:02:22 +00:00

Allow API caller to request raw binary images.

This can make it more straightforward as an interface, and also defer the penalty for base64 processing.
This commit is contained in:
Jarrod Johnson
2026-11-06 09:37:58 -05:00
parent b0fff4a8fe
commit 58d4c6a5a9
2 changed files with 25 additions and 4 deletions
+1 -1
View File
@@ -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
+24 -3
View File
@@ -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):