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:
@@ -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
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user