forked from indymedia/epicyon
Avoid collisions when making new posts
parent
a9e7f58977
commit
86ecab9ac3
48
daemon.py
48
daemon.py
|
@ -2920,7 +2920,8 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
self._set_headers('application/json',0,None)
|
self._set_headers('application/json',0,None)
|
||||||
|
|
||||||
def _receiveNewPostProcess(self,authorized: bool, \
|
def _receiveNewPostProcess(self,authorized: bool, \
|
||||||
postType: str,path: str,headers: {}) -> int:
|
postType: str,path: str,headers: {},
|
||||||
|
length: int,postBytes,boundary: str) -> int:
|
||||||
# Note: this needs to happen synchronously
|
# Note: this needs to happen synchronously
|
||||||
# 0 = this is not a new post
|
# 0 = this is not a new post
|
||||||
# 1 = new post success
|
# 1 = new post success
|
||||||
|
@ -2950,7 +2951,6 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
# Note: we don't use cgi here because it's due to be deprecated
|
# Note: we don't use cgi here because it's due to be deprecated
|
||||||
# in Python 3.8/3.10
|
# in Python 3.8/3.10
|
||||||
# Instead we use the multipart mime parser from the email module
|
# Instead we use the multipart mime parser from the email module
|
||||||
postBytes=self.rfile.read(length)
|
|
||||||
if self.server.debug:
|
if self.server.debug:
|
||||||
print('DEBUG: extracting media from POST')
|
print('DEBUG: extracting media from POST')
|
||||||
mediaBytes,postBytes=extractMediaInFormPOST(postBytes,boundary,'attachpic')
|
mediaBytes,postBytes=extractMediaInFormPOST(postBytes,boundary,'attachpic')
|
||||||
|
@ -3057,9 +3057,8 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
self.server.debug)
|
self.server.debug)
|
||||||
return 1
|
return 1
|
||||||
else:
|
else:
|
||||||
return -1
|
return -1
|
||||||
|
elif postType=='newunlisted':
|
||||||
if postType=='newunlisted':
|
|
||||||
messageJson= \
|
messageJson= \
|
||||||
createUnlistedPost(self.server.baseDir, \
|
createUnlistedPost(self.server.baseDir, \
|
||||||
nickname, \
|
nickname, \
|
||||||
|
@ -3084,8 +3083,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
return 1
|
return 1
|
||||||
else:
|
else:
|
||||||
return -1
|
return -1
|
||||||
|
elif postType=='newfollowers':
|
||||||
if postType=='newfollowers':
|
|
||||||
messageJson= \
|
messageJson= \
|
||||||
createFollowersOnlyPost(self.server.baseDir, \
|
createFollowersOnlyPost(self.server.baseDir, \
|
||||||
nickname, \
|
nickname, \
|
||||||
|
@ -3110,8 +3108,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
return 1
|
return 1
|
||||||
else:
|
else:
|
||||||
return -1
|
return -1
|
||||||
|
elif postType=='newdm':
|
||||||
if postType=='newdm':
|
|
||||||
messageJson=None
|
messageJson=None
|
||||||
if '@' in fields['message']:
|
if '@' in fields['message']:
|
||||||
messageJson= \
|
messageJson= \
|
||||||
|
@ -3143,8 +3140,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
return 1
|
return 1
|
||||||
else:
|
else:
|
||||||
return -1
|
return -1
|
||||||
|
elif postType=='newreport':
|
||||||
if postType=='newreport':
|
|
||||||
if attachmentMediaType:
|
if attachmentMediaType:
|
||||||
if attachmentMediaType!='image':
|
if attachmentMediaType!='image':
|
||||||
return -1
|
return -1
|
||||||
|
@ -3167,8 +3163,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
return 1
|
return 1
|
||||||
else:
|
else:
|
||||||
return -1
|
return -1
|
||||||
|
elif postType=='newshare':
|
||||||
if postType=='newshare':
|
|
||||||
if not fields.get('itemType'):
|
if not fields.get('itemType'):
|
||||||
return -1
|
return -1
|
||||||
if not fields.get('category'):
|
if not fields.get('category'):
|
||||||
|
@ -3249,10 +3244,29 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
headers[dictEntryName]=headerLine
|
headers[dictEntryName]=headerLine
|
||||||
print('New post headers: '+str(headers))
|
print('New post headers: '+str(headers))
|
||||||
|
|
||||||
# Note sending new posts needs to be synchronous, otherwise any attachments
|
length = int(headers['Content-Length'])
|
||||||
# can get mangled if other events happen during their decoding
|
if length>self.server.maxPostLength:
|
||||||
print('Creating new post: '+newPostThreadName)
|
print('POST size too large')
|
||||||
self._receiveNewPostProcess(authorized,postType,path,headers)
|
return pageNumber
|
||||||
|
|
||||||
|
if ' boundary=' in headers['Content-Type']:
|
||||||
|
boundary=headers['Content-Type'].split('boundary=')[1]
|
||||||
|
if ';' in boundary:
|
||||||
|
boundary=boundary.split(';')[0]
|
||||||
|
|
||||||
|
postBytes=self.rfile.read(length)
|
||||||
|
|
||||||
|
# second length check from the bytes received
|
||||||
|
# since Content-Length could be untruthful
|
||||||
|
length=len(postBytes)
|
||||||
|
if length>self.server.maxPostLength:
|
||||||
|
print('POST size too large')
|
||||||
|
return pageNumber
|
||||||
|
|
||||||
|
# Note sending new posts needs to be synchronous, otherwise any attachments
|
||||||
|
# can get mangled if other events happen during their decoding
|
||||||
|
print('Creating new post: '+newPostThreadName)
|
||||||
|
self._receiveNewPostProcess(authorized,postType,path,headers,length,postBytes,boundary)
|
||||||
return pageNumber
|
return pageNumber
|
||||||
|
|
||||||
def do_POST(self):
|
def do_POST(self):
|
||||||
|
|
Loading…
Reference in New Issue