diff --git a/content.py b/content.py index d44f4cce8..50198e337 100644 --- a/content.py +++ b/content.py @@ -440,11 +440,13 @@ def saveMediaInFormPOST(mediaBytes,debug: bool, \ 'png': 'image/png', 'jpeg': 'image/jpeg', 'gif': 'image/gif', + 'webp': 'image/webp', 'mp4': 'video/mp4', 'ogv': 'video/ogv', 'mp3': 'audio/mpeg', 'ogg': 'audio/ogg' } + detectedExtension=None for extension,contentType in extensionList.items(): searchStr=b'Content-Type: '+contentType.encode('utf8', 'ignore') mediaLocation=mediaBytes.find(searchStr) @@ -457,6 +459,7 @@ def saveMediaInFormPOST(mediaBytes,debug: bool, \ filename=filenameBase+'.'+extension attachmentMediaType= \ searchStr.decode().split('/')[0].replace('Content-Type: ','') + detectedExtension=extension break if not filename: @@ -471,6 +474,16 @@ def saveMediaInFormPOST(mediaBytes,debug: bool, \ startPos+=offset break + # remove any existing image files with a different format + extensionTypes=('png','jpg','jpeg','gif','webp') + if detectedExtension in extensionTypes: + for ex in extensionTypes: + if ex==detectedExtension: + continue + possibleOtherFormat=filename.replace('.'+detectedExtension,'.'+ex) + if os.path.isfile(possibleOtherFormat): + os.remove(possibleOtherFormat) + fd = open(filename, 'wb') fd.write(mediaBytes[startPos:]) fd.close() diff --git a/daemon.py b/daemon.py index cb20cd437..9c40b0ae3 100644 --- a/daemon.py +++ b/daemon.py @@ -999,9 +999,12 @@ class PubServer(BaseHTTPRequestHandler): return # image on login screen - if self.path=='/login.png': + if self.path=='/login.png' or \ + self.path=='/login.gif' or \ + self.path=='/login.jpeg' or \ + self.path=='/login.jpg': mediaFilename= \ - self.server.baseDir+'/accounts/login.png' + self.server.baseDir+'/accounts'+self.path if os.path.isfile(mediaFilename): tries=0 mediaBinary=None @@ -3222,6 +3225,7 @@ class PubServer(BaseHTTPRequestHandler): # extract each image type actorChanged=True profileMediaTypes=['avatar','image','banner','instanceLogo'] + profileMediaTypesUploaded={} for mType in profileMediaTypes: if self.server.debug: print('DEBUG: profile update extracting '+mType+' image from POST') @@ -3260,7 +3264,10 @@ class PubServer(BaseHTTPRequestHandler): removeMetaData(filename,postImageFilename) if os.path.isfile(postImageFilename): print('profile update POST '+mType+' image saved to '+postImageFilename) - actorChanged=True + if mType!='instanceLogo': + lastPartOfImageFilename=postImageFilename.split('/')[-1] + profileMediaTypesUploaded[mType]=lastPartOfImageFilename + actorChanged=True else: print('ERROR: profile update POST '+mType+' image could not be saved to '+postImageFilename) @@ -3276,7 +3283,21 @@ class PubServer(BaseHTTPRequestHandler): nickname+'@'+self.server.domain+'.json' if os.path.isfile(actorFilename): actorJson=loadJson(actorFilename) - if actorJson: + if actorJson: + + # update the avatar/image url file extension + for mType,lastPartOfImageFilename in profileMediaTypesUploaded.items(): + if mType=='avatar': + lastPartOfUrl=actorJson['icon']['url'].split('/')[-1] + actorJson['icon']['url']= \ + actorJson['icon']['url'].replace('/'+lastPartOfUrl, \ + '/'+lastPartOfImageFilename) + elif mType=='image': + lastPartOfUrl=actorJson['image']['url'].split('/')[-1] + actorJson['image']['url']= \ + actorJson['image']['url'].replace('/'+lastPartOfUrl, \ + '/'+lastPartOfImageFilename) + skillCtr=1 newSkills={} while skillCtr<10: diff --git a/webinterface.py b/webinterface.py index b78b710a1..5f677b101 100644 --- a/webinterface.py +++ b/webinterface.py @@ -505,6 +505,7 @@ def htmlSkillsSearch(translate: {},baseDir: str, \ def htmlEditProfile(translate: {},baseDir: str,path: str,domain: str,port: int) -> str: """Shows the edit profile screen """ + imageFormats='.png .jpg .jpeg .gif .webp' pathOriginal=path path=path.replace('/inbox','').replace('/outbox','').replace('/shares','') nickname=getNicknameFromActor(path) @@ -601,7 +602,7 @@ def htmlEditProfile(translate: {},baseDir: str,path: str,domain: str,port: int) instanceStr+=' ' instanceStr+=' '+translate['Instance Logo'] instanceStr+=' ' instanceStr+='' moderators='' @@ -633,13 +634,13 @@ def htmlEditProfile(translate: {},baseDir: str,path: str,domain: str,port: int) editProfileForm+=' '+translate['The files attached below should be no larger than 10MB in total uploaded at once.']+'
' editProfileForm+=' '+translate['Avatar image'] editProfileForm+=' ' editProfileForm+='
'+translate['Background image'] editProfileForm+=' ' editProfileForm+='
'+translate['Timeline banner image'] editProfileForm+=' ' editProfileForm+=' ' editProfileForm+='
' editProfileForm+=translate['Change Password']+'
' @@ -706,8 +707,26 @@ def htmlLogin(translate: {},baseDir: str,autocomplete=True) -> str: """ accounts=noOfAccounts(baseDir) - if not os.path.isfile(baseDir+'/accounts/login.png'): - copyfile(baseDir+'/img/login.png',baseDir+'/accounts/login.png') + loginImage='login.png' + loginImageFilename=None + if os.path.isfile(os.path.isfile(baseDir+'/accounts/'+loginImage)): + loginImageFilename=baseDir+'/accounts/'+loginImage + if os.path.isfile(os.path.isfile(baseDir+'/accounts/login.jpg')): + loginImage='login.jpg' + loginImageFilename=baseDir+'/accounts/'+loginImage + if os.path.isfile(os.path.isfile(baseDir+'/accounts/login.jpeg')): + loginImage='login.jpeg' + loginImageFilename=baseDir+'/accounts/'+loginImage + if os.path.isfile(os.path.isfile(baseDir+'/accounts/login.gif')): + loginImage='login.gif' + loginImageFilename=baseDir+'/accounts/'+loginImage + if os.path.isfile(os.path.isfile(baseDir+'/accounts/login.webp')): + loginImage='login.webp' + loginImageFilename=baseDir+'/accounts/'+loginImage + + if not loginImageFilename: + loginImageFilename=baseDir+'/accounts/'+loginImage + copyfile(baseDir+'/img/login.png',loginImageFilename) if os.path.isfile(baseDir+'/img/login-background.png'): if not os.path.isfile(baseDir+'/accounts/login-background.png'): copyfile(baseDir+'/img/login-background.png',baseDir+'/accounts/login-background.png') @@ -747,10 +766,11 @@ def htmlLogin(translate: {},baseDir: str,autocomplete=True) -> str: if not autocomplete: autocompleteStr='autocomplete="off" value=""' + loginForm=htmlHeader(cssFilename,loginCSS) loginForm+='
' loginForm+='
' - loginForm+=' login image' + loginForm+=' login image' loginForm+=loginText+TOSstr loginForm+='
' loginForm+=''