Split files differently

This commit is contained in:
blank X 2021-06-27 08:24:01 +07:00
parent 4de4bb6e3d
commit 2e029df64d
Signed by: blankie
GPG Key ID: CC15FC822C7F61F5
1 changed files with 11 additions and 6 deletions

View File

@ -611,12 +611,13 @@ pub async fn upload_worker(
}; };
let total_size = file.seek(SeekFrom::End(0)).await.unwrap(); let total_size = file.seek(SeekFrom::End(0)).await.unwrap();
file.seek(SeekFrom::Start(0)).await.unwrap(); file.seek(SeekFrom::Start(0)).await.unwrap();
let parts = (total_size as f64 / (2000.0 * 1024.0 * 1024.0)).ceil() as usize; let mut sent_size = 0;
for i in 0..parts { let split = total_size > 2000 * 1024 * 1024;
let filename = if parts == 1 { for i in 0.. {
video_filename.clone() let filename = if split {
} else {
format!("{}.part{:02}", &video_filename, i) format!("{}.part{:02}", &video_filename, i)
} else {
video_filename.clone()
}; };
let message = tclient let message = tclient
.send_message( .send_message(
@ -666,7 +667,7 @@ pub async fn upload_worker(
} }
}; };
} }
let mut size = total_size - file.stream_position().await.unwrap(); let mut size = total_size - sent_size;
if size > 2000 * 1024 * 1024 { if size > 2000 * 1024 * 1024 {
size = 2000 * 1024 * 1024; size = 2000 * 1024 * 1024;
} }
@ -717,6 +718,7 @@ pub async fn upload_worker(
} }
} }
}; };
sent_size = file.stream_position().await.unwrap();
if let Ok(mut message) = message { if let Ok(mut message) = message {
if let Err(err) = message.delete().await { if let Err(err) = message.delete().await {
eprintln!("Failed to delete uploading message: {:?}", err); eprintln!("Failed to delete uploading message: {:?}", err);
@ -761,6 +763,9 @@ pub async fn upload_worker(
}; };
} }
} }
if sent_size >= total_size {
break;
}
} }
drop(file); drop(file);
if success { if success {