added serialized api work
This commit is contained in:
parent
6625b7ce19
commit
a2da6b8c89
@ -10,20 +10,20 @@ from httpapi import miscclientapi, onionrsitesapi, apiutils
|
|||||||
from httpapi import themeapi
|
from httpapi import themeapi
|
||||||
from httpapi import fileoffsetreader
|
from httpapi import fileoffsetreader
|
||||||
from httpapi.sse.private import private_sse_blueprint
|
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
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
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(themeapi.theme_blueprint)
|
||||||
app.register_blueprint(private_sse_blueprint)
|
app.register_blueprint(private_sse_blueprint)
|
||||||
app.register_blueprint(fileoffsetreader.offset_reader_api)
|
app.register_blueprint(fileoffsetreader.offset_reader_api)
|
||||||
|
app.register_blueprint(serialized_api_bp)
|
||||||
|
|
||||||
def _add_events_bp():
|
def _add_events_bp():
|
||||||
while True:
|
while True:
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
view and interact with onionr sites
|
view and interact with onionr sites
|
||||||
"""
|
"""
|
||||||
from flask import Blueprint, Response, request, abort, g
|
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
|
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
|
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)
|
attr = getattr(initial, i)
|
||||||
|
|
||||||
if callable(attr):
|
if callable(attr):
|
||||||
data = json.loads(request.get_json(force=True))
|
try:
|
||||||
|
js = request.get_json(force=True)
|
||||||
|
print('json', js, type(js))
|
||||||
|
data = json.loads(js)
|
||||||
args = data['args']
|
args = data['args']
|
||||||
del data['args']
|
del data['args']
|
||||||
|
except (TypeError, ValueError) as e:
|
||||||
|
print(repr(e))
|
||||||
|
data = {}
|
||||||
|
args = []
|
||||||
|
print('data', data)
|
||||||
if data:
|
if data:
|
||||||
print(*args, **data)
|
print(*args, **data)
|
||||||
return Response(attr(*args, **data))
|
resp = attr(*args, **data)
|
||||||
|
if isinstance(resp, int):
|
||||||
|
resp = str(resp)
|
||||||
|
return Response(resp)
|
||||||
else:
|
else:
|
||||||
print(*args, **data)
|
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:
|
else:
|
||||||
if isinstance(attr, int):
|
if isinstance(attr, int):
|
||||||
attr = str(attr)
|
attr = str(attr)
|
||||||
|
Loading…
Reference in New Issue
Block a user