mirror of https://gitlab.com/bashrc2/epicyon
Show activitypub protocol images
parent
1168f1c8a9
commit
a0700df668
58
daemon.py
58
daemon.py
|
@ -8233,6 +8233,56 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
return
|
return
|
||||||
self._404()
|
self._404()
|
||||||
|
|
||||||
|
def _show_specification_image(self, path: str,
|
||||||
|
base_dir: str, getreq_start_time) -> None:
|
||||||
|
"""Shows an image within the ActivityPub specification document
|
||||||
|
"""
|
||||||
|
image_filename = path.split('/', 1)[1]
|
||||||
|
if '/' in image_filename:
|
||||||
|
self._404()
|
||||||
|
return
|
||||||
|
media_filename = \
|
||||||
|
base_dir + '/specification/' + image_filename
|
||||||
|
if self._etag_exists(media_filename):
|
||||||
|
# The file has not changed
|
||||||
|
self._304()
|
||||||
|
return
|
||||||
|
if self.server.iconsCache.get(media_filename):
|
||||||
|
media_binary = self.server.iconsCache[media_filename]
|
||||||
|
mime_type_str = media_file_mime_type(media_filename)
|
||||||
|
self._set_headers_etag(media_filename,
|
||||||
|
mime_type_str,
|
||||||
|
media_binary, None,
|
||||||
|
self.server.domain_full,
|
||||||
|
False, None)
|
||||||
|
self._write(media_binary)
|
||||||
|
fitness_performance(getreq_start_time, self.server.fitness,
|
||||||
|
'_GET', '_show_specification_image',
|
||||||
|
self.server.debug)
|
||||||
|
return
|
||||||
|
if os.path.isfile(media_filename):
|
||||||
|
media_binary = None
|
||||||
|
try:
|
||||||
|
with open(media_filename, 'rb') as av_file:
|
||||||
|
media_binary = av_file.read()
|
||||||
|
except OSError:
|
||||||
|
print('EX: unable to read specification image ' +
|
||||||
|
media_filename)
|
||||||
|
if media_binary:
|
||||||
|
mime_type = media_file_mime_type(media_filename)
|
||||||
|
self._set_headers_etag(media_filename,
|
||||||
|
mime_type,
|
||||||
|
media_binary, None,
|
||||||
|
self.server.domain_full,
|
||||||
|
False, None)
|
||||||
|
self._write(media_binary)
|
||||||
|
self.server.iconsCache[media_filename] = media_binary
|
||||||
|
fitness_performance(getreq_start_time, self.server.fitness,
|
||||||
|
'_GET', '_show_specification_image',
|
||||||
|
self.server.debug)
|
||||||
|
return
|
||||||
|
self._404()
|
||||||
|
|
||||||
def _show_help_screen_image(self, calling_domain: str, path: str,
|
def _show_help_screen_image(self, calling_domain: str, path: str,
|
||||||
base_dir: str, getreq_start_time) -> None:
|
base_dir: str, getreq_start_time) -> None:
|
||||||
"""Shows a help screen image
|
"""Shows a help screen image
|
||||||
|
@ -16737,6 +16787,14 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
self.server.base_dir, getreq_start_time)
|
self.server.base_dir, getreq_start_time)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# show images within https://instancedomain/activitypub
|
||||||
|
if self.path.startswith('/activitypub-tutorial-'):
|
||||||
|
if self.path.endswith('.png'):
|
||||||
|
self._show_specification_image(self.path,
|
||||||
|
self.server.base_dir,
|
||||||
|
getreq_start_time)
|
||||||
|
return
|
||||||
|
|
||||||
# help screen images
|
# help screen images
|
||||||
# Note that this comes before the busy flag to avoid conflicts
|
# Note that this comes before the busy flag to avoid conflicts
|
||||||
if self.path.startswith('/helpimages/'):
|
if self.path.startswith('/helpimages/'):
|
||||||
|
|
Loading…
Reference in New Issue