added serialized api work

This commit is contained in:
Kevin Froman 2021-01-27 18:15:06 +00:00
parent 6625b7ce19
commit a2da6b8c89
2 changed files with 32 additions and 17 deletions

View File

@ -10,20 +10,20 @@ from httpapi import miscclientapi, onionrsitesapi, apiutils
from httpapi import themeapi
from httpapi import fileoffsetreader
from httpapi.sse.private import private_sse_blueprint
from httpapi.serializedapi import serialized_api_bp
"""
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
@ -44,6 +44,7 @@ def register_private_blueprints(private_api, app):
app.register_blueprint(themeapi.theme_blueprint)
app.register_blueprint(private_sse_blueprint)
app.register_blueprint(fileoffsetreader.offset_reader_api)
app.register_blueprint(serialized_api_bp)
def _add_events_bp():
while True:

View File

@ -3,7 +3,7 @@
view and interact with onionr sites
"""
from flask import Blueprint, Response, request, abort, g
import ujson as json
import json
"""
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -32,15 +32,29 @@ def serialized(name: str) -> Response:
attr = getattr(initial, i)
if callable(attr):
data = json.loads(request.get_json(force=True))
args = data['args']
del data['args']
try:
js = request.get_json(force=True)
print('json', js, type(js))
data = json.loads(js)
args = data['args']
del data['args']
except (TypeError, ValueError) as e:
print(repr(e))
data = {}
args = []
print('data', data)
if data:
print(*args, **data)
return Response(attr(*args, **data))
resp = attr(*args, **data)
if isinstance(resp, int):
resp = str(resp)
return Response(resp)
else:
print(*args, **data)
return Response(attr(*args))
resp = attr(*args)
if isinstance(resp, int):
resp = str(resp)
return Response(resp, content_type='application/octet-stream')
else:
if isinstance(attr, int):
attr = str(attr)