chore(repo): remove dead code and useless tests (#3375)

This commit is contained in:
Hampus authored and GitHub committed 2026-10-10 21:43:29 +02:00
1 parent 7e177a1c90
commit 1cd62eb661
1391 files changed
+783 -120415

No files matched your search

-389
View File
@@ -717,18 +717,6 @@ pub fn normalize_locale(locale: &str) -> String {
locale.replace('-', "_")
}
pub fn build_share_url(slug: &str) -> String {
let trimmed = slug.trim();
if trimmed.is_empty() {
return "https://klipy.com/gifs".to_owned();
}
build_share_url_with_type(KlipyPathType::Gif, trimmed)
}
pub fn extract_slug_from_url(url: &str) -> Option<String> {
parse_klipy_path(url).map(|path| path.slug)
}
pub fn resolve_cache_key(url: &str) -> String {
match parse_klipy_path(url) {
Some(path) => format!("{}:{}", klipy_resource(path.path_type), path.slug),
@@ -923,224 +911,6 @@ mod tests {
);
}
#[test]
fn locale_uses_klipy_supported_form() {
assert_eq!(normalize_locale("en-US"), "en_US");
assert_eq!(normalize_locale("pt-BR"), "pt_BR");
assert_eq!(normalize_locale("zh-CN"), "zh_CN");
assert_eq!(normalize_locale("sv_SE"), "sv_SE");
assert_eq!(normalize_locale("es-419"), "es");
assert_eq!(normalize_locale("es_419"), "es");
assert_eq!(normalize_locale("fr"), "fr");
}
#[test]
fn extracts_klipy_slug_only_from_klipy_hosts() {
assert_eq!(
extract_slug_from_url("https://klipy.com/gifs/funny-123").as_deref(),
Some("funny-123")
);
assert_eq!(
extract_slug_from_url("https://www.klipy.com/clip/abc").as_deref(),
Some("abc")
);
assert_eq!(
extract_slug_from_url("https://notklipy.com/gifs/funny"),
None
);
}
#[test]
fn direct_url_targets_the_items_endpoint() {
let client = KlipyClient::new(MediaProxyUrlBuilder::for_test(
"https://media.example.test",
"secret",
))
.expect("client");
let url = client
.create_direct_url(
"secret/key",
&KlipyPath {
path_type: KlipyPathType::Gif,
slug: "walter blame government-1".to_owned(),
},
)
.expect("direct URL");
assert_eq!(
url.as_str(),
"https://api.klipy.com/api/v1/secret%2Fkey/gifs/items?slugs=walter+blame+government-1"
);
let clip_url = client
.create_direct_url(
"key",
&KlipyPath {
path_type: KlipyPathType::Clip,
slug: "kittens".to_owned(),
},
)
.expect("direct URL");
assert_eq!(
clip_url.as_str(),
"https://api.klipy.com/api/v1/key/clips/items?slugs=kittens"
);
}
#[test]
fn transforms_direct_gif_item_sizes() {
let client = KlipyClient::new(MediaProxyUrlBuilder::for_test(
"https://media.example.test",
"secret",
))
.expect("client");
let input = serde_json::from_value::<KlipyGif>(serde_json::json!({
"id": 5441109273429299_i64,
"slug": "walter-blame-government-1",
"title": "Walter blame government",
"type": "gif",
"file": {
"hd": {
"gif": {"url": "https://static.klipy.com/hd.gif", "width": 498, "height": 420, "size": 1},
"webp": {"url": "https://static.klipy.com/hd.webp", "width": 498, "height": 420, "size": 1},
"webm": {"url": "https://static.klipy.com/hd.webm", "width": 498, "height": 420, "size": 1}
},
"sm": {
"webp": {"url": "https://static.klipy.com/sm.webp", "width": 165, "height": 139, "size": 1}
}
}
}))
.expect("fixture");
let gif = client
.transform_gif_with_path(
input,
Some(&KlipyPath {
path_type: KlipyPathType::Gif,
slug: "walter-blame-government-1".to_owned(),
}),
)
.expect("transformed gif");
assert_eq!(gif.id, "walter-blame-government-1");
assert_eq!(gif.url, "https://klipy.com/gifs/walter-blame-government-1");
assert_eq!(gif.src, "https://static.klipy.com/hd.webm");
assert_eq!((gif.width, gif.height), (498, 420));
assert_eq!(
gif.media.get("webp").map(|format| format.src.as_str()),
Some("https://static.klipy.com/hd.webp")
);
assert_eq!(
gif.media
.get("tinywebp")
.map(|format| (format.width, format.height)),
Some((165, 139))
);
}
#[test]
fn transforms_direct_clip_item_using_file_meta_dimensions() {
let client = KlipyClient::new(MediaProxyUrlBuilder::for_test(
"https://media.example.test",
"secret",
))
.expect("client");
let input = serde_json::from_value::<KlipyGif>(serde_json::json!({
"id": 6641306069493365_i64,
"url": "https://klipy.com/clips/kittens",
"slug": "kittens",
"title": "Kittens",
"type": "clip",
"file": {
"mp4": "https://static.klipy.com/clip.mp4",
"gif": "https://static.klipy.com/clip.gif",
"webp": "https://static.klipy.com/clip.webp"
},
"file_meta": {
"mp4": {"width": 854, "height": 480, "size": 924555},
"gif": {"width": 320, "height": 180, "size": 4117532},
"webp": {"width": 320, "height": 180, "size": 625686}
}
}))
.expect("fixture");
let clip = client
.transform_gif_with_path(
input,
Some(&KlipyPath {
path_type: KlipyPathType::Clip,
slug: "kittens".to_owned(),
}),
)
.expect("transformed clip");
assert_eq!(clip.id, "kittens");
assert_eq!(clip.url, "https://klipy.com/clips/kittens");
assert_eq!(clip.src, "https://static.klipy.com/clip.mp4");
assert_eq!((clip.width, clip.height), (854, 480));
assert_eq!(
clip.media
.get("webp")
.map(|format| (format.src.as_str(), format.width, format.height)),
Some(("https://static.klipy.com/clip.webp", 320, 180))
);
assert!(
clip.media
.get("mp4")
.expect("mp4 format")
.proxy_src
.starts_with("https://media.example.test/external/")
);
}
#[test]
fn direct_response_unwraps_the_items_array() {
let response = serde_json::from_value::<DirectGifResponse>(serde_json::json!({
"result": true,
"data": {
"data": [{
"id": 1_i64,
"slug": "kittens",
"title": "Kittens",
"file": {"mp4": "https://static.klipy.com/clip.mp4"}
}],
"meta": {}
}
}))
.expect("fixture");
let items = response.data.expect("data");
assert_eq!(items.data.len(), 1);
assert_eq!(items.data[0].slug.as_deref(), Some("kittens"));
let empty = serde_json::from_value::<DirectGifResponse>(serde_json::json!({
"result": true,
"data": {"data": [], "meta": {}}
}))
.expect("fixture");
assert!(empty.data.expect("data").data.is_empty());
}
#[test]
fn build_share_url_uses_gifs_path() {
assert_eq!(build_share_url("hello"), "https://klipy.com/gifs/hello");
assert_eq!(build_share_url(" "), "https://klipy.com/gifs");
assert_eq!(
build_share_url_with_type(KlipyPathType::Clip, "hello"),
"https://klipy.com/clips/hello"
);
}
#[test]
fn stringifies_numeric_klipy_ids() {
assert_eq!(
klipy_id_as_string(&serde_json::json!(2484942301552561_i64)).as_deref(),
Some("2484942301552561")
);
assert_eq!(
klipy_id_as_string(&serde_json::json!(" abc ")).as_deref(),
Some("abc")
);
assert_eq!(klipy_id_as_string(&serde_json::json!(" ")), None);
}
#[test]
fn resolve_cache_key_ignores_everything_but_the_klipy_path() {
assert_eq!(
@@ -1306,163 +1076,4 @@ mod tests {
assert_eq!(gif.media["webm"].src, "https://static.klipy.com/hd.webm");
assert_eq!(gif.src, gif.media["webm"].src);
}
#[test]
fn keeps_medium_variants_from_the_v2_media_formats_payload() {
let client = KlipyClient::new(MediaProxyUrlBuilder::for_test(
"https://media.example.test",
"secret",
))
.expect("client");
let input = serde_json::from_value::<KlipyGif>(serde_json::json!({
"id": "medium-variants",
"title": "Medium Variants",
"itemurl": "https://klipy.com/gifs/medium-variants",
"media_formats": {
"webp": {"url": "https://static.klipy.com/m.webp", "dims": [498, 327]},
"mediumwebm": {"url": "https://static.klipy.com/m-medium.webm", "dims": [640, 420]},
"mediummp4": {"url": "https://static.klipy.com/m-medium.mp4", "dims": [640, 420]},
"mediumwebp": {"url": "https://static.klipy.com/m-medium.webp", "dims": [640, 420]},
"tinywebp": {"url": "https://static.klipy.com/m-tiny.webp", "dims": [220, 144]},
"nanowebp": {"url": "https://static.klipy.com/m-nano.webp", "dims": [137, 90]}
}
}))
.expect("fixture");
let gif = client.transform_gif(input).expect("transformed gif");
for format in [
"mediumwebm",
"mediummp4",
"mediumwebp",
"tinywebp",
"nanowebp",
] {
assert!(gif.media.contains_key(format), "missing {format}");
}
assert_eq!(
gif.media.get("mediumwebm").map(|format| (
format.src.as_str(),
format.width,
format.height
)),
Some(("https://static.klipy.com/m-medium.webm", 640, 420))
);
}
#[test]
fn transforms_v2_media_formats_into_animated_variants() {
let client = KlipyClient::new(MediaProxyUrlBuilder::for_test(
"https://media.example.test",
"secret",
))
.expect("client");
let input = serde_json::from_value::<KlipyGif>(serde_json::json!({
"id": "1373787462859498",
"title": "Move Faster",
"itemurl": "https://klipy.com/gifs/move-faster",
"media_formats": {
"webp": {
"url": "https://static.klipy.com/media/move.webp",
"dims": [498, 327]
},
"gif": {
"url": "https://static.klipy.com/media/move.gif",
"dims": [498, 326]
},
"mediumgif": {
"url": "https://static.klipy.com/media/move-medium.gif",
"dims": [640, 420]
},
"tinygif": {
"url": "https://static.klipy.com/media/move-tiny.gif",
"dims": [220, 144]
},
"nanogif": {
"url": "https://static.klipy.com/media/move-nano.gif",
"dims": [137, 90]
},
"webm": {
"url": "https://static.klipy.com/media/move.webm",
"dims": [640, 420]
},
"tinywebm": {
"url": "https://static.klipy.com/media/move-tiny.webm",
"dims": [320, 210]
},
"mp4": {
"url": "https://static.klipy.com/media/move.mp4",
"dims": [640, 420]
},
"preview": {
"url": "https://static.klipy.com/media/move.jpg",
"dims": [220, 144]
}
}
}))
.expect("fixture");
let gif = client.transform_gif(input).expect("transformed gif");
assert_eq!(gif.id, "move-faster");
assert_eq!(gif.url, "https://klipy.com/gifs/move-faster");
assert_eq!(gif.src, "https://static.klipy.com/media/move.webm");
assert_eq!(gif.width, 640);
assert_eq!(gif.height, 420);
assert_eq!(
gif.media.get("webp").map(|format| format.src.as_str()),
Some("https://static.klipy.com/media/move.webp")
);
assert_eq!(
gif.media.get("gif").map(|format| format.src.as_str()),
Some("https://static.klipy.com/media/move.gif")
);
assert_eq!(
gif.media
.get("tinygif")
.map(|format| (format.width, format.height)),
Some((220, 144))
);
assert!(gif.media.contains_key("mediumgif"));
assert!(gif.media.contains_key("nanogif"));
assert!(gif.media.contains_key("tinywebm"));
assert!(!gif.media.contains_key("preview"));
assert!(
gif.media
.get("webp")
.expect("webp format")
.proxy_src
.starts_with("https://media.example.test/external/")
);
}
#[test]
fn media_formats_without_video_choose_webp_as_top_level() {
let client = KlipyClient::new(MediaProxyUrlBuilder::for_test(
"https://media.example.test",
"secret",
))
.expect("client");
let input = serde_json::from_value::<KlipyGif>(serde_json::json!({
"id": "cat-cone",
"title": "Cat Cone",
"media_formats": {
"webp": {
"url": "https://static.klipy.com/media/cat.webp",
"dims": [320, 180]
},
"gif": {
"url": "https://static.klipy.com/media/cat.gif",
"dims": [320, 180]
}
}
}))
.expect("fixture");
let gif = client.transform_gif(input).expect("transformed gif");
assert_eq!(gif.src, "https://static.klipy.com/media/cat.webp");
assert_eq!(gif.proxy_src, gif.media["webp"].proxy_src);
assert_eq!(gif.media["gif"].width, 320);
}
}
-168
View File
@@ -73,57 +73,6 @@ impl MediaProxyUrlBuilder {
#[cfg(test)]
mod tests {
use super::*;
use std::sync::Mutex;
static ENV_LOCK: Mutex<()> = Mutex::new(());
fn with_media_proxy_env(
vars: &[(&str, Option<&str>)],
test: impl FnOnce() -> anyhow::Result<()>,
) -> anyhow::Result<()> {
let _guard = ENV_LOCK.lock().unwrap();
let keys = [
"FLUXER_MEDIA_PROXY_PUBLIC_ENDPOINT",
"FLUXER_MEDIA_ENDPOINT",
"FLUXER_MEDIA_PROXY_ENDPOINT",
"FLUXER_MEDIA_PROXY_SECRET_KEY",
"FLUXER_BASE_DOMAIN",
"FLUXER_PUBLIC_PORT",
"FLUXER_PUBLIC_ORIGIN",
];
let saved = keys
.iter()
.map(|key| (*key, std::env::var(key).ok()))
.collect::<Vec<_>>();
for key in keys {
unsafe {
std::env::remove_var(key);
}
}
for (key, value) in vars {
if let Some(value) = value {
unsafe {
std::env::set_var(key, value);
}
}
}
let result = test();
for (key, value) in saved {
match value {
Some(value) => unsafe {
std::env::set_var(key, value);
},
None => unsafe {
std::env::remove_var(key);
},
}
}
result
}
#[test]
fn external_proxy_url_builds_v2_signed_url() {
@@ -144,121 +93,4 @@ mod tests {
Some("https://media.example.test/external/existing".to_owned())
);
}
#[test]
fn from_env_uses_public_endpoint_when_internal_proxy_endpoint_is_set() -> anyhow::Result<()> {
with_media_proxy_env(
&[
(
"FLUXER_MEDIA_PROXY_PUBLIC_ENDPOINT",
Some("https://media.example.test/"),
),
(
"FLUXER_MEDIA_PROXY_ENDPOINT",
Some("http://media-proxy:8080"),
),
("FLUXER_MEDIA_PROXY_SECRET_KEY", Some("secret")),
],
|| {
let builder = MediaProxyUrlBuilder::from_env()?;
assert_eq!(builder.endpoint, "https://media.example.test");
Ok(())
},
)
}
#[test]
fn from_env_accepts_legacy_public_media_endpoint() -> anyhow::Result<()> {
with_media_proxy_env(
&[
(
"FLUXER_MEDIA_ENDPOINT",
Some("https://media.example.test/media"),
),
(
"FLUXER_MEDIA_PROXY_ENDPOINT",
Some("http://media-proxy:8080"),
),
("FLUXER_MEDIA_PROXY_SECRET_KEY", Some("secret")),
],
|| {
let builder = MediaProxyUrlBuilder::from_env()?;
assert_eq!(builder.endpoint, "https://media.example.test/media");
Ok(())
},
)
}
#[test]
fn from_env_inserts_a_non_default_public_port() -> anyhow::Result<()> {
with_media_proxy_env(
&[
(
"FLUXER_MEDIA_PROXY_PUBLIC_ENDPOINT",
Some("http://fluxer.example/media"),
),
("FLUXER_MEDIA_PROXY_SECRET_KEY", Some("secret")),
("FLUXER_BASE_DOMAIN", Some("fluxer.example")),
("FLUXER_PUBLIC_PORT", Some("19080")),
],
|| {
let builder = MediaProxyUrlBuilder::from_env()?;
assert_eq!(builder.endpoint, "http://fluxer.example:19080/media");
assert_eq!(builder.endpoint_host.as_deref(), Some("fluxer.example"));
assert!(
builder
.external_proxy_url("https://img.example.net/a.webp")
.expect("proxy url")
.starts_with("http://fluxer.example:19080/media/external/")
);
Ok(())
},
)
}
#[test]
fn from_env_leaves_a_default_public_port_alone() -> anyhow::Result<()> {
with_media_proxy_env(
&[
(
"FLUXER_MEDIA_PROXY_PUBLIC_ENDPOINT",
Some("https://fluxer.example/media"),
),
("FLUXER_MEDIA_PROXY_SECRET_KEY", Some("secret")),
("FLUXER_BASE_DOMAIN", Some("fluxer.example")),
("FLUXER_PUBLIC_PORT", Some("443")),
],
|| {
let builder = MediaProxyUrlBuilder::from_env()?;
assert_eq!(builder.endpoint, "https://fluxer.example/media");
Ok(())
},
)
}
#[test]
fn from_env_rejects_internal_proxy_endpoint_without_public_endpoint() -> anyhow::Result<()> {
with_media_proxy_env(
&[
(
"FLUXER_MEDIA_PROXY_ENDPOINT",
Some("http://media-proxy:8080"),
),
("FLUXER_MEDIA_PROXY_SECRET_KEY", Some("secret")),
],
|| {
let err = MediaProxyUrlBuilder::from_env()
.err()
.expect("internal endpoint must not be accepted as public endpoint")
.to_string();
assert!(err.contains("FLUXER_MEDIA_PROXY_PUBLIC_ENDPOINT"));
Ok(())
},
)
}
}
+1 -5
View File
@@ -59,9 +59,7 @@ fn request_l1_key(req: &GifRequest) -> Option<String> {
| GifRequest::GetFeatured { .. }
| GifRequest::GetTrendingGifs { .. }
| GifRequest::Suggest { .. }
| GifRequest::ResolveByUrl { .. }
| GifRequest::BuildShareUrl { .. }
| GifRequest::ExtractSlugFromUrl { .. } => request_key(req),
| GifRequest::ResolveByUrl { .. } => request_key(req),
GifRequest::IsAvailable { .. } | GifRequest::RegisterShare { .. } => None,
}
}
@@ -83,8 +81,6 @@ fn request_key(req: &GifRequest) -> Option<String> {
GifRequest::ResolveByUrl { url, .. } => {
Some(format!("resolve:{}", crate::klipy::resolve_cache_key(url)))
}
GifRequest::BuildShareUrl { slug } => Some(format!("share-url:{slug}")),
GifRequest::ExtractSlugFromUrl { url } => Some(format!("extract-slug:{url}")),
}
}
+1 -7
View File
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
use crate::klipy::{KlipyClient, build_share_url, extract_slug_from_url, resolve_cache_key};
use crate::klipy::{KlipyClient, resolve_cache_key};
use crate::media_proxy::MediaProxyUrlBuilder;
use crate::types::{GifCategoryTag, GifItem, GifMediaFormat, GifRequest, GifServiceResponse};
use fluxer_svc::config::optional_env;
@@ -862,12 +862,6 @@ impl ShardService for GifsShard {
self.handle_resolve_by_url(api_key, url, locale, country)
.await?
}
GifRequest::BuildShareUrl { slug } => GifServiceResponse::ShareUrl {
url: build_share_url(&slug),
},
GifRequest::ExtractSlugFromUrl { url } => GifServiceResponse::ExtractedSlug {
slug: extract_slug_from_url(&url),
},
};
Ok(response)
}
-12
View File
@@ -44,12 +44,6 @@ pub enum GifRequest {
locale: String,
country: String,
},
BuildShareUrl {
slug: String,
},
ExtractSlugFromUrl {
url: String,
},
}
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -68,12 +62,6 @@ pub enum GifServiceResponse {
Resolved {
gif: Arc<Option<GifItem>>,
},
ShareUrl {
url: String,
},
ExtractedSlug {
slug: Option<String>,
},
Failed {
message: String,
},