From 58871d8db9096dd8a2b3de95f6c93f2c10feb9b0 Mon Sep 17 00:00:00 2001 From: Simon Date: Thu, 14 Aug 2025 18:54:05 +0000 Subject: [PATCH] updated api for automatically all sites --- Cargo.toml | 3 ++- src/api.rs | 41 +++++++++++++++-------------------------- src/main.rs | 4 ++++ 3 files changed, 21 insertions(+), 27 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 65adfc9..cf5e710 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,4 +18,5 @@ serde_json = "1.0.140" tokio = { version = "1", features = ["full"] } wreq = { version = "5", features = ["full"] } wreq-util = "2" -percent-encoding = "2.1" \ No newline at end of file +percent-encoding = "2.1" +capitalize = "0.3.4" diff --git a/src/api.rs b/src/api.rs index 73c3434..8216ca2 100644 --- a/src/api.rs +++ b/src/api.rs @@ -2,7 +2,9 @@ use ntex::http::header; use ntex::web; use ntex::web::HttpRequest; use std::cmp::Ordering; +use std::fs; use tokio::task; +use capitalize::Capitalize; use crate::providers::all::AllProvider; use crate::providers::hanime::HanimeProvider; @@ -15,6 +17,7 @@ use crate::providers::rule34video::Rule34videoProvider; use crate::providers::spankbang::SpankbangProvider; use crate::util::cache::VideoCache; use crate::{DbPool, providers::*, status::*, videos::*}; +use cute::c; #[derive(Debug)] struct ClientVersion { @@ -436,6 +439,17 @@ async fn status(req: HttpRequest) -> Result { nsfw: true, }); + let files = fs::read_dir("./src/providers").unwrap(); + let providers = files.map(|entry| entry.unwrap().file_name()) + .filter(|name| name.to_str().unwrap().ends_with(".rs")) + .filter(|name| !name.to_str().unwrap().contains("mod.rs") && !name.to_str().unwrap().contains("all.rs")) + .map(|name| name.to_str().unwrap().replace(".rs", "")) + .collect::>(); + let sites = c![FilterOption { + id: x.to_string(), + title: x.capitalize().to_string(), + }, for x in providers.iter()]; + // All status.add_channel(Channel { id: "all".to_string(), @@ -451,32 +465,7 @@ async fn status(req: HttpRequest) -> Result { description: "What Sites to use".to_string(), //"Sort the videos by Date or Name.".to_string(), systemImage: "list.number".to_string(), colorName: "green".to_string(), - options: vec![ - FilterOption { - id: "hanime".to_string(), - title: "Hanime".to_string(), - }, - FilterOption { - id: "perverzija".to_string(), - title: "Perverzija".to_string(), - }, - FilterOption { - id: "pmvhaven".to_string(), - title: "PMVHaven".to_string(), - }, - FilterOption { - id: "pornhub".to_string(), - title: "Pornhub".to_string(), - }, - FilterOption { - id: "redtube".to_string(), - title: "Redtube".to_string(), - }, - FilterOption { - id: "rule34video".to_string(), - title: "Rule34Video".to_string(), - }, - ], + options: sites, multiSelect: true, }], nsfw: true, diff --git a/src/main.rs b/src/main.rs index 185f5db..242f3cb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,6 +7,10 @@ use dotenvy::dotenv; use ntex_files as fs; use ntex::web; + +#[macro_use] +extern crate cute; + mod api; mod db; mod models;