forked from indymedia/epicyon
Only show a limited subset of follows/followers to unauthorized viewers
parent
cc119b1580
commit
cb58d62bcc
|
@ -584,9 +584,11 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
self.wfile.write(json.dumps(outboxFeed).encode('utf-8'))
|
self.wfile.write(json.dumps(outboxFeed).encode('utf-8'))
|
||||||
self.server.GETbusy=False
|
self.server.GETbusy=False
|
||||||
return
|
return
|
||||||
|
authorized=self._isAuthorized()
|
||||||
following=getFollowingFeed(self.server.baseDir,self.server.domain, \
|
following=getFollowingFeed(self.server.baseDir,self.server.domain, \
|
||||||
self.server.port,self.path, \
|
self.server.port,self.path, \
|
||||||
self.server.httpPrefix,followsPerPage)
|
self.server.httpPrefix,
|
||||||
|
authorized,followsPerPage)
|
||||||
if following:
|
if following:
|
||||||
self._set_headers('application/json')
|
self._set_headers('application/json')
|
||||||
self.wfile.write(json.dumps(following).encode('utf-8'))
|
self.wfile.write(json.dumps(following).encode('utf-8'))
|
||||||
|
@ -595,7 +597,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
followers=getFollowingFeed(self.server.baseDir,self.server.domain, \
|
followers=getFollowingFeed(self.server.baseDir,self.server.domain, \
|
||||||
self.server.port,self.path, \
|
self.server.port,self.path, \
|
||||||
self.server.httpPrefix, \
|
self.server.httpPrefix, \
|
||||||
followsPerPage,'followers')
|
authorized,followsPerPage,'followers')
|
||||||
if followers:
|
if followers:
|
||||||
self._set_headers('application/json')
|
self._set_headers('application/json')
|
||||||
self.wfile.write(json.dumps(followers).encode('utf-8'))
|
self.wfile.write(json.dumps(followers).encode('utf-8'))
|
||||||
|
|
20
follow.py
20
follow.py
|
@ -118,9 +118,14 @@ def clearFollowers(baseDir: str,nickname: str,domain: str) -> None:
|
||||||
clearFollows(baseDir,nickname, domain,'followers.txt')
|
clearFollows(baseDir,nickname, domain,'followers.txt')
|
||||||
|
|
||||||
def getNoOfFollows(baseDir: str,nickname: str,domain: str, \
|
def getNoOfFollows(baseDir: str,nickname: str,domain: str, \
|
||||||
|
authenticated: bool, \
|
||||||
followFile='following.txt') -> int:
|
followFile='following.txt') -> int:
|
||||||
"""Returns the number of follows or followers
|
"""Returns the number of follows or followers
|
||||||
"""
|
"""
|
||||||
|
# only show number of followers to authenticated
|
||||||
|
# account holders
|
||||||
|
if not authenticated:
|
||||||
|
return 9999
|
||||||
handle=nickname.lower()+'@'+domain.lower()
|
handle=nickname.lower()+'@'+domain.lower()
|
||||||
filename=baseDir+'/accounts/'+handle+'/'+followFile
|
filename=baseDir+'/accounts/'+handle+'/'+followFile
|
||||||
if not os.path.isfile(filename):
|
if not os.path.isfile(filename):
|
||||||
|
@ -136,16 +141,21 @@ def getNoOfFollows(baseDir: str,nickname: str,domain: str, \
|
||||||
ctr += 1
|
ctr += 1
|
||||||
return ctr
|
return ctr
|
||||||
|
|
||||||
def getNoOfFollowers(baseDir: str,nickname: str,domain: str) -> int:
|
def getNoOfFollowers(baseDir: str,nickname: str,domain: str,authenticated: bool) -> int:
|
||||||
"""Returns the number of followers of the given person
|
"""Returns the number of followers of the given person
|
||||||
"""
|
"""
|
||||||
return getNoOfFollows(baseDir,nickname,domain,'followers.txt')
|
return getNoOfFollows(baseDir,nickname,domain,authenticated,'followers.txt')
|
||||||
|
|
||||||
def getFollowingFeed(baseDir: str,domain: str,port: int,path: str, \
|
def getFollowingFeed(baseDir: str,domain: str,port: int,path: str, \
|
||||||
httpPrefix: str, followsPerPage=12, \
|
httpPrefix: str, authenticated: bool,
|
||||||
|
followsPerPage=12, \
|
||||||
followFile='following') -> {}:
|
followFile='following') -> {}:
|
||||||
"""Returns the following and followers feeds from GET requests
|
"""Returns the following and followers feeds from GET requests
|
||||||
"""
|
"""
|
||||||
|
# Show a small number of follows to non-authenticated viewers
|
||||||
|
if not authenticated:
|
||||||
|
followsPerPage=6
|
||||||
|
|
||||||
if '/'+followFile not in path:
|
if '/'+followFile not in path:
|
||||||
return None
|
return None
|
||||||
# handle page numbers
|
# handle page numbers
|
||||||
|
@ -153,7 +163,7 @@ def getFollowingFeed(baseDir: str,domain: str,port: int,path: str, \
|
||||||
pageNumber=None
|
pageNumber=None
|
||||||
if '?page=' in path:
|
if '?page=' in path:
|
||||||
pageNumber=path.split('?page=')[1]
|
pageNumber=path.split('?page=')[1]
|
||||||
if pageNumber=='true':
|
if pageNumber=='true' or not authenticated:
|
||||||
pageNumber=1
|
pageNumber=1
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
|
@ -183,7 +193,7 @@ def getFollowingFeed(baseDir: str,domain: str,port: int,path: str, \
|
||||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||||
'first': httpPrefix+'://'+domain+'/users/'+nickname+'/'+followFile+'?page=1',
|
'first': httpPrefix+'://'+domain+'/users/'+nickname+'/'+followFile+'?page=1',
|
||||||
'id': httpPrefix+'://'+domain+'/users/'+nickname+'/'+followFile,
|
'id': httpPrefix+'://'+domain+'/users/'+nickname+'/'+followFile,
|
||||||
'totalItems': getNoOfFollows(baseDir,nickname,domain),
|
'totalItems': getNoOfFollows(baseDir,nickname,domain,authenticated),
|
||||||
'type': 'OrderedCollection'}
|
'type': 'OrderedCollection'}
|
||||||
return following
|
return following
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue