mirror of
https://github.com/flibusta-apps/telegram_files_cache_server.git
synced 2025-12-06 14:45:36 +01:00
Fix
This commit is contained in:
@@ -83,6 +83,7 @@ pub async fn cache_file(
|
|||||||
|
|
||||||
pub async fn download_from_cache(
|
pub async fn download_from_cache(
|
||||||
cached_data: cached_file::Data,
|
cached_data: cached_file::Data,
|
||||||
|
db: Database
|
||||||
) -> Option<DownloadResult> {
|
) -> Option<DownloadResult> {
|
||||||
let response_task = tokio::task::spawn(download_from_telegram_files(cached_data.message_id, cached_data.chat_id));
|
let response_task = tokio::task::spawn(download_from_telegram_files(cached_data.message_id, cached_data.chat_id));
|
||||||
let filename_task = tokio::task::spawn(get_filename(cached_data.object_id, cached_data.object_type.clone()));
|
let filename_task = tokio::task::spawn(get_filename(cached_data.object_id, cached_data.object_type.clone()));
|
||||||
@@ -91,6 +92,14 @@ pub async fn download_from_cache(
|
|||||||
let response = match response_task.await.unwrap() {
|
let response = match response_task.await.unwrap() {
|
||||||
Ok(v) => v,
|
Ok(v) => v,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
db.cached_file()
|
||||||
|
.delete(cached_file::object_id_object_type(cached_data.object_id, cached_data.object_type.clone()))
|
||||||
|
.exec()
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
tokio::spawn(cache_file(cached_data.object_id, cached_data.object_type, db));
|
||||||
|
|
||||||
log::error!("{:?}", err);
|
log::error!("{:?}", err);
|
||||||
return None;
|
return None;
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -27,12 +27,12 @@ async fn download_cached_file(
|
|||||||
Path((object_id, object_type)): Path<(i32, String)>,
|
Path((object_id, object_type)): Path<(i32, String)>,
|
||||||
Extension(Ext { db }): Extension<Ext>
|
Extension(Ext { db }): Extension<Ext>
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
let cached_file = match get_cached_file_or_cache(object_id, object_type, db).await {
|
let cached_file = match get_cached_file_or_cache(object_id, object_type, db.clone()).await {
|
||||||
Some(cached_file) => cached_file,
|
Some(cached_file) => cached_file,
|
||||||
None => return StatusCode::NO_CONTENT.into_response(),
|
None => return StatusCode::NO_CONTENT.into_response(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let data = match download_from_cache(cached_file).await {
|
let data = match download_from_cache(cached_file, db).await {
|
||||||
Some(v) => v,
|
Some(v) => v,
|
||||||
None => {
|
None => {
|
||||||
return StatusCode::NO_CONTENT.into_response();
|
return StatusCode::NO_CONTENT.into_response();
|
||||||
|
|||||||
Reference in New Issue
Block a user