quoter/src/main.rs

38 lines
1.1 KiB
Rust
Raw Normal View History

2024-08-31 00:32:37 +00:00
mod app_state;
mod auth;
mod handlers;
mod s3_utils;
mod thumbnail;
2024-04-08 07:17:14 +00:00
2024-10-02 15:14:54 +00:00
use actix_web::{middleware::Logger, web, App, HttpServer, HttpResponse};
2024-08-31 00:32:37 +00:00
use app_state::AppState;
use handlers::{proxy_handler, upload_handler};
2024-09-23 13:32:54 +00:00
use tokio::task::spawn_blocking;
2023-09-27 23:08:48 +00:00
#[actix_web::main]
async fn main() -> std::io::Result<()> {
2024-08-30 19:11:21 +00:00
let app_state = AppState::new().await;
2024-08-30 20:27:01 +00:00
let app_state_clone = app_state.clone();
2024-09-23 15:16:47 +00:00
2024-09-23 13:32:54 +00:00
// Используем spawn_blocking для работы, которая не совместима с Send
spawn_blocking(move || {
let rt = tokio::runtime::Handle::current();
rt.block_on(async move {
app_state_clone.update_filelist_from_aws().await;
app_state_clone.refresh_file_list_periodically().await;
});
2024-08-30 20:27:01 +00:00
});
2023-09-27 23:08:48 +00:00
HttpServer::new(move || {
App::new()
2024-08-30 19:11:21 +00:00
.app_data(web::Data::new(app_state.clone()))
2023-10-11 20:03:12 +00:00
.wrap(Logger::default())
2024-08-31 00:32:37 +00:00
.route("/", web::post().to(upload_handler))
2024-10-02 15:29:08 +00:00
.route("/{path:.*}", web::get().to(proxy_handler))
2023-09-27 23:08:48 +00:00
})
2024-08-30 18:05:51 +00:00
.bind("127.0.0.1:8080")?
2023-09-27 23:08:48 +00:00
.run()
.await
2024-09-23 15:16:47 +00:00
}