forked from indymedia/epicyon
Support different image formats
parent
9af5129fcb
commit
b94d1e3877
13
content.py
13
content.py
|
@ -440,11 +440,13 @@ def saveMediaInFormPOST(mediaBytes,debug: bool, \
|
||||||
'png': 'image/png',
|
'png': 'image/png',
|
||||||
'jpeg': 'image/jpeg',
|
'jpeg': 'image/jpeg',
|
||||||
'gif': 'image/gif',
|
'gif': 'image/gif',
|
||||||
|
'webp': 'image/webp',
|
||||||
'mp4': 'video/mp4',
|
'mp4': 'video/mp4',
|
||||||
'ogv': 'video/ogv',
|
'ogv': 'video/ogv',
|
||||||
'mp3': 'audio/mpeg',
|
'mp3': 'audio/mpeg',
|
||||||
'ogg': 'audio/ogg'
|
'ogg': 'audio/ogg'
|
||||||
}
|
}
|
||||||
|
detectedExtension=None
|
||||||
for extension,contentType in extensionList.items():
|
for extension,contentType in extensionList.items():
|
||||||
searchStr=b'Content-Type: '+contentType.encode('utf8', 'ignore')
|
searchStr=b'Content-Type: '+contentType.encode('utf8', 'ignore')
|
||||||
mediaLocation=mediaBytes.find(searchStr)
|
mediaLocation=mediaBytes.find(searchStr)
|
||||||
|
@ -457,6 +459,7 @@ def saveMediaInFormPOST(mediaBytes,debug: bool, \
|
||||||
filename=filenameBase+'.'+extension
|
filename=filenameBase+'.'+extension
|
||||||
attachmentMediaType= \
|
attachmentMediaType= \
|
||||||
searchStr.decode().split('/')[0].replace('Content-Type: ','')
|
searchStr.decode().split('/')[0].replace('Content-Type: ','')
|
||||||
|
detectedExtension=extension
|
||||||
break
|
break
|
||||||
|
|
||||||
if not filename:
|
if not filename:
|
||||||
|
@ -471,6 +474,16 @@ def saveMediaInFormPOST(mediaBytes,debug: bool, \
|
||||||
startPos+=offset
|
startPos+=offset
|
||||||
break
|
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 = open(filename, 'wb')
|
||||||
fd.write(mediaBytes[startPos:])
|
fd.write(mediaBytes[startPos:])
|
||||||
fd.close()
|
fd.close()
|
||||||
|
|
29
daemon.py
29
daemon.py
|
@ -999,9 +999,12 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
return
|
return
|
||||||
|
|
||||||
# image on login screen
|
# 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= \
|
mediaFilename= \
|
||||||
self.server.baseDir+'/accounts/login.png'
|
self.server.baseDir+'/accounts'+self.path
|
||||||
if os.path.isfile(mediaFilename):
|
if os.path.isfile(mediaFilename):
|
||||||
tries=0
|
tries=0
|
||||||
mediaBinary=None
|
mediaBinary=None
|
||||||
|
@ -3222,6 +3225,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
# extract each image type
|
# extract each image type
|
||||||
actorChanged=True
|
actorChanged=True
|
||||||
profileMediaTypes=['avatar','image','banner','instanceLogo']
|
profileMediaTypes=['avatar','image','banner','instanceLogo']
|
||||||
|
profileMediaTypesUploaded={}
|
||||||
for mType in profileMediaTypes:
|
for mType in profileMediaTypes:
|
||||||
if self.server.debug:
|
if self.server.debug:
|
||||||
print('DEBUG: profile update extracting '+mType+' image from POST')
|
print('DEBUG: profile update extracting '+mType+' image from POST')
|
||||||
|
@ -3260,7 +3264,10 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
removeMetaData(filename,postImageFilename)
|
removeMetaData(filename,postImageFilename)
|
||||||
if os.path.isfile(postImageFilename):
|
if os.path.isfile(postImageFilename):
|
||||||
print('profile update POST '+mType+' image saved to '+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:
|
else:
|
||||||
print('ERROR: profile update POST '+mType+' image could not be saved to '+postImageFilename)
|
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'
|
nickname+'@'+self.server.domain+'.json'
|
||||||
if os.path.isfile(actorFilename):
|
if os.path.isfile(actorFilename):
|
||||||
actorJson=loadJson(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
|
skillCtr=1
|
||||||
newSkills={}
|
newSkills={}
|
||||||
while skillCtr<10:
|
while skillCtr<10:
|
||||||
|
|
|
@ -505,6 +505,7 @@ def htmlSkillsSearch(translate: {},baseDir: str, \
|
||||||
def htmlEditProfile(translate: {},baseDir: str,path: str,domain: str,port: int) -> str:
|
def htmlEditProfile(translate: {},baseDir: str,path: str,domain: str,port: int) -> str:
|
||||||
"""Shows the edit profile screen
|
"""Shows the edit profile screen
|
||||||
"""
|
"""
|
||||||
|
imageFormats='.png .jpg .jpeg .gif .webp'
|
||||||
pathOriginal=path
|
pathOriginal=path
|
||||||
path=path.replace('/inbox','').replace('/outbox','').replace('/shares','')
|
path=path.replace('/inbox','').replace('/outbox','').replace('/shares','')
|
||||||
nickname=getNicknameFromActor(path)
|
nickname=getNicknameFromActor(path)
|
||||||
|
@ -601,7 +602,7 @@ def htmlEditProfile(translate: {},baseDir: str,path: str,domain: str,port: int)
|
||||||
instanceStr+=' <textarea id="message" name="instanceDescription" style="height:200px">'+instanceDescription+'</textarea>'
|
instanceStr+=' <textarea id="message" name="instanceDescription" style="height:200px">'+instanceDescription+'</textarea>'
|
||||||
instanceStr+=' '+translate['Instance Logo']
|
instanceStr+=' '+translate['Instance Logo']
|
||||||
instanceStr+=' <input type="file" id="instanceLogo" name="instanceLogo"'
|
instanceStr+=' <input type="file" id="instanceLogo" name="instanceLogo"'
|
||||||
instanceStr+=' accept=".png">'
|
instanceStr+=' accept="'+imageFormats+'">'
|
||||||
instanceStr+='</div>'
|
instanceStr+='</div>'
|
||||||
|
|
||||||
moderators=''
|
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.']+'<br>'
|
editProfileForm+=' '+translate['The files attached below should be no larger than 10MB in total uploaded at once.']+'<br>'
|
||||||
editProfileForm+=' '+translate['Avatar image']
|
editProfileForm+=' '+translate['Avatar image']
|
||||||
editProfileForm+=' <input type="file" id="avatar" name="avatar"'
|
editProfileForm+=' <input type="file" id="avatar" name="avatar"'
|
||||||
editProfileForm+=' accept=".png">'
|
editProfileForm+=' accept="'+imageFormats+'">'
|
||||||
editProfileForm+=' <br>'+translate['Background image']
|
editProfileForm+=' <br>'+translate['Background image']
|
||||||
editProfileForm+=' <input type="file" id="image" name="image"'
|
editProfileForm+=' <input type="file" id="image" name="image"'
|
||||||
editProfileForm+=' accept=".png">'
|
editProfileForm+=' accept="'+imageFormats+'">'
|
||||||
editProfileForm+=' <br>'+translate['Timeline banner image']
|
editProfileForm+=' <br>'+translate['Timeline banner image']
|
||||||
editProfileForm+=' <input type="file" id="banner" name="banner"'
|
editProfileForm+=' <input type="file" id="banner" name="banner"'
|
||||||
editProfileForm+=' accept=".png">'
|
editProfileForm+=' accept="'+imageFormats+'">'
|
||||||
editProfileForm+=' </div>'
|
editProfileForm+=' </div>'
|
||||||
editProfileForm+=' <div class="container">'
|
editProfileForm+=' <div class="container">'
|
||||||
editProfileForm+=translate['Change Password']+'<br>'
|
editProfileForm+=translate['Change Password']+'<br>'
|
||||||
|
@ -706,8 +707,26 @@ def htmlLogin(translate: {},baseDir: str,autocomplete=True) -> str:
|
||||||
"""
|
"""
|
||||||
accounts=noOfAccounts(baseDir)
|
accounts=noOfAccounts(baseDir)
|
||||||
|
|
||||||
if not os.path.isfile(baseDir+'/accounts/login.png'):
|
loginImage='login.png'
|
||||||
copyfile(baseDir+'/img/login.png',baseDir+'/accounts/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 os.path.isfile(baseDir+'/img/login-background.png'):
|
||||||
if not os.path.isfile(baseDir+'/accounts/login-background.png'):
|
if not os.path.isfile(baseDir+'/accounts/login-background.png'):
|
||||||
copyfile(baseDir+'/img/login-background.png',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:
|
if not autocomplete:
|
||||||
autocompleteStr='autocomplete="off" value=""'
|
autocompleteStr='autocomplete="off" value=""'
|
||||||
|
|
||||||
|
|
||||||
loginForm=htmlHeader(cssFilename,loginCSS)
|
loginForm=htmlHeader(cssFilename,loginCSS)
|
||||||
loginForm+='<form method="POST" action="/login">'
|
loginForm+='<form method="POST" action="/login">'
|
||||||
loginForm+=' <div class="imgcontainer">'
|
loginForm+=' <div class="imgcontainer">'
|
||||||
loginForm+=' <img loading="lazy" src="login.png" alt="login image" class="loginimage">'
|
loginForm+=' <img loading="lazy" src="'+loginImage+'" alt="login image" class="loginimage">'
|
||||||
loginForm+=loginText+TOSstr
|
loginForm+=loginText+TOSstr
|
||||||
loginForm+=' </div>'
|
loginForm+=' </div>'
|
||||||
loginForm+=''
|
loginForm+=''
|
||||||
|
|
Loading…
Reference in New Issue