fixed the clientversion parsing
This commit is contained in:
354
src/api.rs
354
src/api.rs
@@ -14,6 +14,7 @@ use crate::providers::pornhub::PornhubProvider;
|
||||
use crate::providers::redtube::RedtubeProvider;
|
||||
use crate::providers::rule34video::Rule34videoProvider;
|
||||
// use crate::providers::spankbang::SpankbangProvider;
|
||||
use crate::providers::{ALL_PROVIDERS, DynProvider};
|
||||
use crate::util::cache::VideoCache;
|
||||
use crate::util::discord::send_discord_error_report;
|
||||
use crate::util::proxy::{Proxy, all_proxies_snapshot};
|
||||
@@ -21,7 +22,6 @@ use crate::util::requester::Requester;
|
||||
use crate::{DbPool, db, status::*, videos::*};
|
||||
use cute::c;
|
||||
use std::sync::Arc;
|
||||
use crate::providers::{DynProvider, ALL_PROVIDERS};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ClientVersion {
|
||||
@@ -41,35 +41,31 @@ impl ClientVersion {
|
||||
|
||||
pub fn parse(input: &str) -> Option<Self> {
|
||||
// Example input: "Hot%20Tub/22c CFNetwork/1494.0.7 Darwin/23.4.0 0.002478"
|
||||
let parts: Vec<&str> = input.split_whitespace().collect();
|
||||
if let Some(first) = parts.first() {
|
||||
let name_version: Vec<&str> = first.split('/').collect();
|
||||
let name = name_version[1];
|
||||
let first_part = input.split_whitespace().next()?;
|
||||
let mut name_version = first_part.splitn(2, '/');
|
||||
|
||||
// Extract version and optional subversion
|
||||
let (version, subversion) =
|
||||
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;
|
||||
};
|
||||
let name = name_version.next()?;
|
||||
let version_str = name_version.next()?;
|
||||
|
||||
return Some(ClientVersion {
|
||||
version: version,
|
||||
subversion: subversion,
|
||||
name: name.to_string(),
|
||||
});
|
||||
}
|
||||
None
|
||||
// Find the index where the numeric part ends
|
||||
let split_idx = version_str
|
||||
.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(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,15 +103,8 @@ pub fn config(cfg: &mut web::ServiceConfig) {
|
||||
// .route(web::get().to(videos_get))
|
||||
.route(web::post().to(videos_post)),
|
||||
)
|
||||
.service(
|
||||
web::resource("/test")
|
||||
.route(web::get().to(test))
|
||||
)
|
||||
.service(
|
||||
web::resource("/proxies")
|
||||
.route(web::get().to(proxies))
|
||||
)
|
||||
;
|
||||
.service(web::resource("/test").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> {
|
||||
@@ -128,6 +117,11 @@ async fn status(req: HttpRequest) -> Result<impl web::Responder, web::Error> {
|
||||
_ => ClientVersion::new(999, 0, "999".to_string()),
|
||||
};
|
||||
|
||||
println!(
|
||||
"Received status request with client version: {:?}",
|
||||
clientversion
|
||||
);
|
||||
|
||||
let host = req
|
||||
.headers()
|
||||
.get(header::HOST)
|
||||
@@ -178,75 +172,74 @@ async fn status(req: HttpRequest) -> Result<impl web::Responder, web::Error> {
|
||||
nsfw: true,
|
||||
cacheDuration: Some(1800),
|
||||
});
|
||||
// perverzija
|
||||
status.add_channel(Channel {
|
||||
id: "perverzija".to_string(),
|
||||
name: "Perverzija".to_string(),
|
||||
description: "Free videos from Perverzija".to_string(),
|
||||
premium: false,
|
||||
favicon: "https://www.google.com/s2/favicons?sz=64&domain=tube.perverzija.com"
|
||||
.to_string(),
|
||||
status: "active".to_string(),
|
||||
categories: vec![],
|
||||
options: vec![
|
||||
// ChannelOption {
|
||||
// id: "sort".to_string(),
|
||||
// title: "Sort".to_string(),
|
||||
// description: "Sort the Videos".to_string(), //"Sort the videos by Date or Name.".to_string(),
|
||||
// systemImage: "list.number".to_string(),
|
||||
// colorName: "blue".to_string(),
|
||||
// options: vec![
|
||||
// FilterOption {
|
||||
// id: "date".to_string(),
|
||||
// title: "Date".to_string(),
|
||||
// },
|
||||
// FilterOption {
|
||||
// id: "name".to_string(),
|
||||
// title: "Name".to_string(),
|
||||
// },
|
||||
// ],
|
||||
// multiSelect: false,
|
||||
// },
|
||||
ChannelOption {
|
||||
id: "featured".to_string(),
|
||||
title: "Featured".to_string(),
|
||||
description: "Filter Featured Videos.".to_string(),
|
||||
systemImage: "star".to_string(),
|
||||
colorName: "red".to_string(),
|
||||
options: vec![
|
||||
FilterOption {
|
||||
id: "all".to_string(),
|
||||
title: "No".to_string(),
|
||||
},
|
||||
FilterOption {
|
||||
id: "featured".to_string(),
|
||||
title: "Yes".to_string(),
|
||||
},
|
||||
],
|
||||
multiSelect: false,
|
||||
},
|
||||
// ChannelOption {
|
||||
// id: "duration".to_string(),
|
||||
// title: "Duration".to_string(),
|
||||
// description: "Filter the videos by duration.".to_string(),
|
||||
// systemImage: "timer".to_string(),
|
||||
// colorName: "green".to_string(),
|
||||
// options: vec![
|
||||
// FilterOption {
|
||||
// id: "short".to_string(),
|
||||
// title: "< 1h".to_string(),
|
||||
// },
|
||||
// FilterOption {
|
||||
// id: "long".to_string(),
|
||||
// title: "> 1h".to_string(),
|
||||
// },
|
||||
// ],
|
||||
// multiSelect: true,
|
||||
// },
|
||||
],
|
||||
nsfw: true,
|
||||
cacheDuration: None,
|
||||
});
|
||||
// perverzija
|
||||
status.add_channel(Channel {
|
||||
id: "perverzija".to_string(),
|
||||
name: "Perverzija".to_string(),
|
||||
description: "Free videos from Perverzija".to_string(),
|
||||
premium: false,
|
||||
favicon: "https://www.google.com/s2/favicons?sz=64&domain=tube.perverzija.com".to_string(),
|
||||
status: "active".to_string(),
|
||||
categories: vec![],
|
||||
options: vec![
|
||||
// ChannelOption {
|
||||
// id: "sort".to_string(),
|
||||
// title: "Sort".to_string(),
|
||||
// description: "Sort the Videos".to_string(), //"Sort the videos by Date or Name.".to_string(),
|
||||
// systemImage: "list.number".to_string(),
|
||||
// colorName: "blue".to_string(),
|
||||
// options: vec![
|
||||
// FilterOption {
|
||||
// id: "date".to_string(),
|
||||
// title: "Date".to_string(),
|
||||
// },
|
||||
// FilterOption {
|
||||
// id: "name".to_string(),
|
||||
// title: "Name".to_string(),
|
||||
// },
|
||||
// ],
|
||||
// multiSelect: false,
|
||||
// },
|
||||
ChannelOption {
|
||||
id: "featured".to_string(),
|
||||
title: "Featured".to_string(),
|
||||
description: "Filter Featured Videos.".to_string(),
|
||||
systemImage: "star".to_string(),
|
||||
colorName: "red".to_string(),
|
||||
options: vec![
|
||||
FilterOption {
|
||||
id: "all".to_string(),
|
||||
title: "No".to_string(),
|
||||
},
|
||||
FilterOption {
|
||||
id: "featured".to_string(),
|
||||
title: "Yes".to_string(),
|
||||
},
|
||||
],
|
||||
multiSelect: false,
|
||||
},
|
||||
// ChannelOption {
|
||||
// id: "duration".to_string(),
|
||||
// title: "Duration".to_string(),
|
||||
// description: "Filter the videos by duration.".to_string(),
|
||||
// systemImage: "timer".to_string(),
|
||||
// colorName: "green".to_string(),
|
||||
// options: vec![
|
||||
// FilterOption {
|
||||
// id: "short".to_string(),
|
||||
// title: "< 1h".to_string(),
|
||||
// },
|
||||
// FilterOption {
|
||||
// id: "long".to_string(),
|
||||
// title: "> 1h".to_string(),
|
||||
// },
|
||||
// ],
|
||||
// multiSelect: true,
|
||||
// },
|
||||
],
|
||||
nsfw: true,
|
||||
cacheDuration: None,
|
||||
});
|
||||
|
||||
// pornzog
|
||||
status.add_channel(Channel {
|
||||
@@ -891,72 +884,72 @@ async fn status(req: HttpRequest) -> Result<impl web::Responder, web::Error> {
|
||||
});
|
||||
|
||||
// if clientversion >= ClientVersion::new(22, 105, "22i".to_string()) {
|
||||
//sxyprn
|
||||
status.add_channel(Channel {
|
||||
id: "sxyprn".to_string(),
|
||||
name: "SexyPorn".to_string(),
|
||||
description: "Free Porn Site".to_string(),
|
||||
premium: false,
|
||||
favicon: "https://www.google.com/s2/favicons?sz=64&domain=sxyprn.com".to_string(),
|
||||
status: "active".to_string(),
|
||||
categories: vec![],
|
||||
options: vec![
|
||||
ChannelOption {
|
||||
id: "sort".to_string(),
|
||||
title: "Sort".to_string(),
|
||||
description: "Sort the Videos".to_string(), //"Sort the videos by Date or Name.".to_string(),
|
||||
systemImage: "list.number".to_string(),
|
||||
colorName: "blue".to_string(),
|
||||
options: vec![
|
||||
FilterOption {
|
||||
id: "latest".to_string(),
|
||||
title: "Latest".to_string(),
|
||||
},
|
||||
FilterOption {
|
||||
id: "views".to_string(),
|
||||
title: "Views".to_string(),
|
||||
},
|
||||
FilterOption {
|
||||
id: "rating".to_string(),
|
||||
title: "Rating".to_string(),
|
||||
},
|
||||
FilterOption {
|
||||
id: "orgasmic".to_string(),
|
||||
title: "Orgasmic".to_string(),
|
||||
},
|
||||
],
|
||||
multiSelect: false,
|
||||
},
|
||||
ChannelOption {
|
||||
id: "filter".to_string(),
|
||||
title: "Filter".to_string(),
|
||||
description: "Filter the Videos".to_string(), //"Sort the videos by Date or Name.".to_string(),
|
||||
systemImage: "line.horizontal.3.decrease.circle".to_string(),
|
||||
colorName: "green".to_string(),
|
||||
options: vec![
|
||||
FilterOption {
|
||||
id: "top".to_string(),
|
||||
title: "Top".to_string(),
|
||||
},
|
||||
FilterOption {
|
||||
id: "other".to_string(),
|
||||
title: "Other".to_string(),
|
||||
},
|
||||
FilterOption {
|
||||
id: "all".to_string(),
|
||||
title: "All".to_string(),
|
||||
},
|
||||
],
|
||||
multiSelect: false,
|
||||
},
|
||||
],
|
||||
nsfw: true,
|
||||
cacheDuration: Some(1800),
|
||||
});
|
||||
//sxyprn
|
||||
status.add_channel(Channel {
|
||||
id: "sxyprn".to_string(),
|
||||
name: "SexyPorn".to_string(),
|
||||
description: "Free Porn Site".to_string(),
|
||||
premium: false,
|
||||
favicon: "https://www.google.com/s2/favicons?sz=64&domain=sxyprn.com".to_string(),
|
||||
status: "active".to_string(),
|
||||
categories: vec![],
|
||||
options: vec![
|
||||
ChannelOption {
|
||||
id: "sort".to_string(),
|
||||
title: "Sort".to_string(),
|
||||
description: "Sort the Videos".to_string(), //"Sort the videos by Date or Name.".to_string(),
|
||||
systemImage: "list.number".to_string(),
|
||||
colorName: "blue".to_string(),
|
||||
options: vec![
|
||||
FilterOption {
|
||||
id: "latest".to_string(),
|
||||
title: "Latest".to_string(),
|
||||
},
|
||||
FilterOption {
|
||||
id: "views".to_string(),
|
||||
title: "Views".to_string(),
|
||||
},
|
||||
FilterOption {
|
||||
id: "rating".to_string(),
|
||||
title: "Rating".to_string(),
|
||||
},
|
||||
FilterOption {
|
||||
id: "orgasmic".to_string(),
|
||||
title: "Orgasmic".to_string(),
|
||||
},
|
||||
],
|
||||
multiSelect: false,
|
||||
},
|
||||
ChannelOption {
|
||||
id: "filter".to_string(),
|
||||
title: "Filter".to_string(),
|
||||
description: "Filter the Videos".to_string(), //"Sort the videos by Date or Name.".to_string(),
|
||||
systemImage: "line.horizontal.3.decrease.circle".to_string(),
|
||||
colorName: "green".to_string(),
|
||||
options: vec![
|
||||
FilterOption {
|
||||
id: "top".to_string(),
|
||||
title: "Top".to_string(),
|
||||
},
|
||||
FilterOption {
|
||||
id: "other".to_string(),
|
||||
title: "Other".to_string(),
|
||||
},
|
||||
FilterOption {
|
||||
id: "all".to_string(),
|
||||
title: "All".to_string(),
|
||||
},
|
||||
],
|
||||
multiSelect: false,
|
||||
},
|
||||
],
|
||||
nsfw: true,
|
||||
cacheDuration: Some(1800),
|
||||
});
|
||||
// }
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1032,26 +1025,14 @@ async fn videos_post(
|
||||
.as_deref()
|
||||
.unwrap_or("en")
|
||||
.to_string();
|
||||
let network = video_request
|
||||
.networks
|
||||
.as_deref()
|
||||
.unwrap_or("")
|
||||
.to_string();
|
||||
let stars = video_request
|
||||
.stars
|
||||
.as_deref()
|
||||
.unwrap_or("")
|
||||
.to_string();
|
||||
let network = video_request.networks.as_deref().unwrap_or("").to_string();
|
||||
let stars = video_request.stars.as_deref().unwrap_or("").to_string();
|
||||
let categories = video_request
|
||||
.categories
|
||||
.as_deref()
|
||||
.unwrap_or("")
|
||||
.to_string();
|
||||
let duration = video_request
|
||||
.duration
|
||||
.as_deref()
|
||||
.unwrap_or("")
|
||||
.to_string();
|
||||
let duration = video_request.duration.as_deref().unwrap_or("").to_string();
|
||||
let options = ServerOptions {
|
||||
featured: Some(featured),
|
||||
category: Some(category),
|
||||
@@ -1063,7 +1044,7 @@ async fn videos_post(
|
||||
stars: Some(stars),
|
||||
categories: Some(categories),
|
||||
duration: Some(duration),
|
||||
sort: Some(sort.clone())
|
||||
sort: Some(sort.clone()),
|
||||
};
|
||||
let video_items = provider
|
||||
.get_videos(
|
||||
@@ -1165,7 +1146,8 @@ pub async fn test() -> Result<impl web::Responder, web::Error> {
|
||||
file!(),
|
||||
line!(),
|
||||
module_path!(),
|
||||
).await;
|
||||
)
|
||||
.await;
|
||||
|
||||
Ok(web::HttpResponse::Ok())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user