fixed the clientversion parsing

This commit is contained in:
Simon
2026-02-26 10:52:03 +00:00
parent b3d10ae0d9
commit 4ad9453245

View File

@@ -14,6 +14,7 @@ use crate::providers::pornhub::PornhubProvider;
use crate::providers::redtube::RedtubeProvider; use crate::providers::redtube::RedtubeProvider;
use crate::providers::rule34video::Rule34videoProvider; use crate::providers::rule34video::Rule34videoProvider;
// use crate::providers::spankbang::SpankbangProvider; // use crate::providers::spankbang::SpankbangProvider;
use crate::providers::{ALL_PROVIDERS, DynProvider};
use crate::util::cache::VideoCache; use crate::util::cache::VideoCache;
use crate::util::discord::send_discord_error_report; use crate::util::discord::send_discord_error_report;
use crate::util::proxy::{Proxy, all_proxies_snapshot}; use crate::util::proxy::{Proxy, all_proxies_snapshot};
@@ -21,7 +22,6 @@ use crate::util::requester::Requester;
use crate::{DbPool, db, status::*, videos::*}; use crate::{DbPool, db, status::*, videos::*};
use cute::c; use cute::c;
use std::sync::Arc; use std::sync::Arc;
use crate::providers::{DynProvider, ALL_PROVIDERS};
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct ClientVersion { pub struct ClientVersion {
@@ -41,35 +41,31 @@ impl ClientVersion {
pub fn parse(input: &str) -> Option<Self> { pub fn parse(input: &str) -> Option<Self> {
// Example input: "Hot%20Tub/22c CFNetwork/1494.0.7 Darwin/23.4.0 0.002478" // Example input: "Hot%20Tub/22c CFNetwork/1494.0.7 Darwin/23.4.0 0.002478"
let parts: Vec<&str> = input.split_whitespace().collect(); let first_part = input.split_whitespace().next()?;
if let Some(first) = parts.first() { let mut name_version = first_part.splitn(2, '/');
let name_version: Vec<&str> = first.split('/').collect();
let name = name_version[1];
// Extract version and optional subversion let name = name_version.next()?;
let (version, subversion) = let version_str = name_version.next()?;
if let Some((v, c)) = name.split_at(name.len().saturating_sub(1)).into() {
match v.parse::<u32>() {
Ok(ver) => (ver, c.chars().next().map(|ch| ch as u32).unwrap_or(0)),
Err(_) => {
// Try parsing whole string if no subversion exists
match name.parse::<u32>() {
Ok(ver) => (ver, 0),
Err(_) => return None,
}
}
}
} else {
return None;
};
return Some(ClientVersion { // Find the index where the numeric part ends
version: version, let split_idx = version_str
subversion: subversion, .find(|c: char| !c.is_ascii_digit())
.unwrap_or(version_str.len());
let (v_num, v_alpha) = version_str.split_at(split_idx);
// Parse the numeric version
let version = v_num.parse::<u32>().ok()?;
// Convert the first character of the subversion to u32 (ASCII value),
// or 0 if it doesn't exist.
let subversion = v_alpha.chars().next().map(|ch| ch as u32).unwrap_or(0);
Some(Self {
version,
subversion,
name: name.to_string(), name: name.to_string(),
}); })
}
None
} }
} }
@@ -107,15 +103,8 @@ pub fn config(cfg: &mut web::ServiceConfig) {
// .route(web::get().to(videos_get)) // .route(web::get().to(videos_get))
.route(web::post().to(videos_post)), .route(web::post().to(videos_post)),
) )
.service( .service(web::resource("/test").route(web::get().to(test)))
web::resource("/test") .service(web::resource("/proxies").route(web::get().to(proxies)));
.route(web::get().to(test))
)
.service(
web::resource("/proxies")
.route(web::get().to(proxies))
)
;
} }
async fn status(req: HttpRequest) -> Result<impl web::Responder, web::Error> { async fn status(req: HttpRequest) -> Result<impl web::Responder, web::Error> {
@@ -128,6 +117,11 @@ async fn status(req: HttpRequest) -> Result<impl web::Responder, web::Error> {
_ => ClientVersion::new(999, 0, "999".to_string()), _ => ClientVersion::new(999, 0, "999".to_string()),
}; };
println!(
"Received status request with client version: {:?}",
clientversion
);
let host = req let host = req
.headers() .headers()
.get(header::HOST) .get(header::HOST)
@@ -184,8 +178,7 @@ async fn status(req: HttpRequest) -> Result<impl web::Responder, web::Error> {
name: "Perverzija".to_string(), name: "Perverzija".to_string(),
description: "Free videos from Perverzija".to_string(), description: "Free videos from Perverzija".to_string(),
premium: false, premium: false,
favicon: "https://www.google.com/s2/favicons?sz=64&domain=tube.perverzija.com" favicon: "https://www.google.com/s2/favicons?sz=64&domain=tube.perverzija.com".to_string(),
.to_string(),
status: "active".to_string(), status: "active".to_string(),
categories: vec![], categories: vec![],
options: vec![ options: vec![
@@ -956,7 +949,7 @@ async fn status(req: HttpRequest) -> Result<impl web::Responder, web::Error> {
// } // }
for provider in ALL_PROVIDERS.values() { for provider in ALL_PROVIDERS.values() {
if let Some(channel) = provider.get_channel(clientversion.clone()){ if let Some(channel) = provider.get_channel(clientversion.clone()) {
status.add_channel(channel); status.add_channel(channel);
} }
} }
@@ -1032,26 +1025,14 @@ async fn videos_post(
.as_deref() .as_deref()
.unwrap_or("en") .unwrap_or("en")
.to_string(); .to_string();
let network = video_request let network = video_request.networks.as_deref().unwrap_or("").to_string();
.networks let stars = video_request.stars.as_deref().unwrap_or("").to_string();
.as_deref()
.unwrap_or("")
.to_string();
let stars = video_request
.stars
.as_deref()
.unwrap_or("")
.to_string();
let categories = video_request let categories = video_request
.categories .categories
.as_deref() .as_deref()
.unwrap_or("") .unwrap_or("")
.to_string(); .to_string();
let duration = video_request let duration = video_request.duration.as_deref().unwrap_or("").to_string();
.duration
.as_deref()
.unwrap_or("")
.to_string();
let options = ServerOptions { let options = ServerOptions {
featured: Some(featured), featured: Some(featured),
category: Some(category), category: Some(category),
@@ -1063,7 +1044,7 @@ async fn videos_post(
stars: Some(stars), stars: Some(stars),
categories: Some(categories), categories: Some(categories),
duration: Some(duration), duration: Some(duration),
sort: Some(sort.clone()) sort: Some(sort.clone()),
}; };
let video_items = provider let video_items = provider
.get_videos( .get_videos(
@@ -1165,7 +1146,8 @@ pub async fn test() -> Result<impl web::Responder, web::Error> {
file!(), file!(),
line!(), line!(),
module_path!(), module_path!(),
).await; )
.await;
Ok(web::HttpResponse::Ok()) Ok(web::HttpResponse::Ok())
} }