mirror of https://gitlab.com/bashrc2/epicyon
Tidying
parent
dbddbb4119
commit
224135ca37
13
newswire.py
13
newswire.py
|
@ -19,6 +19,7 @@ from datetime import timezone
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from utils import valid_post_date
|
from utils import valid_post_date
|
||||||
from categories import set_hashtag_category
|
from categories import set_hashtag_category
|
||||||
|
from utils import image_mime_types_dict
|
||||||
from utils import resembles_url
|
from utils import resembles_url
|
||||||
from utils import get_url_from_post
|
from utils import get_url_from_post
|
||||||
from utils import remove_zero_length_strings
|
from utils import remove_zero_length_strings
|
||||||
|
@ -171,17 +172,7 @@ def _download_newswire_feed_favicon(session, base_dir: str,
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# update the favicon url
|
# update the favicon url
|
||||||
extensions_to_mime = {
|
extensions_to_mime = image_mime_types_dict()
|
||||||
'ico': 'x-icon',
|
|
||||||
'png': 'png',
|
|
||||||
'jpg': 'jpeg',
|
|
||||||
'jxl': 'jxl',
|
|
||||||
'gif': 'gif',
|
|
||||||
'avif': 'avif',
|
|
||||||
'heic': 'heic',
|
|
||||||
'svg': 'svg+xml',
|
|
||||||
'webp': 'webp'
|
|
||||||
}
|
|
||||||
for ext, mime_ext in extensions_to_mime.items():
|
for ext, mime_ext in extensions_to_mime.items():
|
||||||
if 'image/' + mime_ext in mime_type:
|
if 'image/' + mime_ext in mime_type:
|
||||||
fav_url = fav_url.replace('.ico', '.' + ext)
|
fav_url = fav_url.replace('.ico', '.' + ext)
|
||||||
|
|
|
@ -37,6 +37,7 @@ from roles import set_role
|
||||||
from roles import actor_roles_from_list
|
from roles import actor_roles_from_list
|
||||||
from roles import get_actor_roles_list
|
from roles import get_actor_roles_list
|
||||||
from media import process_meta_data
|
from media import process_meta_data
|
||||||
|
from utils import get_image_mime_type
|
||||||
from utils import get_instance_url
|
from utils import get_instance_url
|
||||||
from utils import get_url_from_post
|
from utils import get_url_from_post
|
||||||
from utils import date_utcnow
|
from utils import date_utcnow
|
||||||
|
@ -149,13 +150,7 @@ def set_profile_image(base_dir: str, http_prefix: str,
|
||||||
extensions = get_image_extensions()
|
extensions = get_image_extensions()
|
||||||
for ext in extensions:
|
for ext in extensions:
|
||||||
if image_filename.endswith('.' + ext):
|
if image_filename.endswith('.' + ext):
|
||||||
media_type = 'image/' + ext
|
media_type = get_image_mime_type(image_filename)
|
||||||
if ext == 'svg':
|
|
||||||
media_type = 'image/' + ext + '+xml'
|
|
||||||
elif ext == 'jpg':
|
|
||||||
media_type = 'image/jpeg'
|
|
||||||
elif ext == 'ico':
|
|
||||||
media_type = 'image/x-icon'
|
|
||||||
icon_filename = icon_filename_base + '.' + ext
|
icon_filename = icon_filename_base + '.' + ext
|
||||||
|
|
||||||
profile_filename = acct_handle_dir(base_dir, handle) + '/' + icon_filename
|
profile_filename = acct_handle_dir(base_dir, handle) + '/' + icon_filename
|
||||||
|
|
27
session.py
27
session.py
|
@ -14,6 +14,7 @@ from utils import acct_dir
|
||||||
from utils import url_permitted
|
from utils import url_permitted
|
||||||
from utils import is_image_file
|
from utils import is_image_file
|
||||||
from utils import binary_is_image
|
from utils import binary_is_image
|
||||||
|
from utils import image_mime_types_dict
|
||||||
from httpsig import create_signed_header
|
from httpsig import create_signed_header
|
||||||
import json
|
import json
|
||||||
from socket import error as SocketError
|
from socket import error as SocketError
|
||||||
|
@ -752,18 +753,7 @@ def download_image(session, url: str, image_filename: str, debug: bool,
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# try different image types
|
# try different image types
|
||||||
image_formats = {
|
image_formats = image_mime_types_dict()
|
||||||
'png': 'png',
|
|
||||||
'jpg': 'jpeg',
|
|
||||||
'jpeg': 'jpeg',
|
|
||||||
'jxl': 'jxl',
|
|
||||||
'gif': 'gif',
|
|
||||||
'svg': 'svg+xml',
|
|
||||||
'webp': 'webp',
|
|
||||||
'avif': 'avif',
|
|
||||||
'heic': 'heic',
|
|
||||||
'ico': 'x-icon'
|
|
||||||
}
|
|
||||||
session_headers = None
|
session_headers = None
|
||||||
for im_format, mime_type in image_formats.items():
|
for im_format, mime_type in image_formats.items():
|
||||||
if url.endswith('.' + im_format) or \
|
if url.endswith('.' + im_format) or \
|
||||||
|
@ -871,18 +861,7 @@ def download_image_any_mime_type(session, url: str,
|
||||||
if not content_type:
|
if not content_type:
|
||||||
return None, None
|
return None, None
|
||||||
|
|
||||||
image_formats = {
|
image_formats = image_mime_types_dict()
|
||||||
'ico': 'x-icon',
|
|
||||||
'png': 'png',
|
|
||||||
'jpg': 'jpeg',
|
|
||||||
'jxl': 'jxl',
|
|
||||||
'jpeg': 'jpeg',
|
|
||||||
'gif': 'gif',
|
|
||||||
'svg': 'svg+xml',
|
|
||||||
'webp': 'webp',
|
|
||||||
'avif': 'avif',
|
|
||||||
'heic': 'heic'
|
|
||||||
}
|
|
||||||
for _, m_type in image_formats.items():
|
for _, m_type in image_formats.items():
|
||||||
if 'image/' + m_type in content_type:
|
if 'image/' + m_type in content_type:
|
||||||
mime_type = 'image/' + m_type
|
mime_type = 'image/' + m_type
|
||||||
|
|
13
utils.py
13
utils.py
|
@ -805,12 +805,13 @@ def get_image_extensions() -> []:
|
||||||
'svg', 'ico', 'jxl', 'png')
|
'svg', 'ico', 'jxl', 'png')
|
||||||
|
|
||||||
|
|
||||||
def get_image_mime_type(image_filename: str) -> str:
|
def image_mime_types_dict() -> {}:
|
||||||
"""Returns the mime type for the given image
|
"""Returns a dict of image mime types
|
||||||
"""
|
"""
|
||||||
extensions_to_mime = {
|
return {
|
||||||
'png': 'png',
|
'png': 'png',
|
||||||
'jpg': 'jpeg',
|
'jpg': 'jpeg',
|
||||||
|
'jpeg': 'jpeg',
|
||||||
'jxl': 'jxl',
|
'jxl': 'jxl',
|
||||||
'gif': 'gif',
|
'gif': 'gif',
|
||||||
'avif': 'avif',
|
'avif': 'avif',
|
||||||
|
@ -819,6 +820,12 @@ def get_image_mime_type(image_filename: str) -> str:
|
||||||
'webp': 'webp',
|
'webp': 'webp',
|
||||||
'ico': 'x-icon'
|
'ico': 'x-icon'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def get_image_mime_type(image_filename: str) -> str:
|
||||||
|
"""Returns the mime type for the given image filename
|
||||||
|
"""
|
||||||
|
extensions_to_mime = image_mime_types_dict()
|
||||||
for ext, mime_ext in extensions_to_mime.items():
|
for ext, mime_ext in extensions_to_mime.items():
|
||||||
if image_filename.endswith('.' + ext):
|
if image_filename.endswith('.' + ext):
|
||||||
return 'image/' + mime_ext
|
return 'image/' + mime_ext
|
||||||
|
|
|
@ -10,6 +10,7 @@ __module_group__ = "Web Interface Columns"
|
||||||
import os
|
import os
|
||||||
from content import remove_long_words
|
from content import remove_long_words
|
||||||
from content import limit_repeated_words
|
from content import limit_repeated_words
|
||||||
|
from utils import get_image_extensions
|
||||||
from utils import get_fav_filename_from_url
|
from utils import get_fav_filename_from_url
|
||||||
from utils import get_base_content_from_post
|
from utils import get_base_content_from_post
|
||||||
from utils import remove_html
|
from utils import remove_html
|
||||||
|
@ -255,8 +256,7 @@ def _html_newswire(base_dir: str, newswire: {}, nickname: str, moderator: bool,
|
||||||
favicon_url = \
|
favicon_url = \
|
||||||
cached_favicon_filename.replace(base_dir, '')
|
cached_favicon_filename.replace(base_dir, '')
|
||||||
else:
|
else:
|
||||||
extensions = \
|
extensions = get_image_extensions()
|
||||||
('png', 'jpg', 'gif', 'avif', 'heic', 'svg', 'webp', 'jxl')
|
|
||||||
for ext in extensions:
|
for ext in extensions:
|
||||||
cached_favicon_filename = \
|
cached_favicon_filename = \
|
||||||
get_fav_filename_from_url(base_dir, favicon_url)
|
get_fav_filename_from_url(base_dir, favicon_url)
|
||||||
|
|
|
@ -12,6 +12,7 @@ from shutil import copyfile
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from session import get_json
|
from session import get_json
|
||||||
from session import get_json_valid
|
from session import get_json_valid
|
||||||
|
from utils import image_mime_types_dict
|
||||||
from utils import get_url_from_post
|
from utils import get_url_from_post
|
||||||
from utils import get_media_url_from_video
|
from utils import get_media_url_from_video
|
||||||
from utils import get_attributed_to
|
from utils import get_attributed_to
|
||||||
|
@ -357,17 +358,7 @@ def update_avatar_image_cache(signing_priv_key_pem: str,
|
||||||
avatar_image_path = base_dir + '/cache/avatars/' + actor_str
|
avatar_image_path = base_dir + '/cache/avatars/' + actor_str
|
||||||
|
|
||||||
# try different image types
|
# try different image types
|
||||||
image_formats = {
|
image_formats = image_mime_types_dict()
|
||||||
'png': 'png',
|
|
||||||
'jpg': 'jpeg',
|
|
||||||
'jxl': 'jxl',
|
|
||||||
'jpeg': 'jpeg',
|
|
||||||
'gif': 'gif',
|
|
||||||
'svg': 'svg+xml',
|
|
||||||
'webp': 'webp',
|
|
||||||
'avif': 'avif',
|
|
||||||
'heic': 'heic'
|
|
||||||
}
|
|
||||||
avatar_image_filename = None
|
avatar_image_filename = None
|
||||||
for im_format, mime_type in image_formats.items():
|
for im_format, mime_type in image_formats.items():
|
||||||
if avatar_url.endswith('.' + im_format) or \
|
if avatar_url.endswith('.' + im_format) or \
|
||||||
|
@ -1188,9 +1179,7 @@ def _is_attached_image(attachment_filename: str) -> bool:
|
||||||
"""
|
"""
|
||||||
if '.' not in attachment_filename:
|
if '.' not in attachment_filename:
|
||||||
return False
|
return False
|
||||||
image_ext = (
|
image_ext = get_image_extensions()
|
||||||
'png', 'jpg', 'jpeg', 'webp', 'avif', 'heic', 'svg', 'gif', 'jxl'
|
|
||||||
)
|
|
||||||
ext = attachment_filename.split('.')[-1]
|
ext = attachment_filename.split('.')[-1]
|
||||||
if ext in image_ext:
|
if ext in image_ext:
|
||||||
return True
|
return True
|
||||||
|
|
Loading…
Reference in New Issue