work on sitesapi
parent
bc71e3f693
commit
9ccbcf6c1d
|
@ -29,6 +29,7 @@ import onionrexceptions
|
|||
from onionrutils import stringvalidators
|
||||
from utils import safezip
|
||||
from onionrutils import mnemonickeys
|
||||
from . import sitefiles
|
||||
|
||||
site_api = Blueprint('siteapi', __name__)
|
||||
|
||||
|
@ -44,9 +45,9 @@ def site(name: str)->Response:
|
|||
# Now make sure the key is regardless a valid base32 format ed25519 key (readding padding if necessary)
|
||||
if stringvalidators.validate_pub_key(name):
|
||||
name = unpaddedbase32.repad(name)
|
||||
resp = findsite.find_site(name)
|
||||
resp = sitefiles.get_file('index.html')
|
||||
|
||||
if stringvalidators.validate_hash(name):
|
||||
elif stringvalidators.validate_hash(name):
|
||||
try:
|
||||
resp = onionrblockapi.Block(name).bcontent
|
||||
except onionrexceptions.NoDataAvailable:
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
from typing import Union
|
||||
import tarfile
|
||||
import io
|
||||
|
||||
from coredb import blockmetadb
|
||||
from onionrblocks import onionrblockapi
|
||||
|
||||
def find_site_gzip(user_id: str)->str:
|
||||
sites = blockmetadb.get_blocks_by_type('osite')
|
||||
for site in sites:
|
||||
if onionrblockapi.Block(site).isSigner(user_id):
|
||||
return tarfile.open(fileobj=io.BytesIO(site.bcontent), mode='r')
|
||||
return None
|
||||
|
||||
def get_file(user_id, file)->Union[bytes, None]:
|
||||
ret_data = ""
|
||||
site = find_site_gzip(user_id)
|
||||
if site is None: return None
|
||||
for file in site.getmembers():
|
||||
if file.name == file:
|
||||
return site.extractfile(file)
|
||||
return None
|
Loading…
Reference in New Issue