mirror of
https://github.com/flibusta-apps/telegram_files_server.git
synced 2025-12-06 12:35:39 +01:00
Compare commits
16 Commits
0572e300ef
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 6d34fde8ca | |||
| ea8290f74c | |||
|
|
8336c8598e | ||
| 6e9ef95aaf | |||
| 07683cfc0b | |||
|
|
d2519bb9b7 | ||
| 24ebd4fe78 | |||
| 609ab9dcbc | |||
|
|
f0da4ef19c | ||
| ad0fc8faf7 | |||
|
|
3e227c1c17 | ||
| 4def0067cb | |||
| 85b4a12669 | |||
| b7abfc28cc | |||
| 2e98c84ba7 | |||
|
|
a18d1f1094 |
23
.github/workflows/build_docker_image.yml
vendored
23
.github/workflows/build_docker_image.yml
vendored
@@ -3,18 +3,16 @@ name: Build docker image
|
|||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- 'main'
|
- "main"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
Build-Docker-Image:
|
Build-Docker-Image:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
-
|
- name: Checkout
|
||||||
name: Checkout
|
uses: actions/checkout@v5
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
-
|
- name: Set up Docker Buildx
|
||||||
name: Set up Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
- id: repository_name
|
- id: repository_name
|
||||||
@@ -22,16 +20,14 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
string: ${{ github.repository }}
|
string: ${{ github.repository }}
|
||||||
|
|
||||||
-
|
- name: Login to ghcr.io
|
||||||
name: Login to ghcr.io
|
|
||||||
uses: docker/login-action@v3
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
registry: ghcr.io
|
registry: ghcr.io
|
||||||
username: ${{ github.actor }}
|
username: ${{ github.actor }}
|
||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
-
|
- name: Build and push
|
||||||
name: Build and push
|
|
||||||
id: docker_build
|
id: docker_build
|
||||||
uses: docker/build-push-action@v6
|
uses: docker/build-push-action@v6
|
||||||
env:
|
env:
|
||||||
@@ -39,12 +35,11 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
push: true
|
push: true
|
||||||
platforms: linux/amd64
|
platforms: linux/amd64
|
||||||
tags: ghcr.io/${{ env.IMAGE }}:latest
|
tags: ghcr.io/${{ env.IMAGE }}:latest,ghcr.io/${{ env.IMAGE }}:${{ github.sha }}
|
||||||
context: .
|
context: .
|
||||||
file: ./docker/production.dockerfile
|
file: ./docker/production.dockerfile
|
||||||
|
|
||||||
-
|
- name: Invoke deployment hook
|
||||||
name: Invoke deployment hook
|
|
||||||
uses: joelwmale/webhook-action@master
|
uses: joelwmale/webhook-action@master
|
||||||
with:
|
with:
|
||||||
url: ${{ secrets.WEBHOOK_URL }}
|
url: ${{ secrets.WEBHOOK_URL }}?FILES_SERVER_TAG=${{ github.sha }}
|
||||||
|
|||||||
55
.github/workflows/rust-clippy.yml
vendored
Normal file
55
.github/workflows/rust-clippy.yml
vendored
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
# This workflow uses actions that are not certified by GitHub.
|
||||||
|
# They are provided by a third-party and are governed by
|
||||||
|
# separate terms of service, privacy policy, and support
|
||||||
|
# documentation.
|
||||||
|
# rust-clippy is a tool that runs a bunch of lints to catch common
|
||||||
|
# mistakes in your Rust code and help improve your Rust code.
|
||||||
|
# More details at https://github.com/rust-lang/rust-clippy
|
||||||
|
# and https://rust-lang.github.io/rust-clippy/
|
||||||
|
|
||||||
|
name: rust-clippy analyze
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ "main" ]
|
||||||
|
pull_request:
|
||||||
|
# The branches below must be a subset of the branches above
|
||||||
|
branches: [ "main" ]
|
||||||
|
schedule:
|
||||||
|
- cron: '22 1 * * 1'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
rust-clippy-analyze:
|
||||||
|
name: Run rust-clippy analyzing
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
security-events: write
|
||||||
|
actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v5
|
||||||
|
|
||||||
|
- name: Install Rust toolchain
|
||||||
|
uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af #@v1
|
||||||
|
with:
|
||||||
|
profile: minimal
|
||||||
|
toolchain: stable
|
||||||
|
components: clippy
|
||||||
|
override: true
|
||||||
|
|
||||||
|
- name: Install required cargo
|
||||||
|
run: cargo install clippy-sarif sarif-fmt
|
||||||
|
|
||||||
|
- name: Run rust-clippy
|
||||||
|
run:
|
||||||
|
cargo clippy
|
||||||
|
--all-features
|
||||||
|
--message-format=json | clippy-sarif | tee rust-clippy-results.sarif | sarif-fmt
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
- name: Upload analysis results to GitHub
|
||||||
|
uses: github/codeql-action/upload-sarif@v4
|
||||||
|
with:
|
||||||
|
sarif_file: rust-clippy-results.sarif
|
||||||
|
wait-for-processing: true
|
||||||
1775
Cargo.lock
generated
1775
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
25
Cargo.toml
25
Cargo.toml
@@ -3,28 +3,43 @@ name = "telegram_files_server"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
opt-level = 3
|
||||||
|
debug = false
|
||||||
|
strip = true
|
||||||
|
lto = true
|
||||||
|
codegen-units = 1
|
||||||
|
panic = 'abort'
|
||||||
|
|
||||||
|
[profile.profiling]
|
||||||
|
inherits = "release"
|
||||||
|
debug = true
|
||||||
|
strip = false
|
||||||
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
serde = "1.0.219"
|
serde = "1.0.219"
|
||||||
serde_json = "1.0.140"
|
serde_json = "1.0.140"
|
||||||
|
|
||||||
axum = { version = "0.8.1", features = ["multipart"] }
|
axum = { version = "0.8.1", features = ["multipart"] }
|
||||||
axum_typed_multipart = "0.15.1"
|
axum_typed_multipart = "0.16.3"
|
||||||
|
|
||||||
tracing = "0.1.41"
|
tracing = "0.1.41"
|
||||||
tracing-subscriber = { version = "0.3.19", features = ["env-filter"]}
|
tracing-subscriber = { version = "0.3.19", features = ["env-filter"]}
|
||||||
tower-http = { version = "0.6.2", features = ["trace"] }
|
tower-http = { version = "0.6.2", features = ["trace"] }
|
||||||
sentry-tracing = "0.36.0"
|
sentry-tracing = "0.42.0"
|
||||||
|
|
||||||
tokio = { version = "1.44.2", features = [ "full" ] }
|
tokio = { version = "1.44.2", features = [ "full" ] }
|
||||||
tokio-util = { version = "0.7.14", features = [ "full" ] }
|
tokio-util = { version = "0.7.14", features = [ "full" ] }
|
||||||
axum-prometheus = "0.8.0"
|
axum-prometheus = "0.9.0"
|
||||||
|
|
||||||
futures = "0.3.31"
|
futures = "0.3.31"
|
||||||
|
|
||||||
once_cell = "1.21.1"
|
once_cell = "1.21.1"
|
||||||
teloxide = { git = "https://github.com/teloxide/teloxide.git" }
|
teloxide = "0.17.0"
|
||||||
|
|
||||||
sentry = "0.36.0"
|
sentry = "0.42.0"
|
||||||
|
|
||||||
dotenvy = "0.15.7"
|
dotenvy = "0.15.7"
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
|
|
||||||
use axum::body::Bytes;
|
use axum::body::Bytes;
|
||||||
|
use moka::future::Cache;
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use teloxide::{
|
use teloxide::{
|
||||||
@@ -9,7 +10,6 @@ use teloxide::{
|
|||||||
};
|
};
|
||||||
use tokio::fs::File;
|
use tokio::fs::File;
|
||||||
use tracing::log;
|
use tracing::log;
|
||||||
use moka::future::Cache;
|
|
||||||
|
|
||||||
use super::bot::ROUND_ROBIN_BOT;
|
use super::bot::ROUND_ROBIN_BOT;
|
||||||
use crate::config::CONFIG;
|
use crate::config::CONFIG;
|
||||||
@@ -44,7 +44,6 @@ pub static TEMP_FILES_CACHE: Lazy<Cache<i32, MessageId>> = Lazy::new(|| {
|
|||||||
.build()
|
.build()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
pub async fn upload_file(
|
pub async fn upload_file(
|
||||||
file: Bytes,
|
file: Bytes,
|
||||||
filename: String,
|
filename: String,
|
||||||
@@ -70,7 +69,6 @@ pub async fn upload_file(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub async fn download_file(chat_id: i64, message_id: i32) -> Result<Option<File>, Box<dyn Error>> {
|
pub async fn download_file(chat_id: i64, message_id: i32) -> Result<Option<File>, Box<dyn Error>> {
|
||||||
let bot = ROUND_ROBIN_BOT.get_bot();
|
let bot = ROUND_ROBIN_BOT.get_bot();
|
||||||
|
|
||||||
@@ -84,16 +82,12 @@ pub async fn download_file(chat_id: i64, message_id: i32) -> Result<Option<File>
|
|||||||
{
|
{
|
||||||
Ok(v) => v,
|
Ok(v) => v,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
if let teloxide::RequestError::Api(ref err) = err {
|
if let teloxide::RequestError::Api(teloxide::ApiError::MessageToForwardNotFound) = err {
|
||||||
if let teloxide::ApiError::MessageToForwardNotFound = err {
|
return Ok(None);
|
||||||
return Ok(None);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if let teloxide::RequestError::Api(ref err) = err {
|
if let teloxide::RequestError::Api(teloxide::ApiError::MessageIdInvalid) = err {
|
||||||
if let teloxide::ApiError::MessageIdInvalid = err {
|
return Ok(None);
|
||||||
return Ok(None);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
log::error!("Error: {}", err);
|
log::error!("Error: {}", err);
|
||||||
@@ -103,7 +97,9 @@ pub async fn download_file(chat_id: i64, message_id: i32) -> Result<Option<File>
|
|||||||
|
|
||||||
let file_id = forwarded_message.document().unwrap().file.id.clone();
|
let file_id = forwarded_message.document().unwrap().file.id.clone();
|
||||||
|
|
||||||
TEMP_FILES_CACHE.insert(message_id, forwarded_message.id).await;
|
TEMP_FILES_CACHE
|
||||||
|
.insert(message_id, forwarded_message.id)
|
||||||
|
.await;
|
||||||
|
|
||||||
let path = match bot.get_file(file_id.clone()).await {
|
let path = match bot.get_file(file_id.clone()).await {
|
||||||
Ok(v) => v.path,
|
Ok(v) => v.path,
|
||||||
@@ -116,7 +112,6 @@ pub async fn download_file(chat_id: i64, message_id: i32) -> Result<Option<File>
|
|||||||
Ok(Some(File::open(path).await?))
|
Ok(Some(File::open(path).await?))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub async fn clean_files() -> Result<(), Box<dyn Error>> {
|
pub async fn clean_files() -> Result<(), Box<dyn Error>> {
|
||||||
let bots_folder = "/var/lib/telegram-bot-api/";
|
let bots_folder = "/var/lib/telegram-bot-api/";
|
||||||
let documents_folder_name = "documents";
|
let documents_folder_name = "documents";
|
||||||
|
|||||||
Reference in New Issue
Block a user