Refactor author icon handling in YouTube notifications. Updated the logic to strip whitespace from the author icon URL and ensure it starts with a valid HTTP/HTTPS scheme. This change improves the robustness of the embed author icon feature in both the Discord bot and web application.

This commit is contained in:
2026-03-07 00:49:20 +01:00
parent b8ead19360
commit eedc7e4203
2 changed files with 4 additions and 3 deletions
+2 -1
View File
@@ -218,7 +218,8 @@ async def _sendMessage(notification: YouTubeNotification, message: str, video_ur
embed.description = embed_description
author_name = _format_embed_text(notification.embed_author_name, channel_name, video_title, video_url, video_id, thumbnail, published_at, is_short) if notification.embed_author_name else channel_name
author_icon = notification.embed_author_icon if notification.embed_author_icon else "https://www.youtube.com/img/desktop/yt_1200.png"
author_icon_raw = (notification.embed_author_icon or "").strip()
author_icon = author_icon_raw if author_icon_raw.startswith(("http://", "https://")) else "https://www.youtube.com/img/desktop/yt_1200.png"
embed.set_author(name=author_name, icon_url=author_icon)
if notification.embed_thumbnail and thumbnail:
+2 -2
View File
@@ -112,7 +112,7 @@ def addYouTube():
embed_color=embed_color,
embed_footer=request.form.get('embed_footer') or None,
embed_author_name=request.form.get('embed_author_name') or None,
embed_author_icon=request.form.get('embed_author_icon') or None,
embed_author_icon=(request.form.get('embed_author_icon') or '').strip() or None,
embed_thumbnail=request.form.get('embed_thumbnail') == 'on',
embed_image=request.form.get('embed_image') == 'on'
)
@@ -177,7 +177,7 @@ def submitEditYouTube(id):
notification.embed_color = embed_color
notification.embed_footer = request.form.get('embed_footer') or None
notification.embed_author_name = request.form.get('embed_author_name') or None
notification.embed_author_icon = request.form.get('embed_author_icon') or None
notification.embed_author_icon = (request.form.get('embed_author_icon') or '').strip() or None
notification.embed_thumbnail = request.form.get('embed_thumbnail') == 'on'
notification.embed_image = request.form.get('embed_image') == 'on'
db.session.commit()