Merge branch 'main' of gitlab.com:bashrc2/epicyon

merge-requests/30/head
Bob Mottram 2022-05-22 21:31:33 +01:00
commit 8f5d8f85f8
4 changed files with 79 additions and 14 deletions

View File

@ -871,11 +871,15 @@ class PubServer(BaseHTTPRequestHandler):
self.end_headers()
def _set_headers_head(self, file_format: str, length: int, etag: str,
calling_domain: str, permissive: bool) -> None:
calling_domain: str, permissive: bool,
last_modified_time_str: str) -> None:
self._set_headers_base(file_format, length, None, calling_domain,
permissive)
if etag:
self.send_header('ETag', '"' + etag + '"')
if last_modified_time_str:
self.send_header('last-modified',
last_modified_time_str)
self.end_headers()
def _set_headers_etag(self, media_filename: str, file_format: str,
@ -18597,17 +18601,58 @@ class PubServer(BaseHTTPRequestHandler):
check_path = self.path
etag = None
file_length = -1
last_modified_time_str = None
if '/media/' in self.path:
if '/media/' in self.path or \
'/accounts/avatars/' in self.path or \
'/accounts/headers/' in self.path:
if is_image_file(self.path) or \
path_is_video(self.path) or \
path_is_audio(self.path):
media_str = self.path.split('/media/')[1]
media_filename = \
self.server.base_dir + '/media/' + media_str
if '/media/' in self.path:
media_str = self.path.split('/media/')[1]
media_filename = \
self.server.base_dir + '/media/' + media_str
elif '/accounts/avatars/' in self.path:
avatar_file = self.path.split('/accounts/avatars/')[1]
if '/' not in avatar_file:
self._404()
return
nickname = avatar_file.split('/')[0]
avatar_file = avatar_file.split('/')[1]
avatar_file_ext = avatar_file.split('.')[-1]
# remove any numbers, eg. avatar123.png becomes avatar.png
if avatar_file.startswith('avatar'):
avatar_file = 'avatar.' + avatar_file_ext
media_filename = \
self.server.base_dir + '/accounts/' + \
nickname + '@' + self.server.domain + '/' + \
avatar_file
else:
banner_file = self.path.split('/accounts/headers/')[1]
if '/' not in banner_file:
self._404()
return
nickname = banner_file.split('/')[0]
banner_file = banner_file.split('/')[1]
banner_file_ext = banner_file.split('.')[-1]
# remove any numbers, eg. banner123.png becomes banner.png
if banner_file.startswith('banner'):
banner_file = 'banner.' + banner_file_ext
media_filename = \
self.server.base_dir + '/accounts/' + \
nickname + '@' + self.server.domain + '/' + \
banner_file
if os.path.isfile(media_filename):
check_path = media_filename
file_length = os.path.getsize(media_filename)
media_tm = os.path.getmtime(media_filename)
last_modified_time = \
datetime.datetime.fromtimestamp(media_tm)
time_format_str = '%a, %d %b %Y %H:%M:%S GMT'
last_modified_time_str = \
last_modified_time.strftime(time_format_str)
media_tag_filename = media_filename + '.etag'
if os.path.isfile(media_tag_filename):
try:
@ -18632,10 +18677,14 @@ class PubServer(BaseHTTPRequestHandler):
except OSError:
print('EX: do_HEAD unable to write ' +
media_tag_filename)
else:
self._404()
return
media_file_type = media_file_mime_type(check_path)
self._set_headers_head(media_file_type, file_length,
etag, calling_domain, False)
etag, calling_domain, False,
last_modified_time_str)
def _receive_new_post_process(self, post_type: str, path: str, headers: {},
length: int, post_bytes, boundary: str,

View File

@ -194,7 +194,10 @@ def _geocoords_from_wego_link(url: str) -> (int, float, float):
return zoom, latitude, longitude
def geocoords_from_map_link(url: str, osm_domain: str) -> (int, float, float):
def geocoords_from_map_link(url: str,
osm_domain: str = 'openstreetmap.org') -> (int,
float,
float):
"""Returns geocoordinates from a map link url
"""
if osm_domain in url:

View File

@ -93,6 +93,7 @@ from linked_data_sig import generate_json_signature
from petnames import resolve_petnames
from video import convert_video_to_note
from context import get_individual_post_context
from maps import geocoords_from_map_link
def is_moderator(base_dir: str, nickname: str) -> bool:
@ -1280,11 +1281,24 @@ def _create_post_place_and_time(event_date: str, end_date: str,
"endTime": end_date_str
})
if location and not event_uuid:
tags.append({
"@context": "https://www.w3.org/ns/activitystreams",
"type": "Place",
"name": location
})
latitude = longitude = None
if '://' in location:
_, latitude, longitude = \
geocoords_from_map_link(location)
if latitude and longitude:
tags.append({
"@context": "https://www.w3.org/ns/activitystreams",
"type": "Place",
"name": location,
"latitude": latitude,
"longitude": longitude
})
else:
tags.append({
"@context": "https://www.w3.org/ns/activitystreams",
"type": "Place",
"name": location
})
return event_date_str

View File

@ -2187,9 +2187,8 @@ def individual_post_as_html(signing_priv_key_pem: str,
set_map_preferences_url(base_dir, nickname, domain,
location_domain)
# remember the coordinates
osm_domain = 'openstreetmap.org'
map_zoom, map_latitude, map_longitude = \
geocoords_from_map_link(location_str, osm_domain)
geocoords_from_map_link(location_str)
if map_zoom and map_latitude and map_longitude:
set_map_preferences_coords(base_dir, nickname, domain,
map_latitude, map_longitude,