Handle domain

master
Bob Mottram 2019-07-13 20:34:03 +01:00
parent d2fcb37dd9
commit 08a16714c0
1 changed files with 69 additions and 69 deletions

138
daemon.py
View File

@ -300,75 +300,75 @@ class PubServer(BaseHTTPRequestHandler):
domainFull=self.server.domain domainFull=self.server.domain
if self.server.port!=80 and self.server.port!=443: if self.server.port!=80 and self.server.port!=443:
domainFull=self.server.domain+':'+str(self.server.port) domainFull=self.server.domain+':'+str(self.server.port)
boxname='outbox' boxname='outbox'
postDir=self.server.baseDir+'/accounts/'+nickname+'@'+self.server.domain+'/'+boxname postDir=self.server.baseDir+'/accounts/'+nickname+'@'+self.server.domain+'/'+boxname
postRepliesFilename= \ postRepliesFilename= \
postDir+'/'+ \ postDir+'/'+ \
self.server.httpPrefix+':##'+domainFull+'#users#'+nickname+'#statuses#'+statusNumber+'.replies' self.server.httpPrefix+':##'+domainFull+'#users#'+nickname+'#statuses#'+statusNumber+'.replies'
if not os.path.isfile(postRepliesFilename): if not os.path.isfile(postRepliesFilename):
# There are no replies, so show empty collection # There are no replies, so show empty collection
repliesJson = { repliesJson = {
'@context': 'https://www.w3.org/ns/activitystreams', '@context': 'https://www.w3.org/ns/activitystreams',
'first': self.server.httpPrefix+'://'+self.server.domain+'/users/'+nickname+'/statuses/'+statusNumber+'?page=true', 'first': self.server.httpPrefix+'://'+domainFull+'/users/'+nickname+'/statuses/'+statusNumber+'?page=true',
'id': self.server.httpPrefix+'://'+self.server.domain+'/users/'+nickname+'/statuses/'+statusNumber, 'id': self.server.httpPrefix+'://'+domainFull+'/users/'+nickname+'/statuses/'+statusNumber,
'last': self.server.httpPrefix+'://'+self.server.domain+'/users/'+nickname+'/statuses/'+statusNumber+'?page=true', 'last': self.server.httpPrefix+'://'+domainFull+'/users/'+nickname+'/statuses/'+statusNumber+'?page=true',
'totalItems': 0, 'totalItems': 0,
'type': 'OrderedCollection'} 'type': 'OrderedCollection'}
self._set_headers('application/json') self._set_headers('application/json')
self.wfile.write(json.dumps(repliesJson).encode('utf-8')) self.wfile.write(json.dumps(repliesJson).encode('utf-8'))
self.server.GETbusy=False self.server.GETbusy=False
return return
else: else:
# replies exist. Itterate through the text file containing message ids # replies exist. Itterate through the text file containing message ids
repliesJson = { repliesJson = {
'@context': 'https://www.w3.org/ns/activitystreams', '@context': 'https://www.w3.org/ns/activitystreams',
'id': self.server.httpPrefix+'://'+self.server.domain+'/users/'+nickname+'/statuses/'+statusNumber+'?page=true', 'id': self.server.httpPrefix+'://'+domainFull+'/users/'+nickname+'/statuses/'+statusNumber+'?page=true',
'orderedItems': [ 'orderedItems': [
], ],
'partOf': self.server.httpPrefix+'://'+self.server.domain+'/users/'+nickname+'/statuses/'+statusNumber, 'partOf': self.server.httpPrefix+'://'+domainFull+'/users/'+nickname+'/statuses/'+statusNumber,
'type': 'OrderedCollectionPage'} 'type': 'OrderedCollectionPage'}
# some messages could be private, so check authorization state # some messages could be private, so check authorization state
authorized=self._isAuthorized() authorized=self._isAuthorized()
# populate the items list with replies # populate the items list with replies
repliesBoxes=['outbox','inbox'] repliesBoxes=['outbox','inbox']
with open(postRepliesFilename,'r') as repliesFile: with open(postRepliesFilename,'r') as repliesFile:
for messageId in repliesFile: for messageId in repliesFile:
replyFound=False replyFound=False
# examine inbox and outbox # examine inbox and outbox
for boxname in repliesBoxes: for boxname in repliesBoxes:
searchFilename= \ searchFilename= \
self.server.baseDir+ \ self.server.baseDir+ \
'/accounts/'+nickname+'@'+ \ '/accounts/'+nickname+'@'+ \
self.server.domain+'/'+ \ self.server.domain+'/'+ \
boxname+'/'+ \ boxname+'/'+ \
messageId.replace('\n','').replace('/','#')+'.json' messageId.replace('\n','').replace('/','#')+'.json'
if os.path.isfile(searchFilename): if os.path.isfile(searchFilename):
if authorized or \ if authorized or \
'https://www.w3.org/ns/activitystreams#Public' in open(searchFilename).read(): 'https://www.w3.org/ns/activitystreams#Public' in open(searchFilename).read():
with open(searchFilename, 'r') as fp: with open(searchFilename, 'r') as fp:
postJson=commentjson.load(fp) postJson=commentjson.load(fp)
repliesJson['orderedItems'].append(postJson) repliesJson['orderedItems'].append(postJson)
replyFound=True replyFound=True
break break
# if not in either inbox or outbox then examine the shared inbox # if not in either inbox or outbox then examine the shared inbox
if not replyFound: if not replyFound:
searchFilename= \ searchFilename= \
self.server.baseDir+ \ self.server.baseDir+ \
'/accounts/inbox@'+ \ '/accounts/inbox@'+ \
self.server.domain+'/inbox/'+ \ self.server.domain+'/inbox/'+ \
messageId.replace('\n','').replace('/','#')+'.json' messageId.replace('\n','').replace('/','#')+'.json'
if os.path.isfile(searchFilename): if os.path.isfile(searchFilename):
if authorized or \ if authorized or \
'https://www.w3.org/ns/activitystreams#Public' in open(searchFilename).read(): 'https://www.w3.org/ns/activitystreams#Public' in open(searchFilename).read():
# get the json of the reply and append it to the collection # get the json of the reply and append it to the collection
with open(searchFilename, 'r') as fp: with open(searchFilename, 'r') as fp:
postJson=commentjson.load(fp) postJson=commentjson.load(fp)
repliesJson['orderedItems'].append(postJson) repliesJson['orderedItems'].append(postJson)
# send the replies json # send the replies json
self._set_headers('application/json') self._set_headers('application/json')
self.wfile.write(json.dumps(repliesJson).encode('utf-8')) self.wfile.write(json.dumps(repliesJson).encode('utf-8'))
self.server.GETbusy=False self.server.GETbusy=False
return return
# get an individual post from the path /users/nickname/statuses/number # get an individual post from the path /users/nickname/statuses/number
if '/statuses/' in self.path and '/users/' in self.path: if '/statuses/' in self.path and '/users/' in self.path: