forked from indymedia/epicyon
Create thread to send new posts
parent
3f8e4e0b2f
commit
795d6b6f53
120
daemon.py
120
daemon.py
|
@ -2370,33 +2370,24 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
def do_HEAD(self):
|
||||
self._set_headers('application/json',0,None)
|
||||
|
||||
def _receiveNewPost(self,authorized: bool,postType: str,path: str) -> (int,int):
|
||||
def _receiveNewPostThread(self,authorized: bool,postType: str,path: str,headers: []) -> int:
|
||||
# 0 = this is not a new post
|
||||
# 1 = new post success
|
||||
# -1 = new post failed
|
||||
# 2 = new post canceled
|
||||
pageNumber=1
|
||||
if authorized and '/users/' in path and '?'+postType+'?' in path:
|
||||
if '?page=' in path:
|
||||
pageNumberStr=path.split('?page=')[1]
|
||||
if '?' in pageNumberStr:
|
||||
pageNumberStr=pageNumberStr.split('?')[0]
|
||||
if pageNumberStr.isdigit():
|
||||
pageNumber=int(pageNumberStr)
|
||||
path=path.split('?page=')[0]
|
||||
if ' boundary=' in self.headers['Content-type']:
|
||||
if ' boundary=' in headers['Content-type']:
|
||||
nickname=None
|
||||
nicknameStr=path.split('/users/')[1]
|
||||
if '/' in nicknameStr:
|
||||
nickname=nicknameStr.split('/')[0]
|
||||
else:
|
||||
return -1,pageNumber
|
||||
length = int(self.headers['Content-length'])
|
||||
return -1
|
||||
length = int(headers['Content-length'])
|
||||
if length>self.server.maxPostLength:
|
||||
print('POST size too large')
|
||||
return -1,pageNumber
|
||||
return -1
|
||||
|
||||
boundary=self.headers['Content-type'].split('boundary=')[1]
|
||||
boundary=headers['Content-type'].split('boundary=')[1]
|
||||
if ';' in boundary:
|
||||
boundary=boundary.split(';')[0]
|
||||
|
||||
|
@ -2476,12 +2467,12 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
|
||||
# send the post
|
||||
if not fields.get('message') and not fields.get('imageDescription'):
|
||||
return -1,pageNumber
|
||||
return -1
|
||||
if fields.get('submitPost'):
|
||||
if fields['submitPost']!='Submit':
|
||||
return -1,pageNumber
|
||||
return -1
|
||||
else:
|
||||
return 2,pageNumber
|
||||
return 2
|
||||
|
||||
if not fields.get('imageDescription'):
|
||||
fields['imageDescription']=None
|
||||
|
@ -2508,9 +2499,9 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
messageJson, \
|
||||
self.server.maxReplies, \
|
||||
self.server.debug)
|
||||
return 1,pageNumber
|
||||
return 1
|
||||
else:
|
||||
return -1,pageNumber
|
||||
return -1
|
||||
|
||||
if postType=='newunlisted':
|
||||
messageJson= \
|
||||
|
@ -2530,9 +2521,9 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
messageJson, \
|
||||
self.server.maxReplies, \
|
||||
self.server.debug)
|
||||
return 1,pageNumber
|
||||
return 1
|
||||
else:
|
||||
return -1,pageNumber
|
||||
return -1
|
||||
|
||||
if postType=='newfollowers':
|
||||
messageJson= \
|
||||
|
@ -2552,9 +2543,9 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
messageJson, \
|
||||
self.server.maxReplies, \
|
||||
self.server.debug)
|
||||
return 1,pageNumber
|
||||
return 1
|
||||
else:
|
||||
return -1,pageNumber
|
||||
return -1
|
||||
|
||||
if postType=='newdm':
|
||||
messageJson=None
|
||||
|
@ -2581,14 +2572,14 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
messageJson, \
|
||||
self.server.maxReplies, \
|
||||
self.server.debug)
|
||||
return 1,pageNumber
|
||||
return 1
|
||||
else:
|
||||
return -1,pageNumber
|
||||
return -1
|
||||
|
||||
if postType=='newreport':
|
||||
if attachmentMediaType:
|
||||
if attachmentMediaType!='image':
|
||||
return -1,pageNumber
|
||||
return -1
|
||||
# So as to be sure that this only goes to moderators
|
||||
# and not accounts being reported we disable any
|
||||
# included fediverse addresses by replacing '@' with '-at-'
|
||||
|
@ -2605,22 +2596,22 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
if messageJson:
|
||||
self.postToNickname=nickname
|
||||
if self._postToOutbox(messageJson,__version__):
|
||||
return 1,pageNumber
|
||||
return 1
|
||||
else:
|
||||
return -1,pageNumber
|
||||
return -1
|
||||
|
||||
if postType=='newshare':
|
||||
if not fields.get('itemType'):
|
||||
return -1,pageNumber
|
||||
return -1
|
||||
if not fields.get('category'):
|
||||
return -1,pageNumber
|
||||
return -1
|
||||
if not fields.get('location'):
|
||||
return -1,pageNumber
|
||||
return -1
|
||||
if not fields.get('duration'):
|
||||
return -1,pageNumber
|
||||
return -1
|
||||
if attachmentMediaType:
|
||||
if attachmentMediaType!='image':
|
||||
return -1,pageNumber
|
||||
return -1
|
||||
addShare(self.server.baseDir, \
|
||||
self.server.httpPrefix, \
|
||||
nickname, \
|
||||
|
@ -2637,10 +2628,44 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
if os.path.isfile(filename):
|
||||
os.remove(filename)
|
||||
self.postToNickname=nickname
|
||||
return 1,pageNumber
|
||||
return -1,pageNumber
|
||||
else:
|
||||
return 0,pageNumber
|
||||
return 1
|
||||
return -1
|
||||
|
||||
def _receiveNewPost(self,authorized: bool,postType: str,path: str) -> bool:
|
||||
"""A new post has been created
|
||||
This creates a thread to send the new post
|
||||
"""
|
||||
pageNumber=1
|
||||
if authorized and '/users/' in path and '?'+postType+'?' in path:
|
||||
if '?page=' in path:
|
||||
pageNumberStr=path.split('?page=')[1]
|
||||
if '?' in pageNumberStr:
|
||||
pageNumberStr=pageNumberStr.split('?')[0]
|
||||
if pageNumberStr.isdigit():
|
||||
pageNumber=int(pageNumberStr)
|
||||
path=path.split('?page=')[0]
|
||||
|
||||
newPostThreadName=self.postToNickname
|
||||
if not newPostThreadName:
|
||||
newPostThreadName='*'
|
||||
|
||||
if self.server.newPostThread.get(newPostThreadName):
|
||||
print('Waiting for previous new post thread to end')
|
||||
waitCtr=0
|
||||
while self.server.newPostThread[newPostThreadName].isAlive() and waitCtr<8:
|
||||
time.sleep(1)
|
||||
waitCtr+=1
|
||||
if waitCtr>=8:
|
||||
self.server.newPostThread[newPostThreadName].kill()
|
||||
|
||||
print('Creating new post thread')
|
||||
self.server.newPostThread[newPostThreadName]= \
|
||||
threadWithTrace(target=self._receiveNewPostThread, \
|
||||
args=(authorized,postType,path,self.headers.copy()),daemon=True)
|
||||
print('Starting new post thread')
|
||||
self.server.newPostThread[newPostThreadName].start()
|
||||
return True
|
||||
return False
|
||||
|
||||
def do_POST(self):
|
||||
if not self.server.session:
|
||||
|
@ -3637,48 +3662,42 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
self.server.POSTbusy=False
|
||||
return
|
||||
|
||||
postState,pageNumber=self._receiveNewPost(authorized,'newpost',self.path)
|
||||
if postState!=0:
|
||||
if self._receiveNewPost(authorized,'newpost',self.path):
|
||||
nickname=self.path.split('/users/')[1]
|
||||
if '/' in nickname:
|
||||
nickname=nickname.split('/')[0]
|
||||
self._redirect_headers('/users/'+nickname+'/inbox?page='+str(pageNumber),cookie)
|
||||
self.server.POSTbusy=False
|
||||
return
|
||||
postState,pageNumber=self._receiveNewPost(authorized,'newunlisted',self.path)
|
||||
if postState!=0:
|
||||
if self._receiveNewPost(authorized,'newunlisted',self.path):
|
||||
nickname=self.path.split('/users/')[1]
|
||||
if '/' in nickname:
|
||||
nickname=nickname.split('/')[0]
|
||||
self._redirect_headers('/users/'+nickname+'/inbox?page='+str(pageNumber),cookie)
|
||||
self.server.POSTbusy=False
|
||||
return
|
||||
postState,pageNumber=self._receiveNewPost(authorized,'newfollowers',self.path)
|
||||
if postState!=0:
|
||||
if self._receiveNewPost(authorized,'newfollowers',self.path):
|
||||
nickname=self.path.split('/users/')[1]
|
||||
if '/' in nickname:
|
||||
nickname=nickname.split('/')[0]
|
||||
self._redirect_headers('/users/'+nickname+'/inbox?page='+str(pageNumber),cookie)
|
||||
self.server.POSTbusy=False
|
||||
return
|
||||
postState,pageNumber=self._receiveNewPost(authorized,'newdm',self.path)
|
||||
if postState!=0:
|
||||
if self._receiveNewPost(authorized,'newdm',self.path):
|
||||
nickname=self.path.split('/users/')[1]
|
||||
if '/' in nickname:
|
||||
nickname=nickname.split('/')[0]
|
||||
self._redirect_headers('/users/'+nickname+'/inbox?page='+str(pageNumber),cookie)
|
||||
self.server.POSTbusy=False
|
||||
return
|
||||
postState,pageNumber=self._receiveNewPost(authorized,'newreport',self.path)
|
||||
if postState!=0:
|
||||
if self._receiveNewPost(authorized,'newreport',self.path):
|
||||
nickname=self.path.split('/users/')[1]
|
||||
if '/' in nickname:
|
||||
nickname=nickname.split('/')[0]
|
||||
self._redirect_headers('/users/'+nickname+'/inbox?page='+str(pageNumber),cookie)
|
||||
self.server.POSTbusy=False
|
||||
return
|
||||
postState,pageNumber=self._receiveNewPost(authorized,'newshare',self.path)
|
||||
if postState!=0:
|
||||
if self._receiveNewPost(authorized,'newshare',self.path):
|
||||
nickname=self.path.split('/users/')[1]
|
||||
if '/' in nickname:
|
||||
nickname=nickname.split('/')[0]
|
||||
|
@ -3948,6 +3967,7 @@ def runDaemon(projectVersion, \
|
|||
print(e)
|
||||
|
||||
httpd.outboxThread={}
|
||||
httpd.newPostThread={}
|
||||
httpd.projectVersion=projectVersion
|
||||
httpd.authenticatedFetch=authenticatedFetch
|
||||
# max POST size of 30M
|
||||
|
|
Loading…
Reference in New Issue