From e30829416d284ab77a8ed70630113fe3785c7c28 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 4 Jul 2021 18:14:18 +0100 Subject: [PATCH 1/4] Comment --- roles.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/roles.py b/roles.py index 7fb00e38a..7a9a2a569 100644 --- a/roles.py +++ b/roles.py @@ -91,10 +91,11 @@ def _addRole(baseDir: str, nickname: str, domain: str, with open(roleFile, 'w+') as f: for roleNickname in lines: roleNickname = roleNickname.strip('\n').strip('\r') - if len(roleNickname) > 1: - if os.path.isdir(baseDir + '/accounts/' + - roleNickname + '@' + domain): - f.write(roleNickname + '\n') + if len(roleNickname) < 2: + continue + if os.path.isdir(baseDir + '/accounts/' + + roleNickname + '@' + domain): + f.write(roleNickname + '\n') else: with open(roleFile, "w+") as f: if os.path.isdir(baseDir + '/accounts/' + @@ -126,6 +127,7 @@ def _setActorRole(actorJson: {}, roleName: str) -> bool: if not isinstance(actorJson['hasOccupation'], list): return False + # occupation category from www.onetonline.org category = None if 'admin' in roleName: category = '15-1299.01' @@ -228,8 +230,7 @@ def setRole(baseDir: str, nickname: str, domain: str, # avoid giant strings if len(role) > 128: return False - actorFilename = baseDir + '/accounts/' + \ - nickname + '@' + domain + '.json' + actorFilename = baseDir + '/accounts/' + nickname + '@' + domain + '.json' if not os.path.isfile(actorFilename): return False From 83b1bfb29339327c3ee6d3143cc0c7260beb92e1 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 4 Jul 2021 18:55:29 +0100 Subject: [PATCH 2/4] Tidying --- newswire.py | 5 ++--- schedule.py | 9 ++++----- session.py | 15 ++++++++------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/newswire.py b/newswire.py index 544d17577..dca813fb2 100644 --- a/newswire.py +++ b/newswire.py @@ -27,6 +27,7 @@ from utils import saveJson from utils import isSuspended from utils import containsInvalidChars from utils import removeHtml +from utils import isAccountDir from blocking import isBlockedDomain from blocking import isBlockedHashtag from filters import isFiltered @@ -964,9 +965,7 @@ def _addBlogsToNewswire(baseDir: str, domain: str, newswire: {}, # go through each account for subdir, dirs, files in os.walk(baseDir + '/accounts'): for handle in dirs: - if '@' not in handle: - continue - if 'inbox@' in handle or 'news@' in handle: + if not isAccountDir(handle): continue nickname = handle.split('@')[0] diff --git a/schedule.py b/schedule.py index 4aaaa026d..3e3543384 100644 --- a/schedule.py +++ b/schedule.py @@ -13,6 +13,7 @@ import datetime from utils import hasObjectDict from utils import getStatusNumber from utils import loadJson +from utils import isAccountDir from outbox import postMessageToOutbox @@ -116,8 +117,8 @@ def _updatePostSchedule(baseDir: str, handle: str, httpd, continue # move to the outbox - outboxPostFilename = \ - postFilename.replace('/scheduled/', '/outbox/') + outboxPostFilename = postFilename.replace('/scheduled/', + '/outbox/') os.rename(postFilename, outboxPostFilename) print('Scheduled post sent ' + postId) @@ -144,9 +145,7 @@ def runPostSchedule(baseDir: str, httpd, maxScheduledPosts: int): for account in dirs: if '@' not in account: continue - if account.startswith('inbox@'): - continue - if account.startswith('news@'): + if not isAccountDir(account): continue # scheduled posts index for this account scheduleIndexFilename = \ diff --git a/session.py b/session.py index f6ccfbb3a..0790b898f 100644 --- a/session.py +++ b/session.py @@ -10,6 +10,7 @@ __module_group__ = "Core" import os import requests from utils import urlPermitted +from utils import isImageFile import json from socket import error as SocketError import errno @@ -257,11 +258,7 @@ def postImage(session, attachImageFilename: str, federationList: [], print('postJson: ' + inboxUrl + ' not permitted') return None - if not (attachImageFilename.endswith('.jpg') or - attachImageFilename.endswith('.jpeg') or - attachImageFilename.endswith('.png') or - attachImageFilename.endswith('.svg') or - attachImageFilename.endswith('.gif')): + if not isImageFile(attachImageFilename): print('Image must be png, jpg, gif or svg') return None if not os.path.isfile(attachImageFilename): @@ -270,9 +267,13 @@ def postImage(session, attachImageFilename: str, federationList: [], contentType = 'image/jpeg' if attachImageFilename.endswith('.png'): contentType = 'image/png' - if attachImageFilename.endswith('.gif'): + elif attachImageFilename.endswith('.gif'): contentType = 'image/gif' - if attachImageFilename.endswith('.svg'): + elif attachImageFilename.endswith('.webp'): + contentType = 'image/webp' + elif attachImageFilename.endswith('.avif'): + contentType = 'image/avif' + elif attachImageFilename.endswith('.svg'): contentType = 'image/svg+xml' headers['Content-type'] = contentType From 4697de88c0025bf4f853e9f7bb0c919d208c8333 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 4 Jul 2021 19:01:31 +0100 Subject: [PATCH 3/4] Detect account directories --- session.py | 2 +- shares.py | 24 +++++++++++++----------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/session.py b/session.py index 0790b898f..7e48cde5a 100644 --- a/session.py +++ b/session.py @@ -259,7 +259,7 @@ def postImage(session, attachImageFilename: str, federationList: [], return None if not isImageFile(attachImageFilename): - print('Image must be png, jpg, gif or svg') + print('Image must be png, jpg, webp, avif, gif or svg') return None if not os.path.isfile(attachImageFilename): print('Image not found: ' + attachImageFilename) diff --git a/shares.py b/shares.py index b9fac2e41..4407a3234 100644 --- a/shares.py +++ b/shares.py @@ -21,6 +21,7 @@ from utils import saveJson from utils import getImageExtensions from utils import hasObjectDict from utils import removeDomainPort +from utils import isAccountDir from media import processMetaData @@ -136,15 +137,16 @@ def addShare(baseDir: str, itemIDfile = baseDir + '/sharefiles/' + nickname + '/' + itemID formats = getImageExtensions() for ext in formats: - if imageFilename.endswith('.' + ext): - processMetaData(baseDir, nickname, domain, - imageFilename, itemIDfile + '.' + ext, - city) - if moveImage: - os.remove(imageFilename) - imageUrl = \ - httpPrefix + '://' + domainFull + \ - '/sharefiles/' + nickname + '/' + itemID + '.' + ext + if not imageFilename.endswith('.' + ext): + continue + processMetaData(baseDir, nickname, domain, + imageFilename, itemIDfile + '.' + ext, + city) + if moveImage: + os.remove(imageFilename) + imageUrl = \ + httpPrefix + '://' + domainFull + \ + '/sharefiles/' + nickname + '/' + itemID + '.' + ext sharesJson[itemID] = { "displayName": displayName, @@ -162,7 +164,7 @@ def addShare(baseDir: str, # indicate that a new share is available for subdir, dirs, files in os.walk(baseDir + '/accounts'): for handle in dirs: - if '@' not in handle: + if not isAccountDir(handle): continue accountDir = baseDir + '/accounts/' + handle newShareFile = accountDir + '/.newShare' @@ -182,7 +184,7 @@ def expireShares(baseDir: str) -> None: """ for subdir, dirs, files in os.walk(baseDir + '/accounts'): for account in dirs: - if '@' not in account: + if not isAccountDir(account): continue nickname = account.split('@')[0] domain = account.split('@')[1] From 907f3d836651058c87d1bb8a9943c5b8ce44113c Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 4 Jul 2021 20:59:08 +0100 Subject: [PATCH 4/4] Set flag if users path is found --- person.py | 2 ++ skills.py | 20 +++++++++----------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/person.py b/person.py index f0db12612..3e670e381 100644 --- a/person.py +++ b/person.py @@ -1220,6 +1220,7 @@ def getActorJson(hostDomain: str, handle: str, http: bool, gnunet: bool, nickname = handle.split(userPath)[1] nickname = nickname.replace('\n', '').replace('\r', '') domain = handle.split(userPath)[0] + userPathFound = True break if not userPathFound and '://' in originalHandle: domain = originalHandle.split('://')[1] @@ -1245,6 +1246,7 @@ def getActorJson(hostDomain: str, handle: str, http: bool, gnunet: bool, nickname = handle.split('@')[0] domain = handle.split('@')[1] domain = domain.replace('\n', '').replace('\r', '') + cachedWebfingers = {} proxyType = None if http or domain.endswith('.onion'): diff --git a/skills.py b/skills.py index 3d5d3f92b..db4a01a50 100644 --- a/skills.py +++ b/skills.py @@ -83,17 +83,15 @@ def setActorSkillLevel(actorJson: {}, if not actorJson: return True if not actorJson.get('hasOccupation'): - actorJson['hasOccupation'] = [ - { - '@type': 'Occupation', - 'name': '', - "occupationLocation": { - "@type": "City", - "name": "Fediverse" - }, - 'skills': [] - } - ] + actorJson['hasOccupation'] = [{ + '@type': 'Occupation', + 'name': '', + "occupationLocation": { + "@type": "City", + "name": "Fediverse" + }, + 'skills': [] + }] ocSkillsList = getOccupationSkills(actorJson) skillsDict = getSkillsFromList(ocSkillsList) if not skillsDict.get(skill):