cacheDuration

This commit is contained in:
Simon
2025-09-03 14:50:45 +00:00
parent c7e67a3cba
commit 8a57d0c2bf
2 changed files with 152 additions and 106 deletions

View File

@@ -1,10 +1,10 @@
use capitalize::Capitalize;
use ntex::http::header; use ntex::http::header;
use ntex::web; use ntex::web;
use ntex::web::HttpRequest; use ntex::web::HttpRequest;
use std::cmp::Ordering; use std::cmp::Ordering;
use std::fs; use std::fs;
use tokio::task; use tokio::task;
use capitalize::Capitalize;
use crate::providers::all::AllProvider; use crate::providers::all::AllProvider;
use crate::providers::hanime::HanimeProvider; use crate::providers::hanime::HanimeProvider;
@@ -17,7 +17,7 @@ use crate::providers::rule34video::Rule34videoProvider;
// use crate::providers::spankbang::SpankbangProvider; // use crate::providers::spankbang::SpankbangProvider;
use crate::util::cache::VideoCache; use crate::util::cache::VideoCache;
use crate::util::requester::Requester; use crate::util::requester::Requester;
use crate::{db, providers::*, status::*, videos::*, DbPool}; use crate::{DbPool, db, providers::*, status::*, videos::*};
use cute::c; use cute::c;
#[derive(Debug)] #[derive(Debug)]
@@ -160,6 +160,7 @@ async fn status(req: HttpRequest) -> Result<impl web::Responder, web::Error> {
multiSelect: false, multiSelect: false,
}], }],
nsfw: true, nsfw: true,
cacheDuration: 1800,
}); });
if clientversion >= ClientVersion::new(22, 101, "22e".to_string()) { if clientversion >= ClientVersion::new(22, 101, "22e".to_string()) {
// pmvhaven // pmvhaven
@@ -171,67 +172,70 @@ async fn status(req: HttpRequest) -> Result<impl web::Responder, web::Error> {
favicon: "https://www.google.com/s2/favicons?sz=64&domain=pmvhaven.com".to_string(), favicon: "https://www.google.com/s2/favicons?sz=64&domain=pmvhaven.com".to_string(),
status: "active".to_string(), status: "active".to_string(),
categories: vec![], categories: vec![],
options: vec![ChannelOption { options: vec![
id: "category".to_string(), ChannelOption {
title: "Category".to_string(), id: "category".to_string(),
description: "Category of PMV Video get".to_string(), //"Sort the videos by Date or Name.".to_string(), title: "Category".to_string(),
systemImage: "folder".to_string(), description: "Category of PMV Video get".to_string(), //"Sort the videos by Date or Name.".to_string(),
colorName: "yellow".to_string(), systemImage: "folder".to_string(),
options: vec![ colorName: "yellow".to_string(),
FilterOption { options: vec![
id: "all".to_string(), FilterOption {
title: "All".to_string(), id: "all".to_string(),
}, title: "All".to_string(),
FilterOption { },
id: "pmv".to_string(), FilterOption {
title: "PMV".to_string(), id: "pmv".to_string(),
}, title: "PMV".to_string(),
FilterOption { },
id: "hmv".to_string(), FilterOption {
title: "HMV".to_string(), id: "hmv".to_string(),
}, title: "HMV".to_string(),
FilterOption { },
id: "tiktok".to_string(), FilterOption {
title: "Tiktok".to_string(), id: "tiktok".to_string(),
}, title: "Tiktok".to_string(),
FilterOption { },
id: "koreanbj".to_string(), FilterOption {
title: "KoreanBJ".to_string(), id: "koreanbj".to_string(),
}, title: "KoreanBJ".to_string(),
FilterOption { },
id: "hypno".to_string(), FilterOption {
title: "Hypno".to_string(), id: "hypno".to_string(),
}, title: "Hypno".to_string(),
FilterOption { },
id: "other".to_string(), FilterOption {
title: "Other".to_string(), id: "other".to_string(),
}, title: "Other".to_string(),
], },
multiSelect: false, ],
}, multiSelect: false,
ChannelOption { },
id: "sort".to_string(), ChannelOption {
title: "Filter".to_string(), id: "sort".to_string(),
description: "Filter PMV Videos".to_string(), title: "Filter".to_string(),
systemImage: "list.number".to_string(), description: "Filter PMV Videos".to_string(),
colorName: "blue".to_string(), systemImage: "list.number".to_string(),
options: vec![ colorName: "blue".to_string(),
FilterOption { options: vec![
id: "Newest".to_string(), FilterOption {
title: "Newest".to_string(), id: "Newest".to_string(),
}, title: "Newest".to_string(),
FilterOption { },
id: "Top Rated".to_string(), FilterOption {
title: "Top Rated".to_string(), id: "Top Rated".to_string(),
}, title: "Top Rated".to_string(),
FilterOption { },
id: "Most Viewed".to_string(), FilterOption {
title: "Most Viewed".to_string(), id: "Most Viewed".to_string(),
} title: "Most Viewed".to_string(),
], },
multiSelect: false, ],
}], multiSelect: false,
},
],
nsfw: true, nsfw: true,
cacheDuration: 1800,
}); });
} }
if clientversion >= ClientVersion::new(22, 97, "22a".to_string()) { if clientversion >= ClientVersion::new(22, 97, "22a".to_string()) {
@@ -302,6 +306,7 @@ async fn status(req: HttpRequest) -> Result<impl web::Responder, web::Error> {
// }, // },
], ],
nsfw: true, nsfw: true,
cacheDuration: 1800,
}); });
} }
@@ -364,6 +369,7 @@ async fn status(req: HttpRequest) -> Result<impl web::Responder, web::Error> {
multiSelect: false, multiSelect: false,
}], }],
nsfw: true, nsfw: true,
cacheDuration: 1800,
}); });
// status.add_channel(Channel { // status.add_channel(Channel {
@@ -397,6 +403,7 @@ async fn status(req: HttpRequest) -> Result<impl web::Responder, web::Error> {
// multiSelect: false, // multiSelect: false,
// }], // }],
// nsfw: true, // nsfw: true,
//cacheDuration: 1800,
// }); // });
status.add_channel(Channel { status.add_channel(Channel {
@@ -438,12 +445,16 @@ async fn status(req: HttpRequest) -> Result<impl web::Responder, web::Error> {
multiSelect: false, multiSelect: false,
}], }],
nsfw: true, nsfw: true,
cacheDuration: 1800,
}); });
let files = fs::read_dir("./src/providers").unwrap(); let files = fs::read_dir("./src/providers").unwrap();
let providers = files.map(|entry| entry.unwrap().file_name()) let providers = files
.map(|entry| entry.unwrap().file_name())
.filter(|name| name.to_str().unwrap().ends_with(".rs")) .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")) .filter(|name| {
!name.to_str().unwrap().contains("mod.rs") && !name.to_str().unwrap().contains("all.rs")
})
.map(|name| name.to_str().unwrap().replace(".rs", "")) .map(|name| name.to_str().unwrap().replace(".rs", ""))
.collect::<Vec<String>>(); .collect::<Vec<String>>();
let sites = c![FilterOption { let sites = c![FilterOption {
@@ -470,6 +481,7 @@ async fn status(req: HttpRequest) -> Result<impl web::Responder, web::Error> {
multiSelect: true, multiSelect: true,
}], }],
nsfw: true, nsfw: true,
cacheDuration: 1800,
}); });
// Redtube // Redtube
@@ -483,6 +495,7 @@ async fn status(req: HttpRequest) -> Result<impl web::Responder, web::Error> {
categories: vec![], categories: vec![],
options: vec![], options: vec![],
nsfw: true, nsfw: true,
cacheDuration: 1800,
}); });
// ok.porn // ok.porn
@@ -517,6 +530,7 @@ async fn status(req: HttpRequest) -> Result<impl web::Responder, web::Error> {
multiSelect: false, multiSelect: false,
}], }],
nsfw: true, nsfw: true,
cacheDuration: 1800,
}); });
// pornhat // pornhat
@@ -551,6 +565,7 @@ async fn status(req: HttpRequest) -> Result<impl web::Responder, web::Error> {
multiSelect: false, multiSelect: false,
}], }],
nsfw: true, nsfw: true,
cacheDuration: 1800,
}); });
//perfectgirls //perfectgirls
@@ -585,6 +600,7 @@ async fn status(req: HttpRequest) -> Result<impl web::Responder, web::Error> {
multiSelect: false, multiSelect: false,
}], }],
nsfw: true, nsfw: true,
cacheDuration: 1800,
}); });
// okxxx // okxxx
@@ -619,6 +635,7 @@ async fn status(req: HttpRequest) -> Result<impl web::Responder, web::Error> {
multiSelect: false, multiSelect: false,
}], }],
nsfw: true, nsfw: true,
cacheDuration: 1800,
}); });
// homoxxx // homoxxx
@@ -653,6 +670,7 @@ async fn status(req: HttpRequest) -> Result<impl web::Responder, web::Error> {
multiSelect: false, multiSelect: false,
}], }],
nsfw: true, nsfw: true,
cacheDuration: 1800,
}); });
// // hentaimoon // // hentaimoon
@@ -687,9 +705,10 @@ async fn status(req: HttpRequest) -> Result<impl web::Responder, web::Error> {
// multiSelect: false, // multiSelect: false,
// }], // }],
// nsfw: true, // nsfw: true,
// cacheDuration: 1800,
// }); // });
// xxthots // xxthots
status.add_channel(Channel { status.add_channel(Channel {
id: "xxthots".to_string(), id: "xxthots".to_string(),
name: "XXTHOTS".to_string(), name: "XXTHOTS".to_string(),
@@ -721,6 +740,7 @@ async fn status(req: HttpRequest) -> Result<impl web::Responder, web::Error> {
multiSelect: false, multiSelect: false,
}], }],
nsfw: true, nsfw: true,
cacheDuration: 1800,
}); });
// porn00 // porn00
@@ -755,6 +775,7 @@ async fn status(req: HttpRequest) -> Result<impl web::Responder, web::Error> {
multiSelect: false, multiSelect: false,
}], }],
nsfw: true, nsfw: true,
cacheDuration: 1800,
}); });
// freshporno // freshporno
@@ -789,9 +810,10 @@ async fn status(req: HttpRequest) -> Result<impl web::Responder, web::Error> {
multiSelect: false, multiSelect: false,
}], }],
nsfw: true, nsfw: true,
cacheDuration: 1800,
}); });
// porn00 // porn00
// status.add_channel(Channel { // status.add_channel(Channel {
// id: "noodlemagazine".to_string(), // id: "noodlemagazine".to_string(),
// name: "Noodlemagazine".to_string(), // name: "Noodlemagazine".to_string(),
@@ -802,6 +824,7 @@ async fn status(req: HttpRequest) -> Result<impl web::Responder, web::Error> {
// categories: vec![], // categories: vec![],
// options: vec![], // options: vec![],
// nsfw: true, // nsfw: true,
// cacheDuration: 1800,
// }); // });
//missav //missav
@@ -846,9 +869,9 @@ async fn status(req: HttpRequest) -> Result<impl web::Responder, web::Error> {
title: "Total Views".to_string(), title: "Total Views".to_string(),
}, },
], ],
multiSelect: false, multiSelect: false,
}, },
ChannelOption { ChannelOption {
id: "filter".to_string(), id: "filter".to_string(),
title: "Filter".to_string(), title: "Filter".to_string(),
description: "Filter the Videos".to_string(), //"Sort the videos by Date or Name.".to_string(), description: "Filter the Videos".to_string(), //"Sort the videos by Date or Name.".to_string(),
@@ -872,9 +895,9 @@ async fn status(req: HttpRequest) -> Result<impl web::Responder, web::Error> {
title: "English subtitle".to_string(), title: "English subtitle".to_string(),
}, },
], ],
multiSelect: false, multiSelect: false,
}, },
ChannelOption { ChannelOption {
id: "language".to_string(), id: "language".to_string(),
title: "Language".to_string(), title: "Language".to_string(),
description: "What Language to fetch".to_string(), //"Sort the videos by Date or Name.".to_string(), description: "What Language to fetch".to_string(), //"Sort the videos by Date or Name.".to_string(),
@@ -930,10 +953,11 @@ async fn status(req: HttpRequest) -> Result<impl web::Responder, web::Error> {
title: "Português".to_string(), title: "Português".to_string(),
}, },
], ],
multiSelect: false, multiSelect: false,
} },
], ],
nsfw: true, nsfw: true,
cacheDuration: 1800,
}); });
//sxyprn //sxyprn
@@ -970,9 +994,9 @@ async fn status(req: HttpRequest) -> Result<impl web::Responder, web::Error> {
title: "Orgasmic".to_string(), title: "Orgasmic".to_string(),
}, },
], ],
multiSelect: false, multiSelect: false,
}, },
ChannelOption { ChannelOption {
id: "filter".to_string(), id: "filter".to_string(),
title: "Filter".to_string(), title: "Filter".to_string(),
description: "Filter the Videos".to_string(), //"Sort the videos by Date or Name.".to_string(), description: "Filter the Videos".to_string(), //"Sort the videos by Date or Name.".to_string(),
@@ -992,10 +1016,11 @@ async fn status(req: HttpRequest) -> Result<impl web::Responder, web::Error> {
title: "All".to_string(), title: "All".to_string(),
}, },
], ],
multiSelect: false, multiSelect: false,
}, },
], ],
nsfw: true, nsfw: true,
cacheDuration: 1800,
}); });
status.iconUrl = format!("http://{}/favicon.ico", host).to_string(); status.iconUrl = format!("http://{}/favicon.ico", host).to_string();
@@ -1011,8 +1036,11 @@ async fn videos_post(
let requester = requester.get_ref().clone(); let requester = requester.get_ref().clone();
let mut conn = pool.get().expect("couldn't get db connection from pool"); let mut conn = pool.get().expect("couldn't get db connection from pool");
// Ensure "videos" table exists with two string columns // Ensure "videos" table exists with two string columns
if !(db::has_table(&mut conn, "videos").unwrap()){ if !(db::has_table(&mut conn, "videos").unwrap()) {
let _ = db::create_table(&mut conn, "CREATE TABLE videos (id TEXT NOT NULL, url TEXT NOT NULL);"); let _ = db::create_table(
&mut conn,
"CREATE TABLE videos (id TEXT NOT NULL, url TEXT NOT NULL);",
);
} }
let mut videos = Videos { let mut videos = Videos {
@@ -1058,22 +1086,21 @@ async fn videos_post(
.as_deref() .as_deref()
.unwrap_or("all") .unwrap_or("all")
.to_string(); .to_string();
let sites = video_request let sites = video_request.sites.as_deref().unwrap_or("").to_string();
.sites let filter = video_request.filter.as_deref().unwrap_or("new").to_string();
.as_deref()
.unwrap_or("")
.to_string();
let filter = video_request
.filter
.as_deref()
.unwrap_or("new")
.to_string();
let language = video_request let language = video_request
.language .language
.as_deref() .as_deref()
.unwrap_or("en") .unwrap_or("en")
.to_string(); .to_string();
let options = ServerOptions { featured: Some(featured), category: Some(category), sites: Some(sites), filter: Some(filter), language: Some(language), requester: Some(requester) }; let options = ServerOptions {
featured: Some(featured),
category: Some(category),
sites: Some(sites),
filter: Some(filter),
language: Some(language),
requester: Some(requester),
};
let video_items = provider let video_items = provider
.get_videos( .get_videos(
cache.get_ref().clone(), cache.get_ref().clone(),
@@ -1082,7 +1109,7 @@ async fn videos_post(
query.clone(), query.clone(),
page.to_string(), page.to_string(),
perPage.to_string(), perPage.to_string(),
options.clone() options.clone(),
) )
.await; .await;
videos.items = video_items.clone(); videos.items = video_items.clone();
@@ -1114,7 +1141,7 @@ async fn videos_post(
query_clone, query_clone,
next_page.to_string(), next_page.to_string(),
per_page_clone, per_page_clone,
options_clone options_clone,
) )
.await; .await;
}); });
@@ -1133,17 +1160,35 @@ pub fn get_provider(channel: &str) -> Option<AnyProvider> {
"rule34video" => Some(AnyProvider::Rule34video(Rule34videoProvider::new())), "rule34video" => Some(AnyProvider::Rule34video(Rule34videoProvider::new())),
"redtube" => Some(AnyProvider::Redtube(RedtubeProvider::new())), "redtube" => Some(AnyProvider::Redtube(RedtubeProvider::new())),
"okporn" => Some(AnyProvider::Okporn(OkpornProvider::new())), "okporn" => Some(AnyProvider::Okporn(OkpornProvider::new())),
"pornhat" => Some(AnyProvider::Pornhat(crate::providers::pornhat::PornhatProvider::new())), "pornhat" => Some(AnyProvider::Pornhat(
"perfectgirls" => Some(AnyProvider::Perfectgirls(crate::providers::perfectgirls::PerfectgirlsProvider::new())), crate::providers::pornhat::PornhatProvider::new(),
"okxxx" => Some(AnyProvider::Okxxx(crate::providers::okxxx::OkxxxProvider::new())), )),
"homoxxx" => Some(AnyProvider::Homoxxx(crate::providers::homoxxx::HomoxxxProvider::new())), "perfectgirls" => Some(AnyProvider::Perfectgirls(
crate::providers::perfectgirls::PerfectgirlsProvider::new(),
)),
"okxxx" => Some(AnyProvider::Okxxx(
crate::providers::okxxx::OkxxxProvider::new(),
)),
"homoxxx" => Some(AnyProvider::Homoxxx(
crate::providers::homoxxx::HomoxxxProvider::new(),
)),
// "hentaimoon" => Some(AnyProvider::Hentaimoon(crate::providers::hentaimoon::HentaimoonProvider::new())), // "hentaimoon" => Some(AnyProvider::Hentaimoon(crate::providers::hentaimoon::HentaimoonProvider::new())),
"missav" => Some(AnyProvider::Missav(crate::providers::missav::MissavProvider::new())), "missav" => Some(AnyProvider::Missav(
"xxthots" => Some(AnyProvider::Xxthots(crate::providers::xxthots::XxthotsProvider::new())), crate::providers::missav::MissavProvider::new(),
"sxyprn" => Some(AnyProvider::Sxyprn(crate::providers::sxyprn::SxyprnProvider::new())), )),
"porn00" => Some(AnyProvider::Porn00(crate::providers::porn00::Porn00Provider::new())), "xxthots" => Some(AnyProvider::Xxthots(
crate::providers::xxthots::XxthotsProvider::new(),
)),
"sxyprn" => Some(AnyProvider::Sxyprn(
crate::providers::sxyprn::SxyprnProvider::new(),
)),
"porn00" => Some(AnyProvider::Porn00(
crate::providers::porn00::Porn00Provider::new(),
)),
// "noodlemagazine" => Some(AnyProvider::Noodlemagazine(crate::providers::noodlemagazine::NoodlemagazineProvider::new())), // "noodlemagazine" => Some(AnyProvider::Noodlemagazine(crate::providers::noodlemagazine::NoodlemagazineProvider::new())),
"freshporno" => Some(AnyProvider::Freshporno(crate::providers::freshporno::FreshpornoProvider::new())), "freshporno" => Some(AnyProvider::Freshporno(
crate::providers::freshporno::FreshpornoProvider::new(),
)),
_ => Some(AnyProvider::Perverzija(PerverzijaProvider::new())), _ => Some(AnyProvider::Perverzija(PerverzijaProvider::new())),
} }
} }

View File

@@ -18,6 +18,7 @@ pub struct Channel {
pub categories: Vec<String>, //[], pub categories: Vec<String>, //[],
pub options: Vec<ChannelOption>, pub options: Vec<ChannelOption>,
pub nsfw: bool, //true pub nsfw: bool, //true
pub cacheDuration: u32, //Some(86400)
} }
#[derive(serde::Serialize)] #[derive(serde::Serialize)]