diff --git a/daemon.py b/daemon.py index 90d74b3a..105d9d24 100644 --- a/daemon.py +++ b/daemon.py @@ -8,6 +8,7 @@ __status__ = "Production" from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer #import socketserver +import commentjson import json import time from pprint import pprint @@ -198,6 +199,33 @@ class PubServer(BaseHTTPRequestHandler): if self._webfinger(): self.server.GETbusy=False return + # get an individual post + if '/statuses/' in self.path and '/users/' in self.path: + namedStatus=self.path.split('/users/')[1] + if '/' in namedStatus: + postSections=namedStatus.split('/') + if len(postSections)>=2: + nickname=postSections[0] + statusNumber=postSections[2] + if len(statusNumber)>10: + domainFull=self.server.domain + if self.server.port!=80 and self.server.port!=443: + domainFull=self.server.domain+':'+str(self.server.port) + postFilename= \ + self.server.baseDir+'/accounts/'+nickname+'@'+self.server.domain+'/outbox/'+ \ + self.server.httpPrefix+':##'+domainFull+'#users#'+nickname+'#statuses#'+statusNumber+'.json' + if os.path.isfile(postFilename): + postJson={} + with open(postFilename, 'r') as fp: + postJson=commentjson.load(fp) + self._set_headers('application/json') + self.wfile.write(json.dumps(postJson).encode('utf-8')) + self.server.GETbusy=False + return + else: + self._404() + self.server.GETbusy=False + return # get the inbox for a given person if self.path.endswith('/inbox'): if '/users/' in self.path: