fixes and cleanup

This commit is contained in:
Simon
2026-03-05 18:18:48 +00:00
parent 76fd5a4f4f
commit 2627505ade
49 changed files with 3245 additions and 1376 deletions

View File

@@ -1,31 +1,32 @@
#![warn(unused_extern_crates)]
#![allow(non_snake_case)]
use std::{env, thread};
use diesel::{r2d2::{self, ConnectionManager}, SqliteConnection};
use diesel::{
SqliteConnection,
r2d2::{self, ConnectionManager},
};
use dotenvy::dotenv;
use ntex_files as fs;
use ntex::web;
use ntex_files as fs;
mod api;
mod proxy;
mod db;
mod models;
mod providers;
mod proxies;
mod proxy;
mod schema;
mod status;
mod util;
mod videos;
mod proxies;
type DbPool = r2d2::Pool<ConnectionManager<SqliteConnection>>;
// #[macro_use(c)]
// extern crate cute;
#[ntex::main]
async fn main() -> std::io::Result<()> {
// std::env::set_var("RUST_BACKTRACE", "1");
@@ -33,7 +34,7 @@ async fn main() -> std::io::Result<()> {
// Enable request logging
if std::env::var("RUST_LOG").is_err() {
unsafe{
unsafe {
std::env::set_var("RUST_LOG", "warn");
}
}
@@ -49,20 +50,22 @@ async fn main() -> std::io::Result<()> {
let mut requester = util::requester::Requester::new();
requester.set_proxy(env::var("PROXY").unwrap_or("0".to_string()) != "0".to_string());
let cache: util::cache::VideoCache = crate::util::cache::VideoCache::new().max_size(100_000).to_owned();
thread::spawn(move || {
// Create a tiny runtime just for these async tasks
let rt = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.expect("build tokio runtime");
let cache: util::cache::VideoCache = crate::util::cache::VideoCache::new()
.max_size(100_000)
.to_owned();
rt.block_on(async move {
providers::init_providers_now();
});
thread::spawn(move || {
// Create a tiny runtime just for these async tasks
let rt = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.expect("build tokio runtime");
rt.block_on(async move {
providers::init_providers_now();
});
});
web::HttpServer::new(move || {
web::App::new()
.state(pool.clone())
@@ -72,17 +75,16 @@ async fn main() -> std::io::Result<()> {
.service(web::scope("/api").configure(api::config))
.service(web::scope("/proxy").configure(proxy::config))
.service(
web::resource("/")
.route(web::get().to(|req: web::HttpRequest| async move{
let host = match std::env::var("DOMAIN"){
Ok(d) => d,
Err(_) => req.connection_info().host().to_string()
};
let source_forward_header = format!("hottub://source?url={}", host);
web::HttpResponse::Found()
.header("Location", source_forward_header)
.finish()
}))
web::resource("/").route(web::get().to(|req: web::HttpRequest| async move {
let host = match std::env::var("DOMAIN") {
Ok(d) => d,
Err(_) => req.connection_info().host().to_string(),
};
let source_forward_header = format!("hottub://source?url={}", host);
web::HttpResponse::Found()
.header("Location", source_forward_header)
.finish()
})),
)
.service(fs::Files::new("/", "static").index_file("index.html"))
})