mirror of https://gitlab.com/bashrc2/epicyon
Better handling of non-standard actor paths
parent
2ae4150ba1
commit
de99260805
23
follow.py
23
follow.py
|
@ -278,7 +278,12 @@ def getNoOfFollows(baseDir: str, nickname: str, domain: str,
|
||||||
'.' in line and \
|
'.' in line and \
|
||||||
not line.startswith('http'):
|
not line.startswith('http'):
|
||||||
ctr += 1
|
ctr += 1
|
||||||
elif line.startswith('http') and '/users/' in line:
|
elif ((line.startswith('http') or
|
||||||
|
line.startswith('dat')) and
|
||||||
|
('/users/' in line or
|
||||||
|
'/profile/' in line or
|
||||||
|
'/accounts/' in line or
|
||||||
|
'/channel/' in line)):
|
||||||
ctr += 1
|
ctr += 1
|
||||||
return ctr
|
return ctr
|
||||||
|
|
||||||
|
@ -487,7 +492,7 @@ def storeFollowRequest(baseDir: str,
|
||||||
nicknameToFollow: str, domainToFollow: str, port: int,
|
nicknameToFollow: str, domainToFollow: str, port: int,
|
||||||
nickname: str, domain: str, fromPort: int,
|
nickname: str, domain: str, fromPort: int,
|
||||||
followJson: {},
|
followJson: {},
|
||||||
debug: bool) -> bool:
|
debug: bool, personUrl: str) -> bool:
|
||||||
"""Stores the follow request for later use
|
"""Stores the follow request for later use
|
||||||
"""
|
"""
|
||||||
accountsDir = baseDir + '/accounts/' + \
|
accountsDir = baseDir + '/accounts/' + \
|
||||||
|
@ -539,17 +544,23 @@ def storeFollowRequest(baseDir: str,
|
||||||
|
|
||||||
# add to a file which contains a list of requests
|
# add to a file which contains a list of requests
|
||||||
approveFollowsFilename = accountsDir + '/followrequests.txt'
|
approveFollowsFilename = accountsDir + '/followrequests.txt'
|
||||||
|
|
||||||
|
# store either nick@domain or the full person/actor url
|
||||||
|
approveHandleStored = approveHandle
|
||||||
|
if '/users/' not in personUrl:
|
||||||
|
approveHandleStored = personUrl
|
||||||
|
|
||||||
if os.path.isfile(approveFollowsFilename):
|
if os.path.isfile(approveFollowsFilename):
|
||||||
if approveHandle not in open(approveFollowsFilename).read():
|
if approveHandle not in open(approveFollowsFilename).read():
|
||||||
with open(approveFollowsFilename, 'a+') as fp:
|
with open(approveFollowsFilename, 'a+') as fp:
|
||||||
fp.write(approveHandle + '\n')
|
fp.write(approveHandleStored + '\n')
|
||||||
else:
|
else:
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: ' + approveHandle +
|
print('DEBUG: ' + approveHandleStored +
|
||||||
' is already awaiting approval')
|
' is already awaiting approval')
|
||||||
else:
|
else:
|
||||||
with open(approveFollowsFilename, "w+") as fp:
|
with open(approveFollowsFilename, "w+") as fp:
|
||||||
fp.write(approveHandle + '\n')
|
fp.write(approveHandleStored + '\n')
|
||||||
|
|
||||||
# store the follow request in its own directory
|
# store the follow request in its own directory
|
||||||
# We don't rely upon the inbox because items in there could expire
|
# We don't rely upon the inbox because items in there could expire
|
||||||
|
@ -690,7 +701,7 @@ def receiveFollowRequest(session, baseDir: str, httpPrefix: str,
|
||||||
return storeFollowRequest(baseDir,
|
return storeFollowRequest(baseDir,
|
||||||
nicknameToFollow, domainToFollow, port,
|
nicknameToFollow, domainToFollow, port,
|
||||||
nickname, domain, fromPort,
|
nickname, domain, fromPort,
|
||||||
messageJson, debug)
|
messageJson, debug, messageJson['actor'])
|
||||||
else:
|
else:
|
||||||
print('Follow request does not require approval')
|
print('Follow request does not require approval')
|
||||||
# update the followers
|
# update the followers
|
||||||
|
|
|
@ -98,8 +98,29 @@ def manualApproveFollowRequest(session, baseDir: str,
|
||||||
print('Manual follow accept: follow requests file ' +
|
print('Manual follow accept: follow requests file ' +
|
||||||
approveFollowsFilename + ' not found')
|
approveFollowsFilename + ' not found')
|
||||||
return
|
return
|
||||||
|
|
||||||
# is the handle in the requests file?
|
# is the handle in the requests file?
|
||||||
if approveHandle not in open(approveFollowsFilename).read():
|
approveFollowsStr = ''
|
||||||
|
with open(approveFollowsFilename, 'r') as fpFollowers:
|
||||||
|
approveFollowsStr = fpFollowers.read()
|
||||||
|
exists = True
|
||||||
|
approveHandleFull = approveHandle
|
||||||
|
if approveHandle not in approveFollowsStr:
|
||||||
|
exists = False
|
||||||
|
elif '@' in approveHandle:
|
||||||
|
reqNick = approveHandle.split('@')[0]
|
||||||
|
reqDomain = approveHandle.split('@')[1].strip()
|
||||||
|
reqPrefix = httpPrefix + '://' + reqDomain
|
||||||
|
if reqPrefix + '/profile/' + reqNick not in approveFollowsStr:
|
||||||
|
exists = False
|
||||||
|
approveHandleFull = reqPrefix + '/profile/' + reqNick
|
||||||
|
elif reqPrefix + '/channel/' + reqNick not in approveFollowsStr:
|
||||||
|
exists = False
|
||||||
|
approveHandleFull = reqPrefix + '/channel/' + reqNick
|
||||||
|
elif reqPrefix + '/accounts/' + reqNick not in approveFollowsStr:
|
||||||
|
exists = False
|
||||||
|
approveHandleFull = reqPrefix + '/accounts/' + reqNick
|
||||||
|
if not exists:
|
||||||
print('Manual follow accept: ' + approveHandle +
|
print('Manual follow accept: ' + approveHandle +
|
||||||
' not in requests file ' + approveFollowsFilename)
|
' not in requests file ' + approveFollowsFilename)
|
||||||
return
|
return
|
||||||
|
@ -157,28 +178,28 @@ def manualApproveFollowRequest(session, baseDir: str,
|
||||||
# update the followers
|
# update the followers
|
||||||
print('Manual follow accept: updating ' + followersFilename)
|
print('Manual follow accept: updating ' + followersFilename)
|
||||||
if os.path.isfile(followersFilename):
|
if os.path.isfile(followersFilename):
|
||||||
if approveHandle not in open(followersFilename).read():
|
if approveHandleFull not in open(followersFilename).read():
|
||||||
try:
|
try:
|
||||||
with open(followersFilename, 'r+') as followersFile:
|
with open(followersFilename, 'r+') as followersFile:
|
||||||
content = followersFile.read()
|
content = followersFile.read()
|
||||||
followersFile.seek(0, 0)
|
followersFile.seek(0, 0)
|
||||||
followersFile.write(approveHandle + '\n' + content)
|
followersFile.write(approveHandleFull + '\n' + content)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print('WARN: Manual follow accept. ' +
|
print('WARN: Manual follow accept. ' +
|
||||||
'Failed to write entry to followers file ' + str(e))
|
'Failed to write entry to followers file ' + str(e))
|
||||||
else:
|
else:
|
||||||
print('WARN: Manual follow accept: ' + approveHandle +
|
print('WARN: Manual follow accept: ' + approveHandleFull +
|
||||||
' already exists in ' + followersFilename)
|
' already exists in ' + followersFilename)
|
||||||
else:
|
else:
|
||||||
print('Manual follow accept: first follower accepted for ' +
|
print('Manual follow accept: first follower accepted for ' +
|
||||||
handle + ' is ' + approveHandle)
|
handle + ' is ' + approveHandleFull)
|
||||||
followersFile = open(followersFilename, "w+")
|
followersFile = open(followersFilename, "w+")
|
||||||
followersFile.write(approveHandle + '\n')
|
followersFile.write(approveHandleFull + '\n')
|
||||||
followersFile.close()
|
followersFile.close()
|
||||||
|
|
||||||
# only update the follow requests file if the follow is confirmed to be
|
# only update the follow requests file if the follow is confirmed to be
|
||||||
# in followers.txt
|
# in followers.txt
|
||||||
if approveHandle in open(followersFilename).read():
|
if approveHandleFull in open(followersFilename).read():
|
||||||
# mark this handle as approved for following
|
# mark this handle as approved for following
|
||||||
approveFollowerHandle(accountDir, approveHandle)
|
approveFollowerHandle(accountDir, approveHandle)
|
||||||
# update the follow requests with the handles not yet approved
|
# update the follow requests with the handles not yet approved
|
||||||
|
|
Loading…
Reference in New Issue