Files
quoter/src/main.rs
Untone e8955e4a5d
All checks were successful
deploy / deploy (push) Successful in 1m3s
minorfix6
2024-10-22 13:18:57 +03:00

44 lines
1.2 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
mod app_state;
mod auth;
mod handlers;
mod s3_utils;
mod thumbnail;
use actix_web::{middleware::Logger, web, App, HttpServer};
use app_state::AppState;
use handlers::{proxy_handler, upload_handler};
use log::info;
use tokio::task::spawn_blocking;
use std::env;
use env_logger;
#[actix_web::main]
async fn main() -> std::io::Result<()> {
env_logger::init();
info!("Started");
let port = env::var("PORT").unwrap_or_else(|_| "8080".to_string());
let addr = format!("0.0.0.0:{}", port);
let app_state = AppState::new().await;
let app_state_clone = app_state.clone();
// Используем spawn_blocking для работы, которая не совместима с Send
spawn_blocking(move || {
let rt = tokio::runtime::Handle::current();
rt.block_on(async move {
app_state_clone.cache_storj_filelist().await;
});
});
HttpServer::new(move || {
App::new()
.app_data(web::Data::new(app_state.clone()))
.wrap(Logger::default())
.route("/", web::post().to(upload_handler))
.route("/{path:.*}", web::get().to(proxy_handler))
})
.bind(addr)?
.run()
.await
}