some cleanup

This commit is contained in:
Simon
2025-05-31 09:43:46 +00:00
parent 96b914fb2e
commit 5067515933
3 changed files with 0 additions and 55 deletions

View File

@@ -12,50 +12,6 @@ mod videos;
mod providers;
mod util;
#[derive(Clone, Debug, Deserialize)]
struct Metadata {
name: String,
version: String,
author: String,
}
// type getVideosFn = fn get_videos(channel: Option<String>, sort: Option<String>, query: Option<String>, page: Option<String>, per_page: Option<String>) -> Videos;
async fn metadata(data: web::types::State<Metadata>) -> HttpResponse {
async fn counter(x: String) -> String{
for i in 1..=5 {
println!("{}: {}", x, i);
thread::sleep(Duration::from_secs(1));
}
return x;
}
let meta = data.get_ref().clone();
let mut handles = vec![];
for i in 1..=3 {
let name = format!("{}-{}", meta.name, i);
handles.push(thread::spawn(move || {
futures::executor::block_on(counter(name.clone()))
}));
}
let results: Vec<String> = handles
.into_iter()
.map(|handle| handle.join().unwrap())
.collect();
println!("Results: {:?}", results);
HttpResponse::Ok().json(
&json!({
"description": "A simple web server for the Hot Tub app.",
"documentation": ""
}),
)
}
#[ntex::main]
async fn main() -> std::io::Result<()> {
std::env::set_var("RUST_LOG", "ntex=warn");
@@ -64,12 +20,8 @@ async fn main() -> std::io::Result<()> {
web::HttpServer::new(|| {
const METADATA_JSON: &str = include_str!("../metadata.json");
let mut meta: Metadata = serde_json::from_str(METADATA_JSON).unwrap();
web::App::new()
.wrap(web::middleware::Logger::default())
.state(meta.clone())
.route("/meta", web::get().to(metadata))
.service(web::scope("/api").configure(api::config))
.service(fs::Files::new("/", "static"))
})