diff --git a/webinterface.py b/webinterface.py index c38dc20a..2be77922 100644 --- a/webinterface.py +++ b/webinterface.py @@ -2565,6 +2565,187 @@ def postIsMuted(baseDir: str,nickname: str,domain: str, \ return True return False +def getPostAttachmentsAsHtml(postJsonObject: {},boxName: str,translate: {}, \ + isMuted: bool, \ + replyStr: str,announceStr: str,likeStr: str, \ + bookmarkStr: str,deleteStr: str,muteStr: str) -> (str,str): + """Returns a string representing any attachments + """ + attachmentStr='' + galleryStr='' + if not postJsonObject['object'].get('attachment'): + return attachmentStr,galleryStr + + if not isinstance(postJsonObject['object']['attachment'], list): + return attachmentStr,galleryStr + + attachmentCtr=0 + attachmentStr+='
' + for attach in postJsonObject['object']['attachment']: + if not (attach.get('mediaType') and attach.get('url')): + continue + + mediaType=attach['mediaType'] + imageDescription='' + if attach.get('name'): + imageDescription=attach['name'].replace('"',"'") + if mediaType=='image/png' or \ + mediaType=='image/jpeg' or \ + mediaType=='image/webp' or \ + mediaType=='image/gif': + if attach['url'].endswith('.png') or \ + attach['url'].endswith('.jpg') or \ + attach['url'].endswith('.jpeg') or \ + attach['url'].endswith('.webp') or \ + attach['url'].endswith('.gif'): + if attachmentCtr>0: + attachmentStr+='
' + if boxName=='tlmedia': + galleryStr+='\n' + + attachmentStr+='' + attachmentStr+= \ + ''+imageDescription+'\n' + attachmentCtr+=1 + elif mediaType=='video/mp4' or \ + mediaType=='video/webm' or \ + mediaType=='video/ogv': + extension='.mp4' + if attach['url'].endswith('.webm'): + extension='.webm' + elif attach['url'].endswith('.ogv'): + extension='.ogv' + if attach['url'].endswith(extension): + if attachmentCtr>0: + attachmentStr+='
' + if boxName=='tlmedia': + galleryStr+='\n' + + attachmentStr+='
' + attachmentCtr+=1 + elif mediaType=='audio/mpeg' or \ + mediaType=='audio/ogg': + extension='.mp3' + if attach['url'].endswith('.ogg'): + extension='.ogg' + if attach['url'].endswith(extension): + if attachmentCtr>0: + attachmentStr+='
' + if boxName=='tlmedia': + galleryStr+='\n' + + attachmentStr+='
' + attachmentCtr+=1 + attachmentStr+='
' + return attachmentStr,galleryStr def individualPostAsHtml(recentPostsCache: {},maxRecentPosts: int, \ iconsDir: str,translate: {}, \ @@ -3032,172 +3213,12 @@ def individualPostAsHtml(recentPostsCache: {},maxRecentPosts: int, \ '" alt="'+translate['replying to']+'" src="/'+ \ iconsDir+'/reply.png" class="announceOrReply"/> '+postDomain+'' - attachmentStr='' - if postJsonObject['object'].get('attachment'): - if isinstance(postJsonObject['object']['attachment'], list): - attachmentCtr=0 - attachmentStr+='
' - for attach in postJsonObject['object']['attachment']: - if attach.get('mediaType') and attach.get('url'): - mediaType=attach['mediaType'] - imageDescription='' - if attach.get('name'): - imageDescription=attach['name'].replace('"',"'") - if mediaType=='image/png' or \ - mediaType=='image/jpeg' or \ - mediaType=='image/gif': - if attach['url'].endswith('.png') or \ - attach['url'].endswith('.jpg') or \ - attach['url'].endswith('.jpeg') or \ - attach['url'].endswith('.webp') or \ - attach['url'].endswith('.gif'): - if attachmentCtr>0: - attachmentStr+='
' - if boxName=='tlmedia': - galleryStr+='\n' - attachmentStr+='' - attachmentStr+= \ - ''+imageDescription+'\n' - attachmentCtr+=1 - elif mediaType=='video/mp4' or \ - mediaType=='video/webm' or \ - mediaType=='video/ogv': - extension='.mp4' - if attach['url'].endswith('.webm'): - extension='.webm' - elif attach['url'].endswith('.ogv'): - extension='.ogv' - if attach['url'].endswith(extension): - if attachmentCtr>0: - attachmentStr+='
' - if boxName=='tlmedia': - galleryStr+='\n' - - attachmentStr+='
' - attachmentCtr+=1 - elif mediaType=='audio/mpeg' or \ - mediaType=='audio/ogg': - extension='.mp3' - if attach['url'].endswith('.ogg'): - extension='.ogg' - if attach['url'].endswith(extension): - if attachmentCtr>0: - attachmentStr+='
' - if boxName=='tlmedia': - galleryStr+='\n' - - attachmentStr+='
' - attachmentCtr+=1 - attachmentStr+='
' + attachmentStr,galleryStr= \ + getPostAttachmentsAsHtml(postJsonObject,boxName,translate, \ + isMuted, \ + replyStr,announceStr,likeStr, \ + bookmarkStr,deleteStr,muteStr) publishedStr='' if postJsonObject['object'].get('published'):