small bug fixes, added more cors headers for pub api browser requests

This commit is contained in:
Kevin Froman 2020-10-06 02:53:56 +00:00
parent 45940b2dba
commit 10ba2be93f
5 changed files with 15 additions and 7 deletions

View File

@ -8,7 +8,9 @@ class GetBlockData:
return
def get_block_data(self, bHash, decrypt=False, raw=False, headerOnly=False):
if not stringvalidators.validate_hash(bHash): raise onionrexceptions.InvalidHexHash("block hash not valid hash format")
if not stringvalidators.validate_hash(bHash):
raise onionrexceptions.InvalidHexHash(
"block hash not valid hash format")
bl = onionrblockapi.Block(bHash)
if decrypt:
bl.decrypt()

View File

@ -54,7 +54,7 @@ def get_block_data(public_API, b_hash):
if not config.get('general.hide_created_blocks', True) \
or b_hash not in public_API.hideBlocks:
if b_hash in public_API._too_many.get(BlockList).get():
block = apiutils.GetBlockData().get_block_b_hash(
block = apiutils.GetBlockData().get_block_data(
b_hash, raw=True, decrypt=False)
try:
# Encode in case data is binary
@ -62,11 +62,10 @@ def get_block_data(public_API, b_hash):
except AttributeError:
if len(block) == 0:
abort(404)
block = bytesconverter.str_to_bytes(block)
#block = bytesconverter.str_to_bytes(block)
resp = block
if len(resp) == 0:
abort(404)
resp = ""
# Has to be octet stream, otherwise binary data fails hash check
return Response(resp, mimetype='application/octet-stream')

View File

@ -64,11 +64,15 @@ class PublicAPISecurity:
# Network API version
resp.headers['X-API'] = public_api.API_VERSION
resp.headers['Access-Control-Allow-Origin'] = "*"
resp.headers['Access-Control-Allow-Headers'] = "*"
resp.headers['Access-Control-Allow-Methods'] = "POST, GET, OPTIONS"
# Delete some HTTP headers for Onionr user agents
NON_NETWORK_HEADERS = (
'Content-Security-Policy', 'X-Frame-Options',
'X-Content-Type-Options', 'Feature-Policy',
'Clear-Site-Data', 'Referrer-Policy')
'Clear-Site-Data', 'Referrer-Policy',
'Access-Control-Allow-Origin', 'Access-Control-Allow-Headers',
'Access-Control-Allow-Methods')
# For other nodes, we don't need to waste bits on the above headers
try:

View File

@ -11,6 +11,7 @@ import config
from filepaths import block_data_location
from etc.onionrvalues import BLOCK_EXPORT_FILE_EXT
from onionrblocks.blockimporter import import_block_from_data
import onionrexceptions
"""
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
@ -37,7 +38,10 @@ class _Importer(FileSystemEventHandler):
if not event.src_path.endswith(BLOCK_EXPORT_FILE_EXT):
return
with open(event.src_path, 'rb') as block_file:
import_block_from_data(block_file.read())
try:
import_block_from_data(block_file.read())
except onionrexceptions.DataExists:
return
if block_data_location in event.src_path:
try:
os.remove(event.src_path)

View File

@ -20,7 +20,6 @@ function sidebarAddPeerRegister(){
}})
.then((resp) => resp.text())
.then(function(data) {
alert(data)
if (data == "success"){
PNotify.success({
text: 'Peer added'