recycleactor commited on
Commit
835983b
·
verified ·
1 Parent(s): 3e8524e

Upload main.rs

Browse files
Files changed (1) hide show
  1. src/main.rs +15 -8
src/main.rs CHANGED
@@ -910,6 +910,12 @@ async fn inject_audio_metadata(mut bytes: Vec<u8>, ext: &str, meta: &AudioTagMet
910
  return bytes;
911
  }
912
 
 
 
 
 
 
 
913
  let tag_type = if ext.eq_ignore_ascii_case("flac") {
914
  TagType::VorbisComments
915
  } else {
@@ -1073,21 +1079,21 @@ async fn send_audio(
1073
  let filename = format!("track_{}.{}", q.id, ext);
1074
 
1075
  // Загружаем в Telegram через отдельный клиент.
1076
- // Если аплоад виснет по сети, важно быстро вернуть ошибку боту,
1077
- // чтобы он раньше переключился на fallback по URL.
1078
  let tg_url = format!("https://api.telegram.org/bot{}/sendAudio", bot_token);
1079
  let tg_http = reqwest::Client::builder()
1080
  .https_only(true)
1081
- .connect_timeout(Duration::from_secs(8))
1082
- .timeout(Duration::from_secs(18))
1083
- .tcp_keepalive(Duration::from_secs(30))
1084
  .build()
1085
  .unwrap();
1086
 
1087
  let mut tg_json: Option<serde_json::Value> = None;
1088
  let mut last_tg_err: Option<String> = None;
1089
 
1090
- for attempt in 1..=2u8 {
 
 
1091
  let part = reqwest::multipart::Part::bytes(dec.clone())
1092
  .file_name(filename.clone())
1093
  .mime_str(mime)
@@ -1106,6 +1112,7 @@ async fn send_audio(
1106
  Ok(j) => {
1107
  if status.is_success() && j.get("ok").and_then(|v| v.as_bool()) == Some(true) {
1108
  tg_json = Some(j);
 
1109
  break;
1110
  }
1111
  let desc = j
@@ -1128,8 +1135,8 @@ async fn send_audio(
1128
  }
1129
  }
1130
 
1131
- if attempt < 2 {
1132
- tokio::time::sleep(Duration::from_secs(1)).await;
1133
  }
1134
  }
1135
 
 
910
  return bytes;
911
  }
912
 
913
+ // Временно отключаем добавление метаданных для FLAC - возможно lofty ломает файл
914
+ if ext.eq_ignore_ascii_case("flac") {
915
+ tracing::warn!("Skipping metadata injection for FLAC to avoid corruption");
916
+ return bytes;
917
+ }
918
+
919
  let tag_type = if ext.eq_ignore_ascii_case("flac") {
920
  TagType::VorbisComments
921
  } else {
 
1079
  let filename = format!("track_{}.{}", q.id, ext);
1080
 
1081
  // Загружаем в Telegram через отдельный клиент.
 
 
1082
  let tg_url = format!("https://api.telegram.org/bot{}/sendAudio", bot_token);
1083
  let tg_http = reqwest::Client::builder()
1084
  .https_only(true)
1085
+ .connect_timeout(Duration::from_secs(10))
1086
+ .timeout(Duration::from_secs(30))
1087
+ .tcp_keepalive(Duration::from_secs(20))
1088
  .build()
1089
  .unwrap();
1090
 
1091
  let mut tg_json: Option<serde_json::Value> = None;
1092
  let mut last_tg_err: Option<String> = None;
1093
 
1094
+ for attempt in 1..=3u8 {
1095
+ tracing::info!("Telegram sendAudio attempt {} for track {} ({} bytes)", attempt, q.id, dec.len());
1096
+
1097
  let part = reqwest::multipart::Part::bytes(dec.clone())
1098
  .file_name(filename.clone())
1099
  .mime_str(mime)
 
1112
  Ok(j) => {
1113
  if status.is_success() && j.get("ok").and_then(|v| v.as_bool()) == Some(true) {
1114
  tg_json = Some(j);
1115
+ tracing::info!("Telegram sendAudio success on attempt {}", attempt);
1116
  break;
1117
  }
1118
  let desc = j
 
1135
  }
1136
  }
1137
 
1138
+ if attempt < 3 {
1139
+ tokio::time::sleep(Duration::from_secs(3)).await;
1140
  }
1141
  }
1142