mirror of
https://github.com/TheFunny/TelegramTwitterMediaBot.git
synced 2026-10-06 01:22:16 +00:00
refactor(x-media): drop the per-site fns the Site defaults already cover
twitter, bsky, misskey and bilibili each carried enabled() -> true, media_headers(url) -> None and is_retryable(err) -> the trait's own default, with no caller outside their tests (the adapters never override those methods, so the default was already the production policy). The tests that only restated the default are gone; the two that pin site-specific classes (bsky's MediaPrep, bilibili's risk-control codes) now ask the Site impl, and site/mod.rs keeps one assertion of the shared retry policy. The live verification notes (no Referer needed for hdslb/twimg) survive as comments.
This commit is contained in:
@@ -34,10 +34,6 @@ impl Site for MisskeySite {
|
||||
pub static PATTERN: LazyLock<Regex> =
|
||||
LazyLock::new(|| Regex::new(r"^(?:https?://)?misskey\.io/notes/([\w.\-~]+)").unwrap());
|
||||
|
||||
pub fn enabled() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
pub async fn fetch_from_url(url: &str) -> Result<Fetched, FetchError> {
|
||||
let caps = PATTERN.captures(url).ok_or(FetchError::NotFound)?;
|
||||
let note_id = caps.get(1).ok_or(FetchError::NotFound)?.as_str();
|
||||
@@ -53,17 +49,6 @@ pub fn cache_key(url: &str) -> Option<String> {
|
||||
.map(|caps| format!("misskey:{}", &caps[1]))
|
||||
}
|
||||
|
||||
/// Misskey's fetch-retry policy: transient classes only. Not-found, blocked
|
||||
/// and parse failures are permanent.
|
||||
pub fn is_retryable(err: &FetchError) -> bool {
|
||||
matches!(err, FetchError::Http(_) | FetchError::Transient(_))
|
||||
}
|
||||
|
||||
/// misskey.io media hosts need no extra headers (verified: direct GET works).
|
||||
pub fn media_headers(_url: &str) -> Option<Vec<(&'static str, String)>> {
|
||||
None
|
||||
}
|
||||
|
||||
/// Fetches a note from misskey.io by id. The API answers client failures
|
||||
/// with HTTP 400 + `{"error":{"code":...}}` (NO_SUCH_NOTE → NotFound);
|
||||
/// everything else non-success is transient and retried by [`crate::site::fetch`].
|
||||
|
||||
Reference in New Issue
Block a user