From 80e4779d44c1707160af3b83c31b57e36fa19d2a Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Fri, 30 Aug 2019 15:37:24 +0100 Subject: [PATCH] More attachment types --- daemon.py | 28 ++++++++++++++-------------- webinterface.py | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/daemon.py b/daemon.py index 359fa407..1de6c9d4 100644 --- a/daemon.py +++ b/daemon.py @@ -1823,21 +1823,21 @@ class PubServer(BaseHTTPRequestHandler): else: # directly search the binary array for the beginning # of an image - searchStr=b'Content-Type: image/png' - imageLocation=postBytes.find(searchStr) - filenameBase=self.server.baseDir+'/accounts/'+nickname+'@'+self.server.domain+'/upload' - if imageLocation>-1: - filename=filenameBase+'.png' - else: - searchStr=b'Content-Type: image/jpeg' - imageLocation=postBytes.find(searchStr) - if imageLocation>-1: - filename=filenameBase+'.jpg' - else: - searchStr=b'Content-Type: image/gif' + mediaExtension={ + 'image': ['png','jpeg','gif'], + 'video': ['mp4','webm','ogv'], + 'audio': ['mp3','ogg'] + } + for mType,extensionList in mediaTypes.items(): + for extension in extensionList: + searchStr=b'Content-Type: '+mType+'/'+extension imageLocation=postBytes.find(searchStr) - if imageLocation>-1: - filename=filenameBase+'.gif' + filenameBase=self.server.baseDir+'/accounts/'+nickname+'@'+self.server.domain+'/upload' + if imageLocation>-1: + if extension=='jpeg': + extension='jpg' + filename=filenameBase+'.'+extension + break if filename and imageLocation>-1: # locate the beginning of the image, after any # carriage returns diff --git a/webinterface.py b/webinterface.py index 71ef73b2..d9285ade 100644 --- a/webinterface.py +++ b/webinterface.py @@ -807,7 +807,7 @@ def htmlNewPost(baseDir: str,path: str,inReplyTo: str,mentions: [],reportUrl: st '
' \ ' ' \ ' ' \ + ' accept=".png, .jpg, .jpeg, .gif, .mp4, .webm, .ogv, .mp3, .ogg">' \ '
' \ ' ' \ ''