Files
quoter/src/main.rs
Untone d3bee5144f 🧹 Remove unused legacy modules and functions
- Deleted quota.rs module (quota management not needed via HTTP)
- Removed legacy get_id_by_token GraphQL function
- Removed unused set_user_quota and increase_user_quota methods
- Cleaned up unused imports and legacy structs
- Simplified handlers/mod.rs to only expose universal_handler

Architecture now focused on core functionality:
- GET / (user info)
- GET /<filename> (file serving)
- POST / (file upload)
2025-09-02 11:27:48 +03:00

69 lines
2.0 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 lookup;
mod s3_utils;
mod thumbnail;
use actix_cors::Cors;
use actix_web::{
App, HttpServer,
http::header::{self, HeaderName},
middleware::Logger,
web,
};
use app_state::AppState;
use handlers::universal_handler;
use log::warn;
use std::env;
use tokio::task::spawn_blocking;
#[actix_web::main]
async fn main() -> std::io::Result<()> {
env_logger::init();
warn!("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_filelist().await;
});
});
HttpServer::new(move || {
// Настройка CORS middleware
let cors = Cors::default()
.allow_any_origin() // TODO: ограничить конкретными доменами в продакшене
.allowed_methods(vec!["GET", "POST", "PUT", "DELETE", "OPTIONS"])
.allowed_headers(vec![
header::DNT,
header::USER_AGENT,
HeaderName::from_static("x-requested-with"),
header::IF_MODIFIED_SINCE,
header::CACHE_CONTROL,
header::CONTENT_TYPE,
header::RANGE,
header::AUTHORIZATION,
])
.expose_headers(vec![header::CONTENT_LENGTH, header::CONTENT_RANGE])
.supports_credentials()
.max_age(1728000); // 20 дней
App::new()
.app_data(web::Data::new(app_state.clone()))
.wrap(cors)
.wrap(Logger::default())
.default_service(web::to(universal_handler))
})
.bind(addr)?
.run()
.await
}