mirror of
https://github.com/n08i40k/schedule-parser-rusted.git
synced 2025-12-06 17:57:47 +03:00
Compare commits
4 Commits
release/v1
...
b5d372e109
| Author | SHA1 | Date | |
|---|---|---|---|
|
b5d372e109
|
|||
|
84dca02c34
|
|||
|
6c9d3b3b31
|
|||
|
a348b1b99b
|
142
.github/workflows/build.yml
vendored
Normal file
142
.github/workflows/build.yml
vendored
Normal file
@@ -0,0 +1,142 @@
|
|||||||
|
name: build
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ "master" ]
|
||||||
|
tags-ignore: [ "release/v*" ]
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
|
||||||
|
env:
|
||||||
|
CARGO_TERM_COLOR: always
|
||||||
|
|
||||||
|
BINARY_NAME: schedule-parser-rusted
|
||||||
|
|
||||||
|
TEST_DB: ${{ secrets.TEST_DATABASE_URL }}
|
||||||
|
|
||||||
|
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
|
||||||
|
SENTRY_ORG: ${{ secrets.SENTRY_ORG }}
|
||||||
|
SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }}
|
||||||
|
|
||||||
|
DOCKER_IMAGE_NAME: ${{ github.repository }}
|
||||||
|
|
||||||
|
DOCKER_REGISTRY_HOST: registry.n08i40k.ru
|
||||||
|
DOCKER_REGISTRY_USERNAME: ${{ github.repository_owner }}
|
||||||
|
DOCKER_REGISTRY_PASSWORD: ${{ secrets.DOCKER_REGISTRY_PASSWORD }}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
name: Test
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Setup Rust
|
||||||
|
uses: actions-rust-lang/setup-rust-toolchain@v1.11.0
|
||||||
|
with:
|
||||||
|
toolchain: stable
|
||||||
|
|
||||||
|
- name: Test
|
||||||
|
run: |
|
||||||
|
cargo test --verbose
|
||||||
|
env:
|
||||||
|
DATABASE_URL: ${{ env.TEST_DB }}
|
||||||
|
SCHEDULE_DISABLE_AUTO_UPDATE: 1
|
||||||
|
JWT_SECRET: "test-secret-at-least-256-bits-used"
|
||||||
|
VK_ID_CLIENT_ID: 0
|
||||||
|
VK_ID_REDIRECT_URI: "vk0://vk.com/blank.html"
|
||||||
|
TELEGRAM_BOT_ID: 0
|
||||||
|
TELEGRAM_MINI_APP_HOST: example.com
|
||||||
|
TELEGRAM_TEST_DC: false
|
||||||
|
YANDEX_CLOUD_API_KEY: ""
|
||||||
|
YANDEX_CLOUD_FUNC_ID: ""
|
||||||
|
build:
|
||||||
|
name: Build
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: test
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Setup Rust
|
||||||
|
uses: actions-rust-lang/setup-rust-toolchain@v1.11.0
|
||||||
|
with:
|
||||||
|
toolchain: stable
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: cargo build --release --verbose
|
||||||
|
|
||||||
|
- name: Extract debug symbols
|
||||||
|
run: |
|
||||||
|
objcopy --only-keep-debug target/release/${{ env.BINARY_NAME }}{,.d}
|
||||||
|
objcopy --strip-debug --strip-unneeded target/release/${{ env.BINARY_NAME }}
|
||||||
|
objcopy --add-gnu-debuglink target/release/${{ env.BINARY_NAME }}{.d,}
|
||||||
|
|
||||||
|
- name: Setup sentry-cli
|
||||||
|
uses: matbour/setup-sentry-cli@v2.0.0
|
||||||
|
with:
|
||||||
|
version: latest
|
||||||
|
token: ${{ env.SENTRY_AUTH_TOKEN }}
|
||||||
|
organization: ${{ env.SENTRY_ORG }}
|
||||||
|
project: ${{ env.SENTRY_PROJECT }}
|
||||||
|
|
||||||
|
- name: Upload debug symbols to Sentry
|
||||||
|
run: |
|
||||||
|
sentry-cli debug-files upload --include-sources .
|
||||||
|
|
||||||
|
- name: Upload build binary artifact
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: release-binary
|
||||||
|
path: target/release/${{ env.BINARY_NAME }}
|
||||||
|
|
||||||
|
- name: Upload build debug symbols artifact
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: release-symbols
|
||||||
|
path: target/release/${{ env.BINARY_NAME }}.d
|
||||||
|
|
||||||
|
docker:
|
||||||
|
name: Build & Push Docker Image
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: build
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Download build artifacts
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
name: release-binary
|
||||||
|
|
||||||
|
- name: Setup Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3.10.0
|
||||||
|
|
||||||
|
- name: Login to Registry
|
||||||
|
uses: docker/login-action@v3.4.0
|
||||||
|
with:
|
||||||
|
registry: ${{ env.DOCKER_REGISTRY_HOST }}
|
||||||
|
username: ${{ env.DOCKER_REGISTRY_USERNAME }}
|
||||||
|
password: ${{ env.DOCKER_REGISTRY_PASSWORD }}
|
||||||
|
|
||||||
|
- name: Extract Docker metadata
|
||||||
|
id: meta
|
||||||
|
uses: docker/metadata-action@v5.7.0
|
||||||
|
with:
|
||||||
|
images: ${{ env.DOCKER_REGISTRY_HOST }}/${{ env.DOCKER_IMAGE_NAME }}
|
||||||
|
|
||||||
|
- name: Build and push Docker image
|
||||||
|
id: build-and-push
|
||||||
|
uses: docker/build-push-action@v6.15.0
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
push: true
|
||||||
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
|
cache-from: type=gha
|
||||||
|
cache-to: type=gha,mode=max
|
||||||
|
build-args: |
|
||||||
|
"BINARY_NAME=${{ env.BINARY_NAME }}"
|
||||||
2
.github/workflows/test.yml
vendored
2
.github/workflows/test.yml
vendored
@@ -2,7 +2,7 @@ name: cargo test
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ "master" ]
|
branches: [ "development" ]
|
||||||
tags-ignore: [ "release/v*" ]
|
tags-ignore: [ "release/v*" ]
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
|
|||||||
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -3538,7 +3538,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "schedule-parser-rusted"
|
name = "schedule-parser-rusted"
|
||||||
version = "1.2.1"
|
version = "1.2.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"actix-macros 0.1.0",
|
"actix-macros 0.1.0",
|
||||||
"actix-test",
|
"actix-test",
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ members = ["actix-macros", "actix-test", "providers"]
|
|||||||
|
|
||||||
[package]
|
[package]
|
||||||
name = "schedule-parser-rusted"
|
name = "schedule-parser-rusted"
|
||||||
version = "1.2.1"
|
version = "1.2.2"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
|
|||||||
@@ -49,25 +49,29 @@ pub async fn telegram_auth(
|
|||||||
let web_app_user =
|
let web_app_user =
|
||||||
serde_json::from_str::<WebAppUser>(init_data.data_map.get("user").unwrap()).unwrap();
|
serde_json::from_str::<WebAppUser>(init_data.data_map.get("user").unwrap()).unwrap();
|
||||||
|
|
||||||
let user =
|
let user = match Query::find_user_by_telegram_id(app_state.get_database(), web_app_user.id)
|
||||||
match Query::find_user_by_telegram_id(app_state.get_database(), web_app_user.id).await {
|
.await
|
||||||
Ok(Some(value)) => Ok(value),
|
.expect("Failed to find user by telegram id")
|
||||||
_ => {
|
{
|
||||||
let new_user = ActiveUser {
|
Some(value) => value,
|
||||||
id: Set(ObjectId::new().unwrap().to_string()),
|
None => {
|
||||||
username: Set(format!("telegram_{}", web_app_user.id)), // можно оставить, а можно поменять
|
let new_user = ActiveUser {
|
||||||
password: Set(None), // ибо нехуй
|
id: Set(ObjectId::new().unwrap().to_string()),
|
||||||
vk_id: Set(None),
|
username: Set(format!("telegram_{}", web_app_user.id)), // можно оставить, а можно поменять
|
||||||
telegram_id: Set(Some(web_app_user.id)),
|
password: Set(None), // ибо нехуй
|
||||||
group: Set(None),
|
vk_id: Set(None),
|
||||||
role: Set(UserRole::Student), // TODO: при реге проверять данные
|
telegram_id: Set(Some(web_app_user.id)),
|
||||||
android_version: Set(None),
|
group: Set(None),
|
||||||
};
|
role: Set(UserRole::Student), // TODO: при реге проверять данные
|
||||||
|
android_version: Set(None),
|
||||||
|
};
|
||||||
|
|
||||||
new_user.insert(app_state.get_database()).await
|
new_user
|
||||||
}
|
.insert(app_state.get_database())
|
||||||
|
.await
|
||||||
|
.expect("Failed to insert user")
|
||||||
}
|
}
|
||||||
.expect("Failed to get or add user");
|
};
|
||||||
|
|
||||||
let access_token = utility::jwt::encode(&user.id);
|
let access_token = utility::jwt::encode(&user.id);
|
||||||
Ok(Response::new(&access_token, user.group.is_some())).into()
|
Ok(Response::new(&access_token, user.group.is_some())).into()
|
||||||
|
|||||||
@@ -2,10 +2,12 @@ mod env;
|
|||||||
|
|
||||||
pub use crate::state::env::AppEnv;
|
pub use crate::state::env::AppEnv;
|
||||||
use actix_web::web;
|
use actix_web::web;
|
||||||
use database::sea_orm::{Database, DatabaseConnection};
|
use database::migration::{Migrator, MigratorTrait};
|
||||||
|
use database::sea_orm::{ConnectOptions, Database, DatabaseConnection};
|
||||||
use providers::base::{ScheduleProvider, ScheduleSnapshot};
|
use providers::base::{ScheduleProvider, ScheduleSnapshot};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use std::time::Duration;
|
||||||
use tokio_util::sync::CancellationToken;
|
use tokio_util::sync::CancellationToken;
|
||||||
|
|
||||||
/// Common data provided to endpoints.
|
/// Common data provided to endpoints.
|
||||||
@@ -55,9 +57,24 @@ impl AppState {
|
|||||||
database
|
database
|
||||||
} else {
|
} else {
|
||||||
let database_url = std::env::var("DATABASE_URL").expect("DATABASE_URL must be set");
|
let database_url = std::env::var("DATABASE_URL").expect("DATABASE_URL must be set");
|
||||||
Database::connect(&database_url)
|
|
||||||
|
let mut opt = ConnectOptions::new(database_url.clone());
|
||||||
|
|
||||||
|
opt.max_connections(4)
|
||||||
|
.min_connections(2)
|
||||||
|
.connect_timeout(Duration::from_secs(10))
|
||||||
|
.idle_timeout(Duration::from_secs(8))
|
||||||
|
.sqlx_logging(true);
|
||||||
|
|
||||||
|
let database = Database::connect(opt)
|
||||||
.await
|
.await
|
||||||
.unwrap_or_else(|_| panic!("Error connecting to {}", database_url))
|
.unwrap_or_else(|_| panic!("Error connecting to {}", database_url));
|
||||||
|
|
||||||
|
Migrator::up(&database, None)
|
||||||
|
.await
|
||||||
|
.expect("Failed to run database migrations");
|
||||||
|
|
||||||
|
database
|
||||||
},
|
},
|
||||||
env,
|
env,
|
||||||
providers,
|
providers,
|
||||||
|
|||||||
Reference in New Issue
Block a user