Merge branch 'main' of ssh://code.freedombone.net:2222/bashrc/epicyon

main
Bob Mottram 2021-07-04 21:06:28 +01:00
commit 11a1cd7de9
7 changed files with 46 additions and 44 deletions

View File

@ -27,6 +27,7 @@ from utils import saveJson
from utils import isSuspended from utils import isSuspended
from utils import containsInvalidChars from utils import containsInvalidChars
from utils import removeHtml from utils import removeHtml
from utils import isAccountDir
from blocking import isBlockedDomain from blocking import isBlockedDomain
from blocking import isBlockedHashtag from blocking import isBlockedHashtag
from filters import isFiltered from filters import isFiltered
@ -964,9 +965,7 @@ def _addBlogsToNewswire(baseDir: str, domain: str, newswire: {},
# go through each account # go through each account
for subdir, dirs, files in os.walk(baseDir + '/accounts'): for subdir, dirs, files in os.walk(baseDir + '/accounts'):
for handle in dirs: for handle in dirs:
if '@' not in handle: if not isAccountDir(handle):
continue
if 'inbox@' in handle or 'news@' in handle:
continue continue
nickname = handle.split('@')[0] nickname = handle.split('@')[0]

View File

@ -1220,6 +1220,7 @@ def getActorJson(hostDomain: str, handle: str, http: bool, gnunet: bool,
nickname = handle.split(userPath)[1] nickname = handle.split(userPath)[1]
nickname = nickname.replace('\n', '').replace('\r', '') nickname = nickname.replace('\n', '').replace('\r', '')
domain = handle.split(userPath)[0] domain = handle.split(userPath)[0]
userPathFound = True
break break
if not userPathFound and '://' in originalHandle: if not userPathFound and '://' in originalHandle:
domain = originalHandle.split('://')[1] domain = originalHandle.split('://')[1]
@ -1245,6 +1246,7 @@ def getActorJson(hostDomain: str, handle: str, http: bool, gnunet: bool,
nickname = handle.split('@')[0] nickname = handle.split('@')[0]
domain = handle.split('@')[1] domain = handle.split('@')[1]
domain = domain.replace('\n', '').replace('\r', '') domain = domain.replace('\n', '').replace('\r', '')
cachedWebfingers = {} cachedWebfingers = {}
proxyType = None proxyType = None
if http or domain.endswith('.onion'): if http or domain.endswith('.onion'):

View File

@ -91,7 +91,8 @@ def _addRole(baseDir: str, nickname: str, domain: str,
with open(roleFile, 'w+') as f: with open(roleFile, 'w+') as f:
for roleNickname in lines: for roleNickname in lines:
roleNickname = roleNickname.strip('\n').strip('\r') roleNickname = roleNickname.strip('\n').strip('\r')
if len(roleNickname) > 1: if len(roleNickname) < 2:
continue
if os.path.isdir(baseDir + '/accounts/' + if os.path.isdir(baseDir + '/accounts/' +
roleNickname + '@' + domain): roleNickname + '@' + domain):
f.write(roleNickname + '\n') f.write(roleNickname + '\n')
@ -126,6 +127,7 @@ def _setActorRole(actorJson: {}, roleName: str) -> bool:
if not isinstance(actorJson['hasOccupation'], list): if not isinstance(actorJson['hasOccupation'], list):
return False return False
# occupation category from www.onetonline.org
category = None category = None
if 'admin' in roleName: if 'admin' in roleName:
category = '15-1299.01' category = '15-1299.01'
@ -228,8 +230,7 @@ def setRole(baseDir: str, nickname: str, domain: str,
# avoid giant strings # avoid giant strings
if len(role) > 128: if len(role) > 128:
return False return False
actorFilename = baseDir + '/accounts/' + \ actorFilename = baseDir + '/accounts/' + nickname + '@' + domain + '.json'
nickname + '@' + domain + '.json'
if not os.path.isfile(actorFilename): if not os.path.isfile(actorFilename):
return False return False

View File

@ -13,6 +13,7 @@ import datetime
from utils import hasObjectDict from utils import hasObjectDict
from utils import getStatusNumber from utils import getStatusNumber
from utils import loadJson from utils import loadJson
from utils import isAccountDir
from outbox import postMessageToOutbox from outbox import postMessageToOutbox
@ -116,8 +117,8 @@ def _updatePostSchedule(baseDir: str, handle: str, httpd,
continue continue
# move to the outbox # move to the outbox
outboxPostFilename = \ outboxPostFilename = postFilename.replace('/scheduled/',
postFilename.replace('/scheduled/', '/outbox/') '/outbox/')
os.rename(postFilename, outboxPostFilename) os.rename(postFilename, outboxPostFilename)
print('Scheduled post sent ' + postId) print('Scheduled post sent ' + postId)
@ -144,9 +145,7 @@ def runPostSchedule(baseDir: str, httpd, maxScheduledPosts: int):
for account in dirs: for account in dirs:
if '@' not in account: if '@' not in account:
continue continue
if account.startswith('inbox@'): if not isAccountDir(account):
continue
if account.startswith('news@'):
continue continue
# scheduled posts index for this account # scheduled posts index for this account
scheduleIndexFilename = \ scheduleIndexFilename = \

View File

@ -10,6 +10,7 @@ __module_group__ = "Core"
import os import os
import requests import requests
from utils import urlPermitted from utils import urlPermitted
from utils import isImageFile
import json import json
from socket import error as SocketError from socket import error as SocketError
import errno import errno
@ -257,12 +258,8 @@ def postImage(session, attachImageFilename: str, federationList: [],
print('postJson: ' + inboxUrl + ' not permitted') print('postJson: ' + inboxUrl + ' not permitted')
return None return None
if not (attachImageFilename.endswith('.jpg') or if not isImageFile(attachImageFilename):
attachImageFilename.endswith('.jpeg') or print('Image must be png, jpg, webp, avif, gif or svg')
attachImageFilename.endswith('.png') or
attachImageFilename.endswith('.svg') or
attachImageFilename.endswith('.gif')):
print('Image must be png, jpg, gif or svg')
return None return None
if not os.path.isfile(attachImageFilename): if not os.path.isfile(attachImageFilename):
print('Image not found: ' + attachImageFilename) print('Image not found: ' + attachImageFilename)
@ -270,9 +267,13 @@ def postImage(session, attachImageFilename: str, federationList: [],
contentType = 'image/jpeg' contentType = 'image/jpeg'
if attachImageFilename.endswith('.png'): if attachImageFilename.endswith('.png'):
contentType = 'image/png' contentType = 'image/png'
if attachImageFilename.endswith('.gif'): elif attachImageFilename.endswith('.gif'):
contentType = 'image/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' contentType = 'image/svg+xml'
headers['Content-type'] = contentType headers['Content-type'] = contentType

View File

@ -21,6 +21,7 @@ from utils import saveJson
from utils import getImageExtensions from utils import getImageExtensions
from utils import hasObjectDict from utils import hasObjectDict
from utils import removeDomainPort from utils import removeDomainPort
from utils import isAccountDir
from media import processMetaData from media import processMetaData
@ -136,7 +137,8 @@ def addShare(baseDir: str,
itemIDfile = baseDir + '/sharefiles/' + nickname + '/' + itemID itemIDfile = baseDir + '/sharefiles/' + nickname + '/' + itemID
formats = getImageExtensions() formats = getImageExtensions()
for ext in formats: for ext in formats:
if imageFilename.endswith('.' + ext): if not imageFilename.endswith('.' + ext):
continue
processMetaData(baseDir, nickname, domain, processMetaData(baseDir, nickname, domain,
imageFilename, itemIDfile + '.' + ext, imageFilename, itemIDfile + '.' + ext,
city) city)
@ -162,7 +164,7 @@ def addShare(baseDir: str,
# indicate that a new share is available # indicate that a new share is available
for subdir, dirs, files in os.walk(baseDir + '/accounts'): for subdir, dirs, files in os.walk(baseDir + '/accounts'):
for handle in dirs: for handle in dirs:
if '@' not in handle: if not isAccountDir(handle):
continue continue
accountDir = baseDir + '/accounts/' + handle accountDir = baseDir + '/accounts/' + handle
newShareFile = accountDir + '/.newShare' newShareFile = accountDir + '/.newShare'
@ -182,7 +184,7 @@ def expireShares(baseDir: str) -> None:
""" """
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 '@' not in account: if not isAccountDir(account):
continue continue
nickname = account.split('@')[0] nickname = account.split('@')[0]
domain = account.split('@')[1] domain = account.split('@')[1]

View File

@ -83,8 +83,7 @@ def setActorSkillLevel(actorJson: {},
if not actorJson: if not actorJson:
return True return True
if not actorJson.get('hasOccupation'): if not actorJson.get('hasOccupation'):
actorJson['hasOccupation'] = [ actorJson['hasOccupation'] = [{
{
'@type': 'Occupation', '@type': 'Occupation',
'name': '', 'name': '',
"occupationLocation": { "occupationLocation": {
@ -92,8 +91,7 @@ def setActorSkillLevel(actorJson: {},
"name": "Fediverse" "name": "Fediverse"
}, },
'skills': [] 'skills': []
} }]
]
ocSkillsList = getOccupationSkills(actorJson) ocSkillsList = getOccupationSkills(actorJson)
skillsDict = getSkillsFromList(ocSkillsList) skillsDict = getSkillsFromList(ocSkillsList)
if not skillsDict.get(skill): if not skillsDict.get(skill):