Reorg repo

This commit is contained in:
2023-05-16 12:38:37 -03:00
parent f775068850
commit 21abfbfd98
20 changed files with 18 additions and 7 deletions

32
tapas/handler.py Normal file
View File

@ -0,0 +1,32 @@
from json import loads
from tapita import Cover
from io import BytesIO
import base64
def handle(req):
"""handle a request to the function
Args:
req (str): request body
{
"title": "foo",
"subtitle": "bar",
"author": "bat",
}
"""
try:
args = loads(req)
except Exception:
return "Bad Request", 400
c = Cover(**args)
byte_arr = BytesIO()
c.image.save(byte_arr, format="JPEG")
# return Response(chart.render(is_unicode=True), mimetype="image/svg+xml")
return (
f'<img src="data:image/jpeg;base64, {base64.b64encode(byte_arr.getvalue()).decode("utf-8")}">',
200,
{"Content-Type": "text/html"},
)