This commit is contained in:
Simon
2026-04-03 18:01:03 +00:00
parent 543e025dda
commit e680319541
2 changed files with 925 additions and 207 deletions

View File

@@ -11,7 +11,9 @@ use std::time::{Duration, Instant};
use crate::{
DbPool,
api::ClientVersion,
status::{Channel, ChannelGroup, ChannelView, FilterOption, Status, StatusResponse},
status::{
Channel, ChannelGroup, ChannelOption, ChannelView, FilterOption, Status, StatusResponse,
},
uploaders::UploaderProfile,
util::{cache::VideoCache, discord::send_discord_error_report, requester::Requester},
videos::{FlexibleNumber, ServerOptions, VideoItem, VideosRequest},
@@ -756,6 +758,25 @@ fn channel_group_order(group_id: &str) -> usize {
}
}
fn should_hide_status_option(option: &ChannelOption) -> bool {
let id = option.id.trim().to_ascii_lowercase();
let title = option.title.trim().to_ascii_lowercase();
matches!(id.as_str(), "stars" | "networks" | "categories")
|| title.contains("models")
|| title.contains("pornstars")
|| title.contains("genres")
|| title.contains("networks")
|| (id == "filter" && title.contains("tags"))
}
fn sanitize_status_options(options: Vec<ChannelOption>) -> Vec<ChannelOption> {
options
.into_iter()
.filter(|option| !should_hide_status_option(option))
.collect()
}
pub fn decorate_channel(channel: Channel) -> ChannelView {
let metadata = channel_metadata_for(&channel.id);
let runtime_status = current_provider_channel_status(&channel.id);
@@ -770,8 +791,8 @@ pub fn decorate_channel(channel: Channel) -> ChannelView {
premium: channel.premium,
favicon: channel.favicon,
status: runtime_status.unwrap_or(channel.status),
categories: channel.categories,
options: channel.options,
categories: vec![],
options: sanitize_status_options(channel.options),
nsfw: channel.nsfw,
groupKey: metadata.map(|value| value.group_id.to_string()),
sortOrder: None,
@@ -987,6 +1008,79 @@ mod tests {
}
}
#[test]
fn decorate_channel_strips_heavy_status_filters() {
let mut channel = base_channel("status-clean");
channel.categories = vec!["Drama".to_string(), "Action".to_string()];
channel.options = vec![
ChannelOption {
id: "sort".to_string(),
title: "Sort".to_string(),
description: String::new(),
systemImage: "arrow.up.arrow.down".to_string(),
colorName: "blue".to_string(),
options: vec![FilterOption {
id: "new".to_string(),
title: "Newest".to_string(),
}],
multiSelect: false,
},
ChannelOption {
id: "categories".to_string(),
title: "Genres".to_string(),
description: String::new(),
systemImage: "square.grid.2x2".to_string(),
colorName: "orange".to_string(),
options: vec![FilterOption {
id: "drama".to_string(),
title: "Drama".to_string(),
}],
multiSelect: true,
},
ChannelOption {
id: "filter".to_string(),
title: "Tags".to_string(),
description: String::new(),
systemImage: "tag".to_string(),
colorName: "green".to_string(),
options: vec![FilterOption {
id: "tag".to_string(),
title: "Tag".to_string(),
}],
multiSelect: true,
},
ChannelOption {
id: "stars".to_string(),
title: "Models".to_string(),
description: String::new(),
systemImage: "person.2".to_string(),
colorName: "pink".to_string(),
options: vec![FilterOption {
id: "model".to_string(),
title: "Model".to_string(),
}],
multiSelect: true,
},
ChannelOption {
id: "networks".to_string(),
title: "Networks".to_string(),
description: String::new(),
systemImage: "network".to_string(),
colorName: "purple".to_string(),
options: vec![FilterOption {
id: "network".to_string(),
title: "Network".to_string(),
}],
multiSelect: true,
},
];
let decorated = decorate_channel(channel);
assert!(decorated.categories.is_empty());
assert_eq!(decorated.options.len(), 1);
assert_eq!(decorated.options[0].id, "sort");
}
fn test_db_pool() -> DbPool {
let unique = SystemTime::now()
.duration_since(UNIX_EPOCH)

File diff suppressed because it is too large Load Diff