diff --git a/blog.py b/blog.py index 1b72ef2f..458076ce 100644 --- a/blog.py +++ b/blog.py @@ -690,87 +690,3 @@ def htmlEditBlog(mediaInstance: bool, translate: {}, editBlogForm += htmlFooter() return editBlogForm - - -def getBlogAddress(actorJson: {}) -> str: - """Returns blog address for the given actor - """ - if not actorJson.get('attachment'): - return '' - for propertyValue in actorJson['attachment']: - if not propertyValue.get('name'): - continue - if not propertyValue['name'].lower().startswith('Blog'): - continue - if not propertyValue.get('type'): - continue - if not propertyValue.get('value'): - continue - if propertyValue['type'] != 'PropertyValue': - continue - propertyValue['value'] = propertyValue['value'].strip() - if not (propertyValue['value'].startswith('https://') or - propertyValue['value'].startswith('http://') or - propertyValue['value'].startswith('dat://') or - propertyValue['value'].startswith('i2p://')): - continue - if '.' not in propertyValue['value']: - continue - if ' ' in propertyValue['value']: - continue - if ',' in propertyValue['value']: - continue - return propertyValue['value'] - return '' - - -def setBlogAddress(actorJson: {}, blogAddress: str) -> None: - """Sets an blog address for the given actor - """ - if not actorJson.get('attachment'): - actorJson['attachment'] = [] - - # remove any existing value - propertyFound = None - for propertyValue in actorJson['attachment']: - if not propertyValue.get('name'): - continue - if not propertyValue.get('type'): - continue - if not propertyValue['name'].lower().startswith('Blog'): - continue - propertyFound = propertyValue - break - if propertyFound: - actorJson['attachment'].remove(propertyFound) - - if not (blogAddress.startswith('https://') or - blogAddress.startswith('http://') or - blogAddress.startswith('dat://') or - blogAddress.startswith('i2p://')): - return - if '.' not in blogAddress: - return - if ' ' in blogAddress: - return - if ',' in blogAddress: - return - - for propertyValue in actorJson['attachment']: - if not propertyValue.get('name'): - continue - if not propertyValue.get('type'): - continue - if not propertyValue['name'].lower().startswith('blog'): - continue - if propertyValue['type'] != 'PropertyValue': - continue - propertyValue['value'] = blogAddress - return - - newBlogAddress = { - "name": "Blog", - "type": "PropertyValue", - "value": blogAddress - } - actorJson['attachment'].append(newBlogAddress) diff --git a/daemon.py b/daemon.py index cf559f25..8f6fb992 100644 --- a/daemon.py +++ b/daemon.py @@ -97,8 +97,8 @@ from blog import htmlBlogView from blog import htmlBlogPage from blog import htmlBlogPost from blog import htmlEditBlog -from blog import getBlogAddress -from blog import setBlogAddress +from webinterface import getBlogAddress +from webinterface import setBlogAddress from webinterface import htmlCalendarDeleteConfirm from webinterface import htmlDeletePost from webinterface import htmlAbout diff --git a/webinterface.py b/webinterface.py index ea0528ac..2251fd99 100644 --- a/webinterface.py +++ b/webinterface.py @@ -21,7 +21,6 @@ from pgp import getEmailAddress from pgp import getPGPpubKey from xmpp import getXmppAddress from ssb import getSSBAddress -from blog import getBlogAddress from tox import getToxAddress from matrix import getMatrixAddress from donate import getDonationUrl @@ -72,6 +71,90 @@ from happening import getTodaysEvents from git import isGitPatch +def getBlogAddress(actorJson: {}) -> str: + """Returns blog address for the given actor + """ + if not actorJson.get('attachment'): + return '' + for propertyValue in actorJson['attachment']: + if not propertyValue.get('name'): + continue + if not propertyValue['name'].lower().startswith('Blog'): + continue + if not propertyValue.get('type'): + continue + if not propertyValue.get('value'): + continue + if propertyValue['type'] != 'PropertyValue': + continue + propertyValue['value'] = propertyValue['value'].strip() + if not (propertyValue['value'].startswith('https://') or + propertyValue['value'].startswith('http://') or + propertyValue['value'].startswith('dat://') or + propertyValue['value'].startswith('i2p://')): + continue + if '.' not in propertyValue['value']: + continue + if ' ' in propertyValue['value']: + continue + if ',' in propertyValue['value']: + continue + return propertyValue['value'] + return '' + + +def setBlogAddress(actorJson: {}, blogAddress: str) -> None: + """Sets an blog address for the given actor + """ + if not actorJson.get('attachment'): + actorJson['attachment'] = [] + + # remove any existing value + propertyFound = None + for propertyValue in actorJson['attachment']: + if not propertyValue.get('name'): + continue + if not propertyValue.get('type'): + continue + if not propertyValue['name'].lower().startswith('Blog'): + continue + propertyFound = propertyValue + break + if propertyFound: + actorJson['attachment'].remove(propertyFound) + + if not (blogAddress.startswith('https://') or + blogAddress.startswith('http://') or + blogAddress.startswith('dat://') or + blogAddress.startswith('i2p://')): + return + if '.' not in blogAddress: + return + if ' ' in blogAddress: + return + if ',' in blogAddress: + return + + for propertyValue in actorJson['attachment']: + if not propertyValue.get('name'): + continue + if not propertyValue.get('type'): + continue + if not propertyValue['name'].lower().startswith('blog'): + continue + if propertyValue['type'] != 'PropertyValue': + continue + propertyValue['value'] = blogAddress + return + + newBlogAddress = { + "name": "Blog", + "type": "PropertyValue", + "value": blogAddress + } + actorJson['attachment'].append(newBlogAddress) + + def updateAvatarImageCache(session, baseDir: str, httpPrefix: str, actor: str, avatarUrl: str, personCache: {}, force=False) -> str: