mirror of https://gitlab.com/bashrc2/epicyon
				
				
				
			Merge branch 'main' of gitlab.com:bashrc2/epicyon
						commit
						8f5d8f85f8
					
				
							
								
								
									
										61
									
								
								daemon.py
								
								
								
								
							
							
						
						
									
										61
									
								
								daemon.py
								
								
								
								
							|  | @ -871,11 +871,15 @@ class PubServer(BaseHTTPRequestHandler): | ||||||
|         self.end_headers() |         self.end_headers() | ||||||
| 
 | 
 | ||||||
|     def _set_headers_head(self, file_format: str, length: int, etag: str, |     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, |         self._set_headers_base(file_format, length, None, calling_domain, | ||||||
|                                permissive) |                                permissive) | ||||||
|         if etag: |         if etag: | ||||||
|             self.send_header('ETag', '"' + etag + '"') |             self.send_header('ETag', '"' + etag + '"') | ||||||
|  |         if last_modified_time_str: | ||||||
|  |             self.send_header('last-modified', | ||||||
|  |                              last_modified_time_str) | ||||||
|         self.end_headers() |         self.end_headers() | ||||||
| 
 | 
 | ||||||
|     def _set_headers_etag(self, media_filename: str, file_format: str, |     def _set_headers_etag(self, media_filename: str, file_format: str, | ||||||
|  | @ -18597,17 +18601,58 @@ class PubServer(BaseHTTPRequestHandler): | ||||||
|         check_path = self.path |         check_path = self.path | ||||||
|         etag = None |         etag = None | ||||||
|         file_length = -1 |         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 \ |             if is_image_file(self.path) or \ | ||||||
|                path_is_video(self.path) or \ |                path_is_video(self.path) or \ | ||||||
|                path_is_audio(self.path): |                path_is_audio(self.path): | ||||||
|                 media_str = self.path.split('/media/')[1] |                 if '/media/' in self.path: | ||||||
|                 media_filename = \ |                     media_str = self.path.split('/media/')[1] | ||||||
|                     self.server.base_dir + '/media/' + media_str |                     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): |                 if os.path.isfile(media_filename): | ||||||
|                     check_path = media_filename |                     check_path = media_filename | ||||||
|                     file_length = os.path.getsize(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' |                     media_tag_filename = media_filename + '.etag' | ||||||
|                     if os.path.isfile(media_tag_filename): |                     if os.path.isfile(media_tag_filename): | ||||||
|                         try: |                         try: | ||||||
|  | @ -18632,10 +18677,14 @@ class PubServer(BaseHTTPRequestHandler): | ||||||
|                             except OSError: |                             except OSError: | ||||||
|                                 print('EX: do_HEAD unable to write ' + |                                 print('EX: do_HEAD unable to write ' + | ||||||
|                                       media_tag_filename) |                                       media_tag_filename) | ||||||
|  |                 else: | ||||||
|  |                     self._404() | ||||||
|  |                     return | ||||||
| 
 | 
 | ||||||
|         media_file_type = media_file_mime_type(check_path) |         media_file_type = media_file_mime_type(check_path) | ||||||
|         self._set_headers_head(media_file_type, file_length, |         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: {}, |     def _receive_new_post_process(self, post_type: str, path: str, headers: {}, | ||||||
|                                   length: int, post_bytes, boundary: str, |                                   length: int, post_bytes, boundary: str, | ||||||
|  |  | ||||||
							
								
								
									
										5
									
								
								maps.py
								
								
								
								
							
							
						
						
									
										5
									
								
								maps.py
								
								
								
								
							|  | @ -194,7 +194,10 @@ def _geocoords_from_wego_link(url: str) -> (int, float, float): | ||||||
|     return zoom, latitude, longitude |     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 |     """Returns geocoordinates from a map link url | ||||||
|     """ |     """ | ||||||
|     if osm_domain in url: |     if osm_domain in url: | ||||||
|  |  | ||||||
							
								
								
									
										24
									
								
								posts.py
								
								
								
								
							
							
						
						
									
										24
									
								
								posts.py
								
								
								
								
							|  | @ -93,6 +93,7 @@ from linked_data_sig import generate_json_signature | ||||||
| from petnames import resolve_petnames | from petnames import resolve_petnames | ||||||
| from video import convert_video_to_note | from video import convert_video_to_note | ||||||
| from context import get_individual_post_context | from context import get_individual_post_context | ||||||
|  | from maps import geocoords_from_map_link | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def is_moderator(base_dir: str, nickname: str) -> bool: | 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 |                 "endTime": end_date_str | ||||||
|             }) |             }) | ||||||
|     if location and not event_uuid: |     if location and not event_uuid: | ||||||
|         tags.append({ |         latitude = longitude = None | ||||||
|             "@context": "https://www.w3.org/ns/activitystreams", |         if '://' in location: | ||||||
|             "type": "Place", |             _, latitude, longitude = \ | ||||||
|             "name": location |                 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 |     return event_date_str | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -2187,9 +2187,8 @@ def individual_post_as_html(signing_priv_key_pem: str, | ||||||
|                 set_map_preferences_url(base_dir, nickname, domain, |                 set_map_preferences_url(base_dir, nickname, domain, | ||||||
|                                         location_domain) |                                         location_domain) | ||||||
|                 # remember the coordinates |                 # remember the coordinates | ||||||
|                 osm_domain = 'openstreetmap.org' |  | ||||||
|                 map_zoom, map_latitude, map_longitude = \ |                 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: |                 if map_zoom and map_latitude and map_longitude: | ||||||
|                     set_map_preferences_coords(base_dir, nickname, domain, |                     set_map_preferences_coords(base_dir, nickname, domain, | ||||||
|                                                map_latitude, map_longitude, |                                                map_latitude, map_longitude, | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue