mirror of https://gitlab.com/bashrc2/epicyon
Supporting webp image format
parent
7c6f413e95
commit
b0b5f1fece
12
daemon.py
12
daemon.py
|
@ -517,6 +517,8 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
fileExtension='jpg'
|
fileExtension='jpg'
|
||||||
elif mediaTypeStr.endswith('gif'):
|
elif mediaTypeStr.endswith('gif'):
|
||||||
fileExtension='gif'
|
fileExtension='gif'
|
||||||
|
elif mediaTypeStr.endswith('webp'):
|
||||||
|
fileExtension='webp'
|
||||||
elif mediaTypeStr.endswith('audio/mpeg'):
|
elif mediaTypeStr.endswith('audio/mpeg'):
|
||||||
fileExtension='mp3'
|
fileExtension='mp3'
|
||||||
elif mediaTypeStr.endswith('ogg'):
|
elif mediaTypeStr.endswith('ogg'):
|
||||||
|
@ -1085,6 +1087,8 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
mediaImageType='png'
|
mediaImageType='png'
|
||||||
elif emojiFilename.endswith('.jpg'):
|
elif emojiFilename.endswith('.jpg'):
|
||||||
mediaImageType='jpeg'
|
mediaImageType='jpeg'
|
||||||
|
elif emojiFilename.endswith('.webp'):
|
||||||
|
mediaImageType='webp'
|
||||||
else:
|
else:
|
||||||
mediaImageType='gif'
|
mediaImageType='gif'
|
||||||
with open(emojiFilename, 'rb') as avFile:
|
with open(emojiFilename, 'rb') as avFile:
|
||||||
|
@ -1101,6 +1105,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
if self.path.endswith('.png') or \
|
if self.path.endswith('.png') or \
|
||||||
self.path.endswith('.jpg') or \
|
self.path.endswith('.jpg') or \
|
||||||
self.path.endswith('.gif') or \
|
self.path.endswith('.gif') or \
|
||||||
|
self.path.endswith('.webp') or \
|
||||||
self.path.endswith('.mp4') or \
|
self.path.endswith('.mp4') or \
|
||||||
self.path.endswith('.ogv') or \
|
self.path.endswith('.ogv') or \
|
||||||
self.path.endswith('.mp3') or \
|
self.path.endswith('.mp3') or \
|
||||||
|
@ -1116,6 +1121,8 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
mediaFileType='image/jpeg'
|
mediaFileType='image/jpeg'
|
||||||
elif mediaFilename.endswith('.gif'):
|
elif mediaFilename.endswith('.gif'):
|
||||||
mediaFileType='image/gif'
|
mediaFileType='image/gif'
|
||||||
|
elif mediaFilename.endswith('.webp'):
|
||||||
|
mediaFileType='image/webp'
|
||||||
elif mediaFilename.endswith('.mp4'):
|
elif mediaFilename.endswith('.mp4'):
|
||||||
mediaFileType='video/mp4'
|
mediaFileType='video/mp4'
|
||||||
elif mediaFilename.endswith('.ogv'):
|
elif mediaFilename.endswith('.ogv'):
|
||||||
|
@ -1137,6 +1144,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
if '/sharefiles/' in self.path:
|
if '/sharefiles/' in self.path:
|
||||||
if self.path.endswith('.png') or \
|
if self.path.endswith('.png') or \
|
||||||
self.path.endswith('.jpg') or \
|
self.path.endswith('.jpg') or \
|
||||||
|
self.path.endswith('.webp') or \
|
||||||
self.path.endswith('.gif'):
|
self.path.endswith('.gif'):
|
||||||
mediaStr=self.path.split('/sharefiles/')[1]
|
mediaStr=self.path.split('/sharefiles/')[1]
|
||||||
mediaFilename= \
|
mediaFilename= \
|
||||||
|
@ -1147,6 +1155,8 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
mediaFileType='png'
|
mediaFileType='png'
|
||||||
elif mediaFilename.endswith('.jpg'):
|
elif mediaFilename.endswith('.jpg'):
|
||||||
mediaFileType='jpeg'
|
mediaFileType='jpeg'
|
||||||
|
elif mediaFilename.endswith('.webp'):
|
||||||
|
mediaFileType='webp'
|
||||||
else:
|
else:
|
||||||
mediaFileType='gif'
|
mediaFileType='gif'
|
||||||
with open(mediaFilename, 'rb') as avFile:
|
with open(mediaFilename, 'rb') as avFile:
|
||||||
|
@ -4347,6 +4357,8 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
mediaFilename=mediaFilenameBase+'.jpg'
|
mediaFilename=mediaFilenameBase+'.jpg'
|
||||||
if self.headers['Content-type'].endswith('gif'):
|
if self.headers['Content-type'].endswith('gif'):
|
||||||
mediaFilename=mediaFilenameBase+'.gif'
|
mediaFilename=mediaFilenameBase+'.gif'
|
||||||
|
if self.headers['Content-type'].endswith('webp'):
|
||||||
|
mediaFilename=mediaFilenameBase+'.webp'
|
||||||
with open(mediaFilename, 'wb') as avFile:
|
with open(mediaFilename, 'wb') as avFile:
|
||||||
avFile.write(mediaBytes)
|
avFile.write(mediaBytes)
|
||||||
if self.server.debug:
|
if self.server.debug:
|
||||||
|
|
6
media.py
6
media.py
|
@ -35,7 +35,7 @@ def getImageHash(imageFilename: str) -> str:
|
||||||
return blurencode(numpy.array(Image.open(imageFilename).convert("RGB")))
|
return blurencode(numpy.array(Image.open(imageFilename).convert("RGB")))
|
||||||
|
|
||||||
def isMedia(imageFilename: str) -> bool:
|
def isMedia(imageFilename: str) -> bool:
|
||||||
permittedMedia=['png','jpg','gif','mp4','ogv','mp3','ogg']
|
permittedMedia=['png','jpg','gif','webp','mp4','ogv','mp3','ogg']
|
||||||
for m in permittedMedia:
|
for m in permittedMedia:
|
||||||
if imageFilename.endswith('.'+m):
|
if imageFilename.endswith('.'+m):
|
||||||
return True
|
return True
|
||||||
|
@ -58,7 +58,7 @@ def getAttachmentMediaType(filename: str) -> str:
|
||||||
image, video or audio
|
image, video or audio
|
||||||
"""
|
"""
|
||||||
mediaType=None
|
mediaType=None
|
||||||
imageTypes=['png','jpg','jpeg','gif']
|
imageTypes=['png','jpg','jpeg','gif','webp']
|
||||||
for mType in imageTypes:
|
for mType in imageTypes:
|
||||||
if filename.endswith('.'+mType):
|
if filename.endswith('.'+mType):
|
||||||
return 'image'
|
return 'image'
|
||||||
|
@ -84,7 +84,7 @@ def attachMedia(baseDir: str,httpPrefix: str,domain: str,port: int, \
|
||||||
return postJson
|
return postJson
|
||||||
|
|
||||||
fileExtension=None
|
fileExtension=None
|
||||||
acceptedTypes=['png','jpg','gif','mp4','webm','ogv','mp3','ogg']
|
acceptedTypes=['png','jpg','gif','webp','mp4','webm','ogv','mp3','ogg']
|
||||||
for mType in acceptedTypes:
|
for mType in acceptedTypes:
|
||||||
if imageFilename.endswith('.'+mType):
|
if imageFilename.endswith('.'+mType):
|
||||||
if mType=='jpg':
|
if mType=='jpg':
|
||||||
|
|
|
@ -72,6 +72,9 @@ def updateAvatarImageCache(session,baseDir: str,httpPrefix: str,actor: str,avata
|
||||||
elif avatarUrl.endswith('.gif') or '.gif?' in avatarUrl:
|
elif avatarUrl.endswith('.gif') or '.gif?' in avatarUrl:
|
||||||
sessionHeaders = {'Accept': 'image/gif'}
|
sessionHeaders = {'Accept': 'image/gif'}
|
||||||
avatarImageFilename=avatarImagePath+'.gif'
|
avatarImageFilename=avatarImagePath+'.gif'
|
||||||
|
elif avatarUrl.endswith('.webp') or '.webp?' in avatarUrl:
|
||||||
|
sessionHeaders = {'Accept': 'image/webp'}
|
||||||
|
avatarImageFilename=avatarImagePath+'.webp'
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
if not os.path.isfile(avatarImageFilename) or force:
|
if not os.path.isfile(avatarImageFilename) or force:
|
||||||
|
@ -130,6 +133,8 @@ def getPersonAvatarUrl(baseDir: str,personUrl: str,personCache: {}) -> str:
|
||||||
return '/avatars/'+actorStr+'.jpg'
|
return '/avatars/'+actorStr+'.jpg'
|
||||||
if os.path.isfile(avatarImagePath+'.gif'):
|
if os.path.isfile(avatarImagePath+'.gif'):
|
||||||
return '/avatars/'+actorStr+'.gif'
|
return '/avatars/'+actorStr+'.gif'
|
||||||
|
if os.path.isfile(avatarImagePath+'.webp'):
|
||||||
|
return '/avatars/'+actorStr+'.webp'
|
||||||
if os.path.isfile(avatarImagePath):
|
if os.path.isfile(avatarImagePath):
|
||||||
return '/avatars/'+actorStr
|
return '/avatars/'+actorStr
|
||||||
|
|
||||||
|
@ -1052,7 +1057,7 @@ def htmlNewPost(translate: {},baseDir: str, \
|
||||||
newPostForm+=' <div class="container">'
|
newPostForm+=' <div class="container">'
|
||||||
newPostForm+=' <input type="text" placeholder="'+translate['Image description']+'" name="imageDescription">'
|
newPostForm+=' <input type="text" placeholder="'+translate['Image description']+'" name="imageDescription">'
|
||||||
newPostForm+=' <input type="file" id="attachpic" name="attachpic"'
|
newPostForm+=' <input type="file" id="attachpic" name="attachpic"'
|
||||||
newPostForm+=' accept=".png, .jpg, .jpeg, .gif, .mp4, .webm, .ogv, .mp3, .ogg">'
|
newPostForm+=' accept=".png, .jpg, .jpeg, .gif, .webp, .mp4, .webm, .ogv, .mp3, .ogg">'
|
||||||
newPostForm+=' </div>'
|
newPostForm+=' </div>'
|
||||||
newPostForm+=' </div>'
|
newPostForm+=' </div>'
|
||||||
newPostForm+='</form>'
|
newPostForm+='</form>'
|
||||||
|
@ -2057,6 +2062,7 @@ def individualPostAsHtml(iconsDir: str,translate: {}, \
|
||||||
if attach['url'].endswith('.png') or \
|
if attach['url'].endswith('.png') or \
|
||||||
attach['url'].endswith('.jpg') or \
|
attach['url'].endswith('.jpg') or \
|
||||||
attach['url'].endswith('.jpeg') or \
|
attach['url'].endswith('.jpeg') or \
|
||||||
|
attach['url'].endswith('.webp') or \
|
||||||
attach['url'].endswith('.gif'):
|
attach['url'].endswith('.gif'):
|
||||||
if attachmentCtr>0:
|
if attachmentCtr>0:
|
||||||
attachmentStr+='<br>'
|
attachmentStr+='<br>'
|
||||||
|
|
Loading…
Reference in New Issue