mirror of
https://github.com/flibusta-apps/telegram_files_server.git
synced 2025-12-06 12:35:39 +01:00
Compare commits
5 Commits
07683cfc0b
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 6d34fde8ca | |||
| ea8290f74c | |||
|
|
8336c8598e | ||
| 6e9ef95aaf | |||
|
|
d2519bb9b7 |
4
.github/workflows/rust-clippy.yml
vendored
4
.github/workflows/rust-clippy.yml
vendored
@@ -28,7 +28,7 @@ jobs:
|
|||||||
actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
|
actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v5
|
||||||
|
|
||||||
- name: Install Rust toolchain
|
- name: Install Rust toolchain
|
||||||
uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af #@v1
|
uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af #@v1
|
||||||
@@ -49,7 +49,7 @@ jobs:
|
|||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
|
|
||||||
- name: Upload analysis results to GitHub
|
- name: Upload analysis results to GitHub
|
||||||
uses: github/codeql-action/upload-sarif@v3
|
uses: github/codeql-action/upload-sarif@v4
|
||||||
with:
|
with:
|
||||||
sarif_file: rust-clippy-results.sarif
|
sarif_file: rust-clippy-results.sarif
|
||||||
wait-for-processing: true
|
wait-for-processing: true
|
||||||
|
|||||||
@@ -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