Browse Source

Showing image attachments

Bob Mottram 4 months ago
parent
commit
8b3b71d942
3 changed files with 44 additions and 5 deletions
  1. 8 0
      epicyon.css
  2. 2 2
      epicyon.py
  3. 34 3
      webinterface.py

+ 8 - 0
epicyon.css

@@ -1,3 +1,5 @@
+@charset "UTF-8";
+
 body {
   margin: 0 auto;
   max-width: 800px;
@@ -31,6 +33,12 @@ body {
   border-radius: 50%;
 }
 
+.container img.attachment {
+  max-width: 100%;
+  margin-left: 25%;
+  width: 50%;
+  border-radius: 0%;
+}
 .container img.right {
   float: right;
   margin-left: 20px;

+ 2 - 2
epicyon.py

@@ -1056,8 +1056,8 @@ if args.testdata:
     createPublicPost(baseDir,nickname,domain,port,httpPrefix,"like, this is totally just a test, man",False,True,False,None,None,useBlurhash)
     createPublicPost(baseDir,nickname,domain,port,httpPrefix,"Zoiks!!!",False,True,False,None,None,useBlurhash)
     createPublicPost(baseDir,nickname,domain,port,httpPrefix,"Hey scoob we need like a hundred more milkshakes",False,True,False,None,None,useBlurhash)
-    createPublicPost(baseDir,nickname,domain,port,httpPrefix,"Getting kinda spooky around here",False,True,False,None,None,useBlurhash)
-    createPublicPost(baseDir,nickname,domain,port,httpPrefix,"And they would have gotten away with it too if it wasn't for those pesky hackers",False,True,False,None,None,useBlurhash)
+    createPublicPost(baseDir,nickname,domain,port,httpPrefix,"Getting kinda spooky around here",False,True,False,None,None,useBlurhash,'someone')
+    createPublicPost(baseDir,nickname,domain,port,httpPrefix,"And they would have gotten away with it too if it wasn't for those pesky hackers",False,True,False,'img/logo.png','Description of image',useBlurhash)
     createPublicPost(baseDir,nickname,domain,port,httpPrefix,"man, these centralized sites are, like, the worst!",False,True,False,None,None,useBlurhash)
     createPublicPost(baseDir,nickname,domain,port,httpPrefix,"another mystery solved hey",False,True,False,None,None,useBlurhash)
     createPublicPost(baseDir,nickname,domain,port,httpPrefix,"let's go bowling",False,True,False,None,None,useBlurhash)

+ 34 - 3
webinterface.py

@@ -41,11 +41,42 @@ def htmlFollowers(followersJson: {}) -> str:
     return htmlHeader()+"<h1>Followers collection</h1>"+htmlFooter()
 
 def individualPostAsHtml(postJsonObject: {}) -> str:
+    avatarPosition=''
+    containerClass='container'
+    timeClass='time-right'
+    if postJsonObject['object']['inReplyTo']:
+        containerClass='container darker'
+        avatarPosition=' class="right"'
+        timeClass='time-left'
+    attachmentStr=''
+    if postJsonObject['object']['attachment']:
+        if isinstance(postJsonObject['object']['attachment'], list):
+            attachmentCtr=0
+            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']
+                    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('.gif'):
+                            if attachmentCtr>0:
+                                attachmentStr+='<br>'
+                            attachmentStr+= \
+                                '<img src="'+attach['url']+'" alt="'+imageDescription+'" title="'+imageDescription+'" class="attachment">\n'
+                            attachmentCtr+=1
+
     return \
-        '<div class="container">\n' \
-        '<img src="'+postJsonObject['actor']+'/avatar.png" alt="Avatar">\n'+ \
+        '<div class="'+containerClass+'">\n' \
+        '<img src="'+postJsonObject['actor']+'/avatar.png" alt="Avatar"'+avatarPosition+'>\n'+ \
         postJsonObject['object']['content']+'\n'+ \
-        '<span class="time-right">'+postJsonObject['object']['published']+'</span>\n' \
+        attachmentStr+ \
+        '<span class="'+timeClass+'">'+postJsonObject['object']['published']+'</span>\n'+ \
         '</div>\n'    
 
 def htmlTimeline(timelineJson: {}) -> str: