mirror of https://gitlab.com/bashrc2/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._set_headers('text/css')
|
||||||
self.wfile.write(css.encode('utf-8'))
|
self.wfile.write(css.encode('utf-8'))
|
||||||
return
|
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
|
# show media
|
||||||
|
# Note that this comes before the busy flag to avoid conflicts
|
||||||
if '/media/' in self.path:
|
if '/media/' 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 \
|
||||||
|
@ -373,12 +351,11 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
with open(mediaFilename, 'rb') as avFile:
|
with open(mediaFilename, 'rb') as avFile:
|
||||||
mediaBinary = avFile.read()
|
mediaBinary = avFile.read()
|
||||||
self.wfile.write(mediaBinary)
|
self.wfile.write(mediaBinary)
|
||||||
self.server.GETbusy=False
|
|
||||||
return
|
return
|
||||||
self._404()
|
self._404()
|
||||||
self.server.GETbusy=False
|
|
||||||
return
|
return
|
||||||
# show avatar or background image
|
# show avatar or background image
|
||||||
|
# Note that this comes before the busy flag to avoid conflicts
|
||||||
if '/users/' in self.path:
|
if '/users/' 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 \
|
||||||
|
@ -401,6 +378,28 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
with open(avatarFilename, 'rb') as avFile:
|
with open(avatarFilename, 'rb') as avFile:
|
||||||
avBinary = avFile.read()
|
avBinary = avFile.read()
|
||||||
self.wfile.write(avBinary)
|
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
|
self.server.GETbusy=False
|
||||||
return
|
return
|
||||||
# get an individual post from the path /@nickname/statusnumber
|
# get an individual post from the path /@nickname/statusnumber
|
||||||
|
|
Loading…
Reference in New Issue