forked from indymedia/epicyon
Avoid busy conflicts when grabbing media
parent
63a84a57f7
commit
82676d5c92
49
daemon.py
49
daemon.py
|
@ -332,30 +332,8 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
self._set_headers('text/css')
|
||||
self.wfile.write(css.encode('utf-8'))
|
||||
return
|
||||
if self.server.GETbusy:
|
||||
currTimeGET=int(time.time())
|
||||
if currTimeGET-self.server.lastGET<10:
|
||||
if self.server.debug:
|
||||
print('DEBUG: GET Busy')
|
||||
self.send_response(429)
|
||||
self.end_headers()
|
||||
return
|
||||
self.server.lastGET=currTimeGET
|
||||
self.server.GETbusy=True
|
||||
|
||||
#print('Accept: '+self.headers['Accept'])
|
||||
|
||||
if not self._permittedDir(self.path):
|
||||
if self.server.debug:
|
||||
print('DEBUG: GET Not permitted')
|
||||
self._404()
|
||||
self.server.GETbusy=False
|
||||
return
|
||||
# get webfinger endpoint for a person
|
||||
if self._webfinger():
|
||||
self.server.GETbusy=False
|
||||
return
|
||||
# show media
|
||||
# Note that this comes before the busy flag to avoid conflicts
|
||||
if '/media/' in self.path:
|
||||
if self.path.endswith('.png') or \
|
||||
self.path.endswith('.jpg') or \
|
||||
|
@ -373,12 +351,11 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
with open(mediaFilename, 'rb') as avFile:
|
||||
mediaBinary = avFile.read()
|
||||
self.wfile.write(mediaBinary)
|
||||
self.server.GETbusy=False
|
||||
return
|
||||
self._404()
|
||||
self.server.GETbusy=False
|
||||
return
|
||||
# show avatar or background image
|
||||
# Note that this comes before the busy flag to avoid conflicts
|
||||
if '/users/' in self.path:
|
||||
if self.path.endswith('.png') or \
|
||||
self.path.endswith('.jpg') or \
|
||||
|
@ -401,6 +378,28 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
with open(avatarFilename, 'rb') as avFile:
|
||||
avBinary = avFile.read()
|
||||
self.wfile.write(avBinary)
|
||||
return
|
||||
if self.server.GETbusy:
|
||||
currTimeGET=int(time.time())
|
||||
if currTimeGET-self.server.lastGET<10:
|
||||
if self.server.debug:
|
||||
print('DEBUG: GET Busy')
|
||||
self.send_response(429)
|
||||
self.end_headers()
|
||||
return
|
||||
self.server.lastGET=currTimeGET
|
||||
self.server.GETbusy=True
|
||||
|
||||
#print('Accept: '+self.headers['Accept'])
|
||||
|
||||
if not self._permittedDir(self.path):
|
||||
if self.server.debug:
|
||||
print('DEBUG: GET Not permitted')
|
||||
self._404()
|
||||
self.server.GETbusy=False
|
||||
return
|
||||
# get webfinger endpoint for a person
|
||||
if self._webfinger():
|
||||
self.server.GETbusy=False
|
||||
return
|
||||
# get an individual post from the path /@nickname/statusnumber
|
||||
|
|
Loading…
Reference in New Issue