forked from indymedia/epicyon
Return devices for a handle
parent
ea80dbb496
commit
b7be635aa3
75
daemon.py
75
daemon.py
|
@ -5781,6 +5781,49 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
postBytes, boundary)
|
postBytes, boundary)
|
||||||
return pageNumber
|
return pageNumber
|
||||||
|
|
||||||
|
def _cryptoAPIreadHandle(self):
|
||||||
|
"""Reads handle
|
||||||
|
"""
|
||||||
|
messageBytes = None
|
||||||
|
maxDeviceIdLength = 2048
|
||||||
|
length = int(self.headers['Content-length'])
|
||||||
|
if length >= maxDeviceIdLength:
|
||||||
|
print('WARN: handle post to crypto API is too long ' +
|
||||||
|
str(length) + ' bytes')
|
||||||
|
return {}
|
||||||
|
try:
|
||||||
|
messageBytes = self.rfile.read(length)
|
||||||
|
except SocketError as e:
|
||||||
|
if e.errno == errno.ECONNRESET:
|
||||||
|
print('WARN: handle POST messageBytes ' +
|
||||||
|
'connection reset by peer')
|
||||||
|
else:
|
||||||
|
print('WARN: handle POST messageBytes socket error')
|
||||||
|
return {}
|
||||||
|
except ValueError as e:
|
||||||
|
print('ERROR: handle POST messageBytes rfile.read failed')
|
||||||
|
print(e)
|
||||||
|
return {}
|
||||||
|
|
||||||
|
lenMessage = len(messageBytes)
|
||||||
|
if lenMessage > 2048:
|
||||||
|
print('WARN: handle post to crypto API is too long ' +
|
||||||
|
str(lenMessage) + ' bytes')
|
||||||
|
return {}
|
||||||
|
|
||||||
|
handle = messageBytes.decode("utf-8")
|
||||||
|
if not handle:
|
||||||
|
return None
|
||||||
|
if '@' not in handle:
|
||||||
|
return None
|
||||||
|
if '[' in handle:
|
||||||
|
return json.loads(messageBytes)
|
||||||
|
if handle.startswith('@'):
|
||||||
|
handle = handle[1:]
|
||||||
|
if '@' not in handle:
|
||||||
|
return None
|
||||||
|
return handle.strip()
|
||||||
|
|
||||||
def _cryptoAPIreadJson(self) -> {}:
|
def _cryptoAPIreadJson(self) -> {}:
|
||||||
"""Obtains json from POST to the crypto API
|
"""Obtains json from POST to the crypto API
|
||||||
"""
|
"""
|
||||||
|
@ -5813,6 +5856,34 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
|
|
||||||
return json.loads(messageBytes)
|
return json.loads(messageBytes)
|
||||||
|
|
||||||
|
def _cryptoAPIQuery(self, callingDomain: str) -> bool:
|
||||||
|
handle = self._cryptoAPIreadHandle()
|
||||||
|
if not handle:
|
||||||
|
return False
|
||||||
|
if isinstance(handle, str):
|
||||||
|
personDir = self.server.baseDir + '/accounts/' + handle
|
||||||
|
if not os.path.isdir(personDir + '/devices'):
|
||||||
|
return False
|
||||||
|
devicesList = []
|
||||||
|
for subdir, dirs, files in os.walk(personDir + '/devices'):
|
||||||
|
for f in files:
|
||||||
|
deviceFilename = os.path.join(personDir + '/devices', f)
|
||||||
|
if not os.path.isfile(deviceFilename):
|
||||||
|
continue
|
||||||
|
contentJson = loadJson(deviceFilename)
|
||||||
|
if contentJson:
|
||||||
|
devicesList.append(contentJson)
|
||||||
|
# return the list of devices for this handle
|
||||||
|
msg = \
|
||||||
|
json.dumps(devicesList,
|
||||||
|
ensure_ascii=False).encode('utf-8')
|
||||||
|
self._set_headers('application/json',
|
||||||
|
len(msg),
|
||||||
|
None, callingDomain)
|
||||||
|
self._write(msg)
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
def _cryptoAPI(self, path: str, authorized: bool) -> None:
|
def _cryptoAPI(self, path: str, authorized: bool) -> None:
|
||||||
"""POST or GET with the crypto API
|
"""POST or GET with the crypto API
|
||||||
"""
|
"""
|
||||||
|
@ -5862,8 +5933,8 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
return
|
return
|
||||||
self._400()
|
self._400()
|
||||||
elif path.startswith('/api/v1/crypto/keys/query'):
|
elif path.startswith('/api/v1/crypto/keys/query'):
|
||||||
# TODO
|
if not self._cryptoAPIQuery():
|
||||||
self._200()
|
self._400()
|
||||||
elif path.startswith('/api/v1/crypto/keys/claim'):
|
elif path.startswith('/api/v1/crypto/keys/claim'):
|
||||||
# TODO
|
# TODO
|
||||||
self._200()
|
self._200()
|
||||||
|
|
2
tests.py
2
tests.py
|
@ -1685,7 +1685,7 @@ def testWebLinks():
|
||||||
'TemplateAttachmentRichPopout'
|
'TemplateAttachmentRichPopout'
|
||||||
|
|
||||||
exampleText = \
|
exampleText = \
|
||||||
'<p>Test1 test2 #YetAnotherExcessivelyLongwindedAndBoringHashtag<\p>'
|
'<p>Test1 test2 #YetAnotherExcessivelyLongwindedAndBoringHashtag</p>'
|
||||||
resultText = removeLongWords(addWebLinks(exampleText), 40, [])
|
resultText = removeLongWords(addWebLinks(exampleText), 40, [])
|
||||||
assert(resultText ==
|
assert(resultText ==
|
||||||
'<p>Test1 test2 '
|
'<p>Test1 test2 '
|
||||||
|
|
Loading…
Reference in New Issue