Compare commits

..

No commits in common. "ece6e42b68564476218b44c63ffa8fba35f78405" and "d51ca2cced0ad1c177d6065b9b34ef9a99a81804" have entirely different histories.

3 changed files with 11 additions and 37 deletions

View file

@ -1,7 +1,6 @@
from __future__ import annotations from __future__ import annotations
import datetime import datetime
import json
import logging import logging
import os import os
import pprint import pprint
@ -37,7 +36,6 @@ from discord_rss_bot.hoyolab_api import extract_post_id_from_hoyolab_url
from discord_rss_bot.hoyolab_api import fetch_hoyolab_post from discord_rss_bot.hoyolab_api import fetch_hoyolab_post
from discord_rss_bot.hoyolab_api import is_c3kay_feed from discord_rss_bot.hoyolab_api import is_c3kay_feed
from discord_rss_bot.is_url_valid import is_url_valid from discord_rss_bot.is_url_valid import is_url_valid
from discord_rss_bot.settings import default_custom_embed
from discord_rss_bot.settings import default_custom_message from discord_rss_bot.settings import default_custom_message
from discord_rss_bot.settings import get_reader from discord_rss_bot.settings import get_reader
@ -572,8 +570,5 @@ def create_feed(reader: Reader, feed_url: str, webhook_dropdown: str) -> None:
# This is the default message that will be sent to Discord. # This is the default message that will be sent to Discord.
reader.set_tag(clean_feed_url, "custom_message", default_custom_message) # pyright: ignore[reportArgumentType] reader.set_tag(clean_feed_url, "custom_message", default_custom_message) # pyright: ignore[reportArgumentType]
# Set the default embed tag when creating the feed
reader.set_tag(clean_feed_url, "embed", json.dumps(default_custom_embed))
# Update the full-text search index so our new feed is searchable. # Update the full-text search index so our new feed is searchable.
reader.update_search() reader.update_search()

View file

@ -620,7 +620,7 @@ async def get_embed_page(
@app.post("/embed", response_class=HTMLResponse) @app.post("/embed", response_class=HTMLResponse)
async def post_embed( # noqa: C901 async def post_embed(
feed_url: Annotated[str, Form()], feed_url: Annotated[str, Form()],
reader: Annotated[Reader, Depends(get_reader_dependency)], reader: Annotated[Reader, Depends(get_reader_dependency)],
title: Annotated[str, Form()] = "", title: Annotated[str, Form()] = "",
@ -657,29 +657,16 @@ async def post_embed( # noqa: C901
feed: Feed = reader.get_feed(urllib.parse.unquote(clean_feed_url)) feed: Feed = reader.get_feed(urllib.parse.unquote(clean_feed_url))
custom_embed: CustomEmbed = get_embed(reader, feed) custom_embed: CustomEmbed = get_embed(reader, feed)
# Only overwrite fields that the user provided. This prevents accidental custom_embed.title = title
# clearing of previously saved embed data when the form submits empty custom_embed.description = description
# values for fields the user did not change. custom_embed.color = color
if title: custom_embed.image_url = image_url
custom_embed.title = title custom_embed.thumbnail_url = thumbnail_url
if description: custom_embed.author_name = author_name
custom_embed.description = description custom_embed.author_url = author_url
if color: custom_embed.author_icon_url = author_icon_url
custom_embed.color = color custom_embed.footer_text = footer_text
if image_url: custom_embed.footer_icon_url = footer_icon_url
custom_embed.image_url = image_url
if thumbnail_url:
custom_embed.thumbnail_url = thumbnail_url
if author_name:
custom_embed.author_name = author_name
if author_url:
custom_embed.author_url = author_url
if author_icon_url:
custom_embed.author_icon_url = author_icon_url
if footer_text:
custom_embed.footer_text = footer_text
if footer_icon_url:
custom_embed.footer_icon_url = footer_icon_url
# Save the data. # Save the data.
save_embed(reader, feed, custom_embed) save_embed(reader, feed, custom_embed)

View file

@ -4,14 +4,11 @@ import os
import shutil import shutil
import sys import sys
import tempfile import tempfile
import warnings
from contextlib import suppress from contextlib import suppress
from pathlib import Path from pathlib import Path
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from typing import Any from typing import Any
from bs4 import MarkupResemblesLocatorWarning
if TYPE_CHECKING: if TYPE_CHECKING:
import pytest import pytest
@ -37,11 +34,6 @@ def pytest_sessionstart(session: pytest.Session) -> None:
os.environ["DISCORD_RSS_BOT_DATA_DIR"] = str(worker_data_dir) os.environ["DISCORD_RSS_BOT_DATA_DIR"] = str(worker_data_dir)
# Tests call markdownify which may invoke BeautifulSoup on strings that look
# like URLs; that triggers MarkupResemblesLocatorWarning from bs4. Silence
# that warning during tests to avoid noisy output.
warnings.filterwarnings("ignore", category=MarkupResemblesLocatorWarning)
# If modules were imported before this hook (unlikely), force them to use # If modules were imported before this hook (unlikely), force them to use
# the worker-specific location. # the worker-specific location.
settings_module: Any = sys.modules.get("discord_rss_bot.settings") settings_module: Any = sys.modules.get("discord_rss_bot.settings")