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::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())
|
||||||
name: name.to_string(),
|
.unwrap_or(version_str.len());
|
||||||
});
|
|
||||||
}
|
let (v_num, v_alpha) = version_str.split_at(split_idx);
|
||||||
None
|
|
||||||
|
// 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::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)
|
||||||
@@ -178,75 +172,74 @@ async fn status(req: HttpRequest) -> Result<impl web::Responder, web::Error> {
|
|||||||
nsfw: true,
|
nsfw: true,
|
||||||
cacheDuration: Some(1800),
|
cacheDuration: Some(1800),
|
||||||
});
|
});
|
||||||
// perverzija
|
// perverzija
|
||||||
status.add_channel(Channel {
|
status.add_channel(Channel {
|
||||||
id: "perverzija".to_string(),
|
id: "perverzija".to_string(),
|
||||||
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![
|
// ChannelOption {
|
||||||
// ChannelOption {
|
// id: "sort".to_string(),
|
||||||
// id: "sort".to_string(),
|
// title: "Sort".to_string(),
|
||||||
// title: "Sort".to_string(),
|
// description: "Sort the Videos".to_string(), //"Sort the videos by Date or Name.".to_string(),
|
||||||
// description: "Sort the Videos".to_string(), //"Sort the videos by Date or Name.".to_string(),
|
// systemImage: "list.number".to_string(),
|
||||||
// systemImage: "list.number".to_string(),
|
// colorName: "blue".to_string(),
|
||||||
// colorName: "blue".to_string(),
|
// options: vec![
|
||||||
// options: vec![
|
// FilterOption {
|
||||||
// FilterOption {
|
// id: "date".to_string(),
|
||||||
// id: "date".to_string(),
|
// title: "Date".to_string(),
|
||||||
// title: "Date".to_string(),
|
// },
|
||||||
// },
|
// FilterOption {
|
||||||
// FilterOption {
|
// id: "name".to_string(),
|
||||||
// id: "name".to_string(),
|
// title: "Name".to_string(),
|
||||||
// title: "Name".to_string(),
|
// },
|
||||||
// },
|
// ],
|
||||||
// ],
|
// multiSelect: false,
|
||||||
// multiSelect: false,
|
// },
|
||||||
// },
|
ChannelOption {
|
||||||
ChannelOption {
|
id: "featured".to_string(),
|
||||||
id: "featured".to_string(),
|
title: "Featured".to_string(),
|
||||||
title: "Featured".to_string(),
|
description: "Filter Featured Videos.".to_string(),
|
||||||
description: "Filter Featured Videos.".to_string(),
|
systemImage: "star".to_string(),
|
||||||
systemImage: "star".to_string(),
|
colorName: "red".to_string(),
|
||||||
colorName: "red".to_string(),
|
options: vec![
|
||||||
options: vec![
|
FilterOption {
|
||||||
FilterOption {
|
id: "all".to_string(),
|
||||||
id: "all".to_string(),
|
title: "No".to_string(),
|
||||||
title: "No".to_string(),
|
},
|
||||||
},
|
FilterOption {
|
||||||
FilterOption {
|
id: "featured".to_string(),
|
||||||
id: "featured".to_string(),
|
title: "Yes".to_string(),
|
||||||
title: "Yes".to_string(),
|
},
|
||||||
},
|
],
|
||||||
],
|
multiSelect: false,
|
||||||
multiSelect: false,
|
},
|
||||||
},
|
// ChannelOption {
|
||||||
// ChannelOption {
|
// id: "duration".to_string(),
|
||||||
// id: "duration".to_string(),
|
// title: "Duration".to_string(),
|
||||||
// title: "Duration".to_string(),
|
// description: "Filter the videos by duration.".to_string(),
|
||||||
// description: "Filter the videos by duration.".to_string(),
|
// systemImage: "timer".to_string(),
|
||||||
// systemImage: "timer".to_string(),
|
// colorName: "green".to_string(),
|
||||||
// colorName: "green".to_string(),
|
// options: vec![
|
||||||
// options: vec![
|
// FilterOption {
|
||||||
// FilterOption {
|
// id: "short".to_string(),
|
||||||
// id: "short".to_string(),
|
// title: "< 1h".to_string(),
|
||||||
// title: "< 1h".to_string(),
|
// },
|
||||||
// },
|
// FilterOption {
|
||||||
// FilterOption {
|
// id: "long".to_string(),
|
||||||
// id: "long".to_string(),
|
// title: "> 1h".to_string(),
|
||||||
// title: "> 1h".to_string(),
|
// },
|
||||||
// },
|
// ],
|
||||||
// ],
|
// multiSelect: true,
|
||||||
// multiSelect: true,
|
// },
|
||||||
// },
|
],
|
||||||
],
|
nsfw: true,
|
||||||
nsfw: true,
|
cacheDuration: None,
|
||||||
cacheDuration: None,
|
});
|
||||||
});
|
|
||||||
|
|
||||||
// pornzog
|
// pornzog
|
||||||
status.add_channel(Channel {
|
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()) {
|
// if clientversion >= ClientVersion::new(22, 105, "22i".to_string()) {
|
||||||
//sxyprn
|
//sxyprn
|
||||||
status.add_channel(Channel {
|
status.add_channel(Channel {
|
||||||
id: "sxyprn".to_string(),
|
id: "sxyprn".to_string(),
|
||||||
name: "SexyPorn".to_string(),
|
name: "SexyPorn".to_string(),
|
||||||
description: "Free Porn Site".to_string(),
|
description: "Free Porn Site".to_string(),
|
||||||
premium: false,
|
premium: false,
|
||||||
favicon: "https://www.google.com/s2/favicons?sz=64&domain=sxyprn.com".to_string(),
|
favicon: "https://www.google.com/s2/favicons?sz=64&domain=sxyprn.com".to_string(),
|
||||||
status: "active".to_string(),
|
status: "active".to_string(),
|
||||||
categories: vec![],
|
categories: vec![],
|
||||||
options: vec![
|
options: vec![
|
||||||
ChannelOption {
|
ChannelOption {
|
||||||
id: "sort".to_string(),
|
id: "sort".to_string(),
|
||||||
title: "Sort".to_string(),
|
title: "Sort".to_string(),
|
||||||
description: "Sort the Videos".to_string(), //"Sort the videos by Date or Name.".to_string(),
|
description: "Sort the Videos".to_string(), //"Sort the videos by Date or Name.".to_string(),
|
||||||
systemImage: "list.number".to_string(),
|
systemImage: "list.number".to_string(),
|
||||||
colorName: "blue".to_string(),
|
colorName: "blue".to_string(),
|
||||||
options: vec![
|
options: vec![
|
||||||
FilterOption {
|
FilterOption {
|
||||||
id: "latest".to_string(),
|
id: "latest".to_string(),
|
||||||
title: "Latest".to_string(),
|
title: "Latest".to_string(),
|
||||||
},
|
},
|
||||||
FilterOption {
|
FilterOption {
|
||||||
id: "views".to_string(),
|
id: "views".to_string(),
|
||||||
title: "Views".to_string(),
|
title: "Views".to_string(),
|
||||||
},
|
},
|
||||||
FilterOption {
|
FilterOption {
|
||||||
id: "rating".to_string(),
|
id: "rating".to_string(),
|
||||||
title: "Rating".to_string(),
|
title: "Rating".to_string(),
|
||||||
},
|
},
|
||||||
FilterOption {
|
FilterOption {
|
||||||
id: "orgasmic".to_string(),
|
id: "orgasmic".to_string(),
|
||||||
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(),
|
||||||
systemImage: "line.horizontal.3.decrease.circle".to_string(),
|
systemImage: "line.horizontal.3.decrease.circle".to_string(),
|
||||||
colorName: "green".to_string(),
|
colorName: "green".to_string(),
|
||||||
options: vec![
|
options: vec![
|
||||||
FilterOption {
|
FilterOption {
|
||||||
id: "top".to_string(),
|
id: "top".to_string(),
|
||||||
title: "Top".to_string(),
|
title: "Top".to_string(),
|
||||||
},
|
},
|
||||||
FilterOption {
|
FilterOption {
|
||||||
id: "other".to_string(),
|
id: "other".to_string(),
|
||||||
title: "Other".to_string(),
|
title: "Other".to_string(),
|
||||||
},
|
},
|
||||||
FilterOption {
|
FilterOption {
|
||||||
id: "all".to_string(),
|
id: "all".to_string(),
|
||||||
title: "All".to_string(),
|
title: "All".to_string(),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
multiSelect: false,
|
multiSelect: false,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
nsfw: true,
|
nsfw: true,
|
||||||
cacheDuration: Some(1800),
|
cacheDuration: Some(1800),
|
||||||
});
|
});
|
||||||
// }
|
// }
|
||||||
|
|
||||||
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())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user