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 utils import valid_post_date
|
||||
from categories import set_hashtag_category
|
||||
from utils import image_mime_types_dict
|
||||
from utils import resembles_url
|
||||
from utils import get_url_from_post
|
||||
from utils import remove_zero_length_strings
|
||||
|
@ -171,17 +172,7 @@ def _download_newswire_feed_favicon(session, base_dir: str,
|
|||
return False
|
||||
|
||||
# update the favicon url
|
||||
extensions_to_mime = {
|
||||
'ico': 'x-icon',
|
||||
'png': 'png',
|
||||
'jpg': 'jpeg',
|
||||
'jxl': 'jxl',
|
||||
'gif': 'gif',
|
||||
'avif': 'avif',
|
||||
'heic': 'heic',
|
||||
'svg': 'svg+xml',
|
||||
'webp': 'webp'
|
||||
}
|
||||
extensions_to_mime = image_mime_types_dict()
|
||||
for ext, mime_ext in extensions_to_mime.items():
|
||||
if 'image/' + mime_ext in mime_type:
|
||||
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 get_actor_roles_list
|
||||
from media import process_meta_data
|
||||
from utils import get_image_mime_type
|
||||
from utils import get_instance_url
|
||||
from utils import get_url_from_post
|
||||
from utils import date_utcnow
|
||||
|
@ -149,13 +150,7 @@ def set_profile_image(base_dir: str, http_prefix: str,
|
|||
extensions = get_image_extensions()
|
||||
for ext in extensions:
|
||||
if image_filename.endswith('.' + ext):
|
||||
media_type = 'image/' + ext
|
||||
if ext == 'svg':
|
||||
media_type = 'image/' + ext + '+xml'
|
||||
elif ext == 'jpg':
|
||||
media_type = 'image/jpeg'
|
||||
elif ext == 'ico':
|
||||
media_type = 'image/x-icon'
|
||||
media_type = get_image_mime_type(image_filename)
|
||||
icon_filename = icon_filename_base + '.' + ext
|
||||
|
||||
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 is_image_file
|
||||
from utils import binary_is_image
|
||||
from utils import image_mime_types_dict
|
||||
from httpsig import create_signed_header
|
||||
import json
|
||||
from socket import error as SocketError
|
||||
|
@ -752,18 +753,7 @@ def download_image(session, url: str, image_filename: str, debug: bool,
|
|||
return None
|
||||
|
||||
# try different image types
|
||||
image_formats = {
|
||||
'png': 'png',
|
||||
'jpg': 'jpeg',
|
||||
'jpeg': 'jpeg',
|
||||
'jxl': 'jxl',
|
||||
'gif': 'gif',
|
||||
'svg': 'svg+xml',
|
||||
'webp': 'webp',
|
||||
'avif': 'avif',
|
||||
'heic': 'heic',
|
||||
'ico': 'x-icon'
|
||||
}
|
||||
image_formats = image_mime_types_dict()
|
||||
session_headers = None
|
||||
for im_format, mime_type in image_formats.items():
|
||||
if url.endswith('.' + im_format) or \
|
||||
|
@ -871,18 +861,7 @@ def download_image_any_mime_type(session, url: str,
|
|||
if not content_type:
|
||||
return None, None
|
||||
|
||||
image_formats = {
|
||||
'ico': 'x-icon',
|
||||
'png': 'png',
|
||||
'jpg': 'jpeg',
|
||||
'jxl': 'jxl',
|
||||
'jpeg': 'jpeg',
|
||||
'gif': 'gif',
|
||||
'svg': 'svg+xml',
|
||||
'webp': 'webp',
|
||||
'avif': 'avif',
|
||||
'heic': 'heic'
|
||||
}
|
||||
image_formats = image_mime_types_dict()
|
||||
for _, m_type in image_formats.items():
|
||||
if 'image/' + m_type in content_type:
|
||||
mime_type = 'image/' + m_type
|
||||
|
|
13
utils.py
13
utils.py
|
@ -805,12 +805,13 @@ def get_image_extensions() -> []:
|
|||
'svg', 'ico', 'jxl', 'png')
|
||||
|
||||
|
||||
def get_image_mime_type(image_filename: str) -> str:
|
||||
"""Returns the mime type for the given image
|
||||
def image_mime_types_dict() -> {}:
|
||||
"""Returns a dict of image mime types
|
||||
"""
|
||||
extensions_to_mime = {
|
||||
return {
|
||||
'png': 'png',
|
||||
'jpg': 'jpeg',
|
||||
'jpeg': 'jpeg',
|
||||
'jxl': 'jxl',
|
||||
'gif': 'gif',
|
||||
'avif': 'avif',
|
||||
|
@ -819,6 +820,12 @@ def get_image_mime_type(image_filename: str) -> str:
|
|||
'webp': 'webp',
|
||||
'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():
|
||||
if image_filename.endswith('.' + ext):
|
||||
return 'image/' + mime_ext
|
||||
|
|
|
@ -10,6 +10,7 @@ __module_group__ = "Web Interface Columns"
|
|||
import os
|
||||
from content import remove_long_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_base_content_from_post
|
||||
from utils import remove_html
|
||||
|
@ -255,8 +256,7 @@ def _html_newswire(base_dir: str, newswire: {}, nickname: str, moderator: bool,
|
|||
favicon_url = \
|
||||
cached_favicon_filename.replace(base_dir, '')
|
||||
else:
|
||||
extensions = \
|
||||
('png', 'jpg', 'gif', 'avif', 'heic', 'svg', 'webp', 'jxl')
|
||||
extensions = get_image_extensions()
|
||||
for ext in extensions:
|
||||
cached_favicon_filename = \
|
||||
get_fav_filename_from_url(base_dir, favicon_url)
|
||||
|
|
|
@ -12,6 +12,7 @@ from shutil import copyfile
|
|||
from collections import OrderedDict
|
||||
from session import get_json
|
||||
from session import get_json_valid
|
||||
from utils import image_mime_types_dict
|
||||
from utils import get_url_from_post
|
||||
from utils import get_media_url_from_video
|
||||
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
|
||||
|
||||
# try different image types
|
||||
image_formats = {
|
||||
'png': 'png',
|
||||
'jpg': 'jpeg',
|
||||
'jxl': 'jxl',
|
||||
'jpeg': 'jpeg',
|
||||
'gif': 'gif',
|
||||
'svg': 'svg+xml',
|
||||
'webp': 'webp',
|
||||
'avif': 'avif',
|
||||
'heic': 'heic'
|
||||
}
|
||||
image_formats = image_mime_types_dict()
|
||||
avatar_image_filename = None
|
||||
for im_format, mime_type in image_formats.items():
|
||||
if avatar_url.endswith('.' + im_format) or \
|
||||
|
@ -1188,9 +1179,7 @@ def _is_attached_image(attachment_filename: str) -> bool:
|
|||
"""
|
||||
if '.' not in attachment_filename:
|
||||
return False
|
||||
image_ext = (
|
||||
'png', 'jpg', 'jpeg', 'webp', 'avif', 'heic', 'svg', 'gif', 'jxl'
|
||||
)
|
||||
image_ext = get_image_extensions()
|
||||
ext = attachment_filename.split('.')[-1]
|
||||
if ext in image_ext:
|
||||
return True
|
||||
|
|
Loading…
Reference in New Issue