diff options
author | 2022-11-18 14:49:04 -0500 | |
---|---|---|
committer | 2022-11-18 14:49:04 -0500 | |
commit | 05a2b1a3cc4b70de10c8793993eb05c6ad0fd16e (patch) | |
tree | ad247a671b2fad122ddf440cb8b8d54e6a1c4cd0 | |
parent | Add override for timeit (diff) |
Add `size` and `compression` to attachment fields
-rw-r--r-- | snekbox/api/resources/eval.py | 4 | ||||
-rw-r--r-- | snekbox/snekio.py | 13 |
2 files changed, 15 insertions, 2 deletions
diff --git a/snekbox/api/resources/eval.py b/snekbox/api/resources/eval.py index b0678ac..38781ba 100644 --- a/snekbox/api/resources/eval.py +++ b/snekbox/api/resources/eval.py @@ -64,7 +64,9 @@ class EvalResource: ... { ... "name": "output.png", ... "mime": "image/png", - ... "content" "...=", # Base64 encoded zlib compressed content + ... "size": 57344, + ... "compression": "zlib", + ... "content": "eJzzSM3...=" # Base64-encoded ... } ... ] ... } diff --git a/snekbox/snekio.py b/snekbox/snekio.py index fd0362d..3074041 100644 --- a/snekbox/snekio.py +++ b/snekbox/snekio.py @@ -43,8 +43,19 @@ class FileAttachment: """MIME type of the attachment.""" return mimetypes.guess_type(self.name)[0] + @property + def size(self) -> int: + """Size of the attachment.""" + return len(self.content) + def to_dict(self) -> dict[str, str]: """Convert the attachment to a dict.""" cmp = zlib.compress(self.content) content = b64encode(cmp).decode("ascii") - return {"name": self.name, "mime": self.mime, "content": content} + return { + "name": self.name, + "mime": self.mime, + "size": self.size, + "compression": "zlib", + "content": content, + } |