Portado tapas

This commit is contained in:
2024-08-21 17:54:09 -03:00
parent d57a58b45a
commit 1e5f913c70
8 changed files with 39 additions and 7 deletions

View File

@ -1,33 +0,0 @@
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",
}
"""
if not req:
return "Foo", 200, {"Content-Type": "text/plain"}
try:
args = loads(req)
except Exception:
return "Bad Request", 400
c = Cover(**args)
byte_arr = BytesIO()
c.image.save(byte_arr, format="JPEG")
return (
f'<img src="data:image/jpeg;base64, {base64.b64encode(byte_arr.getvalue()).decode("utf-8")}" style="width: 100%; border: solid 1px #aaa;">',
200,
{"Content-Type": "text/html"},
)