mirror of https://gitlab.com/bashrc2/epicyon
Merge branch 'main' of ssh://code.freedombone.net:2222/bashrc/epicyon
commit
328984bb98
|
|
@ -995,11 +995,8 @@ def saveMediaInFormPOST(mediaBytes, debug: bool,
|
||||||
if os.path.isfile(possibleOtherFormat):
|
if os.path.isfile(possibleOtherFormat):
|
||||||
os.remove(possibleOtherFormat)
|
os.remove(possibleOtherFormat)
|
||||||
|
|
||||||
fd = open(filename, 'wb')
|
with open(filename, 'wb') as fp:
|
||||||
if not fd:
|
fp.write(mediaBytes[startPos:])
|
||||||
return None, None
|
|
||||||
fd.write(mediaBytes[startPos:])
|
|
||||||
fd.close()
|
|
||||||
|
|
||||||
if not os.path.isfile(filename):
|
if not os.path.isfile(filename):
|
||||||
print('WARN: Media file could not be written to file: ' + filename)
|
print('WARN: Media file could not be written to file: ' + filename)
|
||||||
|
|
|
||||||
4
posts.py
4
posts.py
|
|
@ -1348,11 +1348,9 @@ def getPinnedPostAsJson(baseDir: str, httpPrefix: str,
|
||||||
pinnedPostJson = {}
|
pinnedPostJson = {}
|
||||||
actor = httpPrefix + '://' + domainFull + '/users/' + nickname
|
actor = httpPrefix + '://' + domainFull + '/users/' + nickname
|
||||||
if os.path.isfile(pinnedFilename):
|
if os.path.isfile(pinnedFilename):
|
||||||
pinFile = open(pinnedFilename, "r")
|
|
||||||
pinnedContent = None
|
pinnedContent = None
|
||||||
if pinFile:
|
with open(pinnedFilename, "r") as pinFile:
|
||||||
pinnedContent = pinFile.read()
|
pinnedContent = pinFile.read()
|
||||||
pinFile.close()
|
|
||||||
if pinnedContent:
|
if pinnedContent:
|
||||||
pinnedPostJson = {
|
pinnedPostJson = {
|
||||||
'atomUri': actor + '/pinned',
|
'atomUri': actor + '/pinned',
|
||||||
|
|
|
||||||
191
utils.py
191
utils.py
|
|
@ -1517,11 +1517,7 @@ def noOfAccounts(baseDir: str) -> bool:
|
||||||
accountCtr = 0
|
accountCtr = 0
|
||||||
for subdir, dirs, files in os.walk(baseDir + '/accounts'):
|
for subdir, dirs, files in os.walk(baseDir + '/accounts'):
|
||||||
for account in dirs:
|
for account in dirs:
|
||||||
if '@' in account:
|
if isAccountDir(account):
|
||||||
if account.startswith('inbox@'):
|
|
||||||
continue
|
|
||||||
elif account.startswith('news@'):
|
|
||||||
continue
|
|
||||||
accountCtr += 1
|
accountCtr += 1
|
||||||
break
|
break
|
||||||
return accountCtr
|
return accountCtr
|
||||||
|
|
@ -1804,6 +1800,7 @@ def searchBoxPosts(baseDir: str, nickname: str, domain: str,
|
||||||
containing matching strings
|
containing matching strings
|
||||||
"""
|
"""
|
||||||
path = baseDir + '/accounts/' + nickname + '@' + domain + '/' + boxName
|
path = baseDir + '/accounts/' + nickname + '@' + domain + '/' + boxName
|
||||||
|
# is this a virtual box, such as direct messages?
|
||||||
if not os.path.isdir(path):
|
if not os.path.isdir(path):
|
||||||
if os.path.isfile(path + '.index'):
|
if os.path.isfile(path + '.index'):
|
||||||
return _searchVirtualBoxPosts(baseDir, nickname, domain,
|
return _searchVirtualBoxPosts(baseDir, nickname, domain,
|
||||||
|
|
@ -1858,54 +1855,56 @@ def undoLikesCollectionEntry(recentPostsCache: {},
|
||||||
"""Undoes a like for a particular actor
|
"""Undoes a like for a particular actor
|
||||||
"""
|
"""
|
||||||
postJsonObject = loadJson(postFilename)
|
postJsonObject = loadJson(postFilename)
|
||||||
if postJsonObject:
|
if not postJsonObject:
|
||||||
# remove any cached version of this post so that the
|
return
|
||||||
# like icon is changed
|
# remove any cached version of this post so that the
|
||||||
nickname = getNicknameFromActor(actor)
|
# like icon is changed
|
||||||
cachedPostFilename = getCachedPostFilename(baseDir, nickname,
|
nickname = getNicknameFromActor(actor)
|
||||||
domain, postJsonObject)
|
cachedPostFilename = getCachedPostFilename(baseDir, nickname,
|
||||||
if cachedPostFilename:
|
domain, postJsonObject)
|
||||||
if os.path.isfile(cachedPostFilename):
|
if cachedPostFilename:
|
||||||
os.remove(cachedPostFilename)
|
if os.path.isfile(cachedPostFilename):
|
||||||
removePostFromCache(postJsonObject, recentPostsCache)
|
os.remove(cachedPostFilename)
|
||||||
|
removePostFromCache(postJsonObject, recentPostsCache)
|
||||||
|
|
||||||
if not postJsonObject.get('type'):
|
if not postJsonObject.get('type'):
|
||||||
return
|
return
|
||||||
if postJsonObject['type'] != 'Create':
|
if postJsonObject['type'] != 'Create':
|
||||||
return
|
return
|
||||||
if not hasObjectDict(postJsonObject):
|
if not hasObjectDict(postJsonObject):
|
||||||
if debug:
|
if debug:
|
||||||
pprint(postJsonObject)
|
pprint(postJsonObject)
|
||||||
print('DEBUG: post ' + objectUrl + ' has no object')
|
print('DEBUG: post ' + objectUrl + ' has no object')
|
||||||
return
|
return
|
||||||
if not postJsonObject['object'].get('likes'):
|
if not postJsonObject['object'].get('likes'):
|
||||||
return
|
return
|
||||||
if not isinstance(postJsonObject['object']['likes'], dict):
|
if not isinstance(postJsonObject['object']['likes'], dict):
|
||||||
return
|
return
|
||||||
if not postJsonObject['object']['likes'].get('items'):
|
if not postJsonObject['object']['likes'].get('items'):
|
||||||
return
|
return
|
||||||
totalItems = 0
|
totalItems = 0
|
||||||
if postJsonObject['object']['likes'].get('totalItems'):
|
if postJsonObject['object']['likes'].get('totalItems'):
|
||||||
totalItems = postJsonObject['object']['likes']['totalItems']
|
totalItems = postJsonObject['object']['likes']['totalItems']
|
||||||
itemFound = False
|
itemFound = False
|
||||||
for likeItem in postJsonObject['object']['likes']['items']:
|
for likeItem in postJsonObject['object']['likes']['items']:
|
||||||
if likeItem.get('actor'):
|
if likeItem.get('actor'):
|
||||||
if likeItem['actor'] == actor:
|
if likeItem['actor'] == actor:
|
||||||
if debug:
|
|
||||||
print('DEBUG: like was removed for ' + actor)
|
|
||||||
postJsonObject['object']['likes']['items'].remove(likeItem)
|
|
||||||
itemFound = True
|
|
||||||
break
|
|
||||||
if itemFound:
|
|
||||||
if totalItems == 1:
|
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: likes was removed from post')
|
print('DEBUG: like was removed for ' + actor)
|
||||||
del postJsonObject['object']['likes']
|
postJsonObject['object']['likes']['items'].remove(likeItem)
|
||||||
else:
|
itemFound = True
|
||||||
itlen = len(postJsonObject['object']['likes']['items'])
|
break
|
||||||
postJsonObject['object']['likes']['totalItems'] = itlen
|
if not itemFound:
|
||||||
|
return
|
||||||
|
if totalItems == 1:
|
||||||
|
if debug:
|
||||||
|
print('DEBUG: likes was removed from post')
|
||||||
|
del postJsonObject['object']['likes']
|
||||||
|
else:
|
||||||
|
itlen = len(postJsonObject['object']['likes']['items'])
|
||||||
|
postJsonObject['object']['likes']['totalItems'] = itlen
|
||||||
|
|
||||||
saveJson(postJsonObject, postFilename)
|
saveJson(postJsonObject, postFilename)
|
||||||
|
|
||||||
|
|
||||||
def updateLikesCollection(recentPostsCache: {},
|
def updateLikesCollection(recentPostsCache: {},
|
||||||
|
|
@ -1978,54 +1977,56 @@ def undoAnnounceCollectionEntry(recentPostsCache: {},
|
||||||
shares of posts, not shares of physical objects.
|
shares of posts, not shares of physical objects.
|
||||||
"""
|
"""
|
||||||
postJsonObject = loadJson(postFilename)
|
postJsonObject = loadJson(postFilename)
|
||||||
if postJsonObject:
|
if not postJsonObject:
|
||||||
# remove any cached version of this announce so that the announce
|
return
|
||||||
# icon is changed
|
# remove any cached version of this announce so that the announce
|
||||||
nickname = getNicknameFromActor(actor)
|
# icon is changed
|
||||||
cachedPostFilename = getCachedPostFilename(baseDir, nickname, domain,
|
nickname = getNicknameFromActor(actor)
|
||||||
postJsonObject)
|
cachedPostFilename = getCachedPostFilename(baseDir, nickname, domain,
|
||||||
if cachedPostFilename:
|
postJsonObject)
|
||||||
if os.path.isfile(cachedPostFilename):
|
if cachedPostFilename:
|
||||||
os.remove(cachedPostFilename)
|
if os.path.isfile(cachedPostFilename):
|
||||||
removePostFromCache(postJsonObject, recentPostsCache)
|
os.remove(cachedPostFilename)
|
||||||
|
removePostFromCache(postJsonObject, recentPostsCache)
|
||||||
|
|
||||||
if not postJsonObject.get('type'):
|
if not postJsonObject.get('type'):
|
||||||
return
|
return
|
||||||
if postJsonObject['type'] != 'Create':
|
if postJsonObject['type'] != 'Create':
|
||||||
return
|
return
|
||||||
if not hasObjectDict(postJsonObject):
|
if not hasObjectDict(postJsonObject):
|
||||||
if debug:
|
if debug:
|
||||||
pprint(postJsonObject)
|
pprint(postJsonObject)
|
||||||
print('DEBUG: post has no object')
|
print('DEBUG: post has no object')
|
||||||
return
|
return
|
||||||
if not postJsonObject['object'].get('shares'):
|
if not postJsonObject['object'].get('shares'):
|
||||||
return
|
return
|
||||||
if not postJsonObject['object']['shares'].get('items'):
|
if not postJsonObject['object']['shares'].get('items'):
|
||||||
return
|
return
|
||||||
totalItems = 0
|
totalItems = 0
|
||||||
if postJsonObject['object']['shares'].get('totalItems'):
|
if postJsonObject['object']['shares'].get('totalItems'):
|
||||||
totalItems = postJsonObject['object']['shares']['totalItems']
|
totalItems = postJsonObject['object']['shares']['totalItems']
|
||||||
itemFound = False
|
itemFound = False
|
||||||
for announceItem in postJsonObject['object']['shares']['items']:
|
for announceItem in postJsonObject['object']['shares']['items']:
|
||||||
if announceItem.get('actor'):
|
if announceItem.get('actor'):
|
||||||
if announceItem['actor'] == actor:
|
if announceItem['actor'] == actor:
|
||||||
if debug:
|
|
||||||
print('DEBUG: Announce was removed for ' + actor)
|
|
||||||
anIt = announceItem
|
|
||||||
postJsonObject['object']['shares']['items'].remove(anIt)
|
|
||||||
itemFound = True
|
|
||||||
break
|
|
||||||
if itemFound:
|
|
||||||
if totalItems == 1:
|
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: shares (announcements) ' +
|
print('DEBUG: Announce was removed for ' + actor)
|
||||||
'was removed from post')
|
anIt = announceItem
|
||||||
del postJsonObject['object']['shares']
|
postJsonObject['object']['shares']['items'].remove(anIt)
|
||||||
else:
|
itemFound = True
|
||||||
itlen = len(postJsonObject['object']['shares']['items'])
|
break
|
||||||
postJsonObject['object']['shares']['totalItems'] = itlen
|
if not itemFound:
|
||||||
|
return
|
||||||
|
if totalItems == 1:
|
||||||
|
if debug:
|
||||||
|
print('DEBUG: shares (announcements) ' +
|
||||||
|
'was removed from post')
|
||||||
|
del postJsonObject['object']['shares']
|
||||||
|
else:
|
||||||
|
itlen = len(postJsonObject['object']['shares']['items'])
|
||||||
|
postJsonObject['object']['shares']['totalItems'] = itlen
|
||||||
|
|
||||||
saveJson(postJsonObject, postFilename)
|
saveJson(postJsonObject, postFilename)
|
||||||
|
|
||||||
|
|
||||||
def updateAnnounceCollection(recentPostsCache: {},
|
def updateAnnounceCollection(recentPostsCache: {},
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue