mirror of https://gitlab.com/bashrc2/epicyon
json endpoint for person options notes
parent
bd80115869
commit
905f5c0e29
|
@ -112,6 +112,7 @@ from utils import get_json_content_from_accept
|
|||
from utils import check_bad_path
|
||||
from utils import corp_servers
|
||||
from utils import decoded_host
|
||||
from person import get_person_notes_endpoint
|
||||
from person import get_account_pub_key
|
||||
from shares import actor_attached_shares
|
||||
from shares import get_share_category
|
||||
|
@ -657,6 +658,32 @@ def daemon_http_get(self) -> None:
|
|||
'_GET', 'isAuthorized',
|
||||
self.server.debug)
|
||||
|
||||
# json endpoint for person options notes
|
||||
if (authorized and
|
||||
('/private_account_notes/' in self.path or
|
||||
self.path.endswith('/private_account_notes'))):
|
||||
nickname = get_nickname_from_actor(self.path)
|
||||
handle = ''
|
||||
if '/private_account_notes/' in self.path:
|
||||
handle = self.path.split('/private_account_notes/', 1)[1]
|
||||
if nickname:
|
||||
notes_json = \
|
||||
get_person_notes_endpoint(self.server.base_dir,
|
||||
nickname,
|
||||
self.server.domain,
|
||||
handle,
|
||||
self.server.http_prefix,
|
||||
self.server.domain_full)
|
||||
msg_str = json.dumps(notes_json)
|
||||
msg = msg_str.encode('utf-8')
|
||||
msglen = len(msg)
|
||||
set_headers(self, 'application/json', msglen,
|
||||
None, calling_domain, True)
|
||||
write2(self, msg)
|
||||
return
|
||||
http_404(self, 212)
|
||||
return
|
||||
|
||||
if authorized and self.path.endswith('/bots.txt'):
|
||||
known_bots_str = ''
|
||||
for bot_name in self.server.known_bots:
|
||||
|
|
39
person.py
39
person.py
|
@ -1703,6 +1703,45 @@ def get_person_notes(base_dir: str, nickname: str, domain: str,
|
|||
return person_notes
|
||||
|
||||
|
||||
def get_person_notes_endpoint(base_dir: str, nickname: str, domain: str,
|
||||
handle: str,
|
||||
http_prefix: str, domain_full: str) -> {}:
|
||||
"""Returns a json endpoint for account notes, for use by c2s
|
||||
"""
|
||||
actor = local_actor_url(http_prefix, nickname, domain_full)
|
||||
notes_json = {
|
||||
"@context": "http://www.w3.org/ns/anno.jsonld",
|
||||
"id": actor + "/private_account_notes",
|
||||
"type": "AnnotationCollection",
|
||||
"items": []
|
||||
}
|
||||
dir_str = acct_dir(base_dir, nickname, domain) + '/notes'
|
||||
if not os.path.isdir(dir_str):
|
||||
return notes_json
|
||||
handle_txt = ''
|
||||
if handle:
|
||||
handle_txt = handle + '.txt'
|
||||
for _, _, files in os.walk(dir_str):
|
||||
for filename in files:
|
||||
if not filename.endswith('.txt'):
|
||||
continue
|
||||
if handle:
|
||||
if filename != handle_txt:
|
||||
continue
|
||||
handle2 = filename.replace('.txt', '')
|
||||
notes_text = get_person_notes(base_dir, nickname, domain, handle2)
|
||||
if not notes_text:
|
||||
continue
|
||||
notes_json['items'] += {
|
||||
"id": actor + "/private_account_notes/" + handle2,
|
||||
"type": "Annotation",
|
||||
"bodyValue": notes_text,
|
||||
"target": handle2
|
||||
}
|
||||
break
|
||||
return notes_json
|
||||
|
||||
|
||||
def _detect_users_path(url: str) -> str:
|
||||
"""Tries to detect the /users/ path
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue