Skip to content

Commit

Permalink
Merge pull request #22 from ostis-ai/feature/binary_content
Browse files Browse the repository at this point in the history
feat: convert from base64 to binary if is base64 string
  • Loading branch information
NikitaZotov authored Sep 19, 2022
2 parents 79e434e + 5426b08 commit f67a8c4
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion server/handlers/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

import tornado.web
import json
import base64
import binascii

from sc_client import client
from sc_client.constants import sc_types
Expand Down Expand Up @@ -151,11 +153,17 @@ def get(self):
return logic.serialize_error(self, 404, 'Invalid arguments')

result = client.get_link_content(addr)
result = result[0].data
try:
data = base64.b64decode(result, validate=True)
except binascii.Error:
data = result

if len(result) == 0:
return logic.serialize_error(self, 404, 'Content not found')

self.set_header("Content-Type", logic.get_link_mime(addr))
self.finish(result[0].data)
self.finish(data)


class LinkFormat(base.BaseHandler):
Expand Down

0 comments on commit f67a8c4

Please sign in to comment.