forked from indymedia/epicyon
Simplify
parent
ef53f79fca
commit
e3a5e074c2
51
daemon.py
51
daemon.py
|
@ -1824,34 +1824,29 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
else:
|
else:
|
||||||
# directly search the binary array for the beginning
|
# directly search the binary array for the beginning
|
||||||
# of an image
|
# of an image
|
||||||
mediaTypes={
|
extensionList=['png','jpeg','gif','mp4','webm','ogv','mp3','ogg']
|
||||||
'image': ['png','jpeg','gif'],
|
for extension in extensionList:
|
||||||
'video': ['mp4','webm','ogv'],
|
searchStr=b'Content-Type: image/png'
|
||||||
'audio': ['mp3','ogg']
|
if extension=='jpeg':
|
||||||
}
|
searchStr=b'Content-Type: image/jpeg'
|
||||||
for mType,extensionList in mediaTypes.items():
|
elif extension=='gif':
|
||||||
for extension in extensionList:
|
searchStr=b'Content-Type: image/gif'
|
||||||
searchStr=b'Content-Type: image/png'
|
elif extension=='mp4':
|
||||||
|
searchStr=b'Content-Type: video/mp4'
|
||||||
|
elif extension=='ogv':
|
||||||
|
searchStr=b'Content-Type: video/ogv'
|
||||||
|
elif extension=='mp3':
|
||||||
|
searchStr=b'Content-Type: audio/mp3'
|
||||||
|
elif extension=='ogg':
|
||||||
|
searchStr=b'Content-Type: audio/ogg'
|
||||||
|
imageLocation=postBytes.find(searchStr)
|
||||||
|
filenameBase=self.server.baseDir+'/accounts/'+nickname+'@'+self.server.domain+'/upload'
|
||||||
|
if imageLocation>-1:
|
||||||
if extension=='jpeg':
|
if extension=='jpeg':
|
||||||
searchStr=b'Content-Type: image/jpeg'
|
extension='jpg'
|
||||||
elif extension=='gif':
|
filename=filenameBase+'.'+extension
|
||||||
searchStr=b'Content-Type: image/gif'
|
attachmentMediaType=mType
|
||||||
elif extension=='mp4':
|
break
|
||||||
searchStr=b'Content-Type: video/mp4'
|
|
||||||
elif extension=='ogv':
|
|
||||||
searchStr=b'Content-Type: video/ogv'
|
|
||||||
elif extension=='mp3':
|
|
||||||
searchStr=b'Content-Type: audio/mp3'
|
|
||||||
elif extension=='ogg':
|
|
||||||
searchStr=b'Content-Type: audio/ogg'
|
|
||||||
imageLocation=postBytes.find(searchStr)
|
|
||||||
filenameBase=self.server.baseDir+'/accounts/'+nickname+'@'+self.server.domain+'/upload'
|
|
||||||
if imageLocation>-1:
|
|
||||||
if extension=='jpeg':
|
|
||||||
extension='jpg'
|
|
||||||
filename=filenameBase+'.'+extension
|
|
||||||
attachmentMediaType=mType
|
|
||||||
break
|
|
||||||
if filename and imageLocation>-1:
|
if filename and imageLocation>-1:
|
||||||
# locate the beginning of the image, after any
|
# locate the beginning of the image, after any
|
||||||
# carriage returns
|
# carriage returns
|
||||||
|
@ -1865,6 +1860,8 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
fd = open(filename, 'wb')
|
fd = open(filename, 'wb')
|
||||||
fd.write(postBytes[startPos:])
|
fd.write(postBytes[startPos:])
|
||||||
fd.close()
|
fd.close()
|
||||||
|
else:
|
||||||
|
filename=None
|
||||||
|
|
||||||
# send the post
|
# send the post
|
||||||
if not fields.get('message'):
|
if not fields.get('message'):
|
||||||
|
|
Loading…
Reference in New Issue