mirror of
https://github.com/n08i40k/schedule-parser-rusted.git
synced 2025-12-06 17:57:47 +03:00
feat!: add telegram auth and async refactor
- Removed "/schedule/update-download-url" endpoint, this mechanism was replaced by Yandex Cloud FaaS. Ура :) - Improved schedule caching mechanism. - Added Telegram WebApp authentication support. - Reworked endpoints responses and errors mechanism. - Refactored application state management. - Make synchronous database operations, middlewares and extractors to asynchronous. - Made user password field optional to support multiple auth methods. - Renamed users table column "version" to "android_version" and made it nullable.
This commit is contained in:
17
src/state/env/mod.rs
vendored
Normal file
17
src/state/env/mod.rs
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
pub mod schedule;
|
||||
pub mod telegram;
|
||||
pub mod vk_id;
|
||||
pub mod yandex_cloud;
|
||||
|
||||
pub use self::schedule::ScheduleEnvData;
|
||||
pub use self::telegram::TelegramEnvData;
|
||||
pub use self::vk_id::VkIdEnvData;
|
||||
pub use self::yandex_cloud::YandexCloudEnvData;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct AppEnv {
|
||||
pub schedule: ScheduleEnvData,
|
||||
pub telegram: TelegramEnvData,
|
||||
pub vk_id: VkIdEnvData,
|
||||
pub yandex_cloud: YandexCloudEnvData,
|
||||
}
|
||||
17
src/state/env/schedule.rs
vendored
Normal file
17
src/state/env/schedule.rs
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
use std::env;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ScheduleEnvData {
|
||||
pub url: Option<String>,
|
||||
pub auto_update: bool,
|
||||
}
|
||||
|
||||
impl Default for ScheduleEnvData {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
url: env::var("SCHEDULE_INIT_URL").ok(),
|
||||
auto_update: !env::var("SCHEDULE_DISABLE_AUTO_UPDATE")
|
||||
.is_ok_and(|v| v.eq("1") || v.eq("true")),
|
||||
}
|
||||
}
|
||||
}
|
||||
28
src/state/env/telegram.rs
vendored
Normal file
28
src/state/env/telegram.rs
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
use std::env;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct TelegramEnvData {
|
||||
pub bot_id: i64,
|
||||
pub mini_app_host: String,
|
||||
pub test_dc: bool,
|
||||
}
|
||||
|
||||
impl Default for TelegramEnvData {
|
||||
fn default() -> Self {
|
||||
let _self = Self {
|
||||
bot_id: env::var("TELEGRAM_BOT_ID")
|
||||
.expect("TELEGRAM_BOT_ID must be set")
|
||||
.parse()
|
||||
.expect("TELEGRAM_BOT_ID must be integer"),
|
||||
mini_app_host: env::var("TELEGRAM_MINI_APP_HOST")
|
||||
.expect("TELEGRAM_MINI_APP_HOST must be set"),
|
||||
test_dc: env::var("TELEGRAM_TEST_DC").is_ok_and(|v| v.eq("1") || v.eq("true")),
|
||||
};
|
||||
|
||||
if _self.test_dc {
|
||||
log::warn!("Using test data-center of telegram!");
|
||||
}
|
||||
|
||||
_self
|
||||
}
|
||||
}
|
||||
19
src/state/env/vk_id.rs
vendored
Normal file
19
src/state/env/vk_id.rs
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
use std::env;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct VkIdEnvData {
|
||||
pub client_id: i32,
|
||||
pub redirect_url: String,
|
||||
}
|
||||
|
||||
impl Default for VkIdEnvData {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
client_id: env::var("VK_ID_CLIENT_ID")
|
||||
.expect("VK_ID_CLIENT_ID must be set")
|
||||
.parse()
|
||||
.expect("VK_ID_CLIENT_ID must be integer"),
|
||||
redirect_url: env::var("VK_ID_REDIRECT_URI").expect("VK_ID_REDIRECT_URI must be set"),
|
||||
}
|
||||
}
|
||||
}
|
||||
16
src/state/env/yandex_cloud.rs
vendored
Normal file
16
src/state/env/yandex_cloud.rs
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
use std::env;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct YandexCloudEnvData {
|
||||
pub api_key: String,
|
||||
pub func_id: String,
|
||||
}
|
||||
|
||||
impl Default for YandexCloudEnvData {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
api_key: env::var("YANDEX_CLOUD_API_KEY").expect("YANDEX_CLOUD_API_KEY must be set"),
|
||||
func_id: env::var("YANDEX_CLOUD_FUNC_ID").expect("YANDEX_CLOUD_FUNC_ID must be set"),
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user