mirror of
https://github.com/Drop-OSS/drop-app.git
synced 2025-11-14 08:41:21 +10:00
fixed multi-chunk downloads
This commit is contained in:
@ -3,8 +3,8 @@ use crate::db::DatabaseImpls;
|
||||
use crate::downloads::manifest::DropDownloadContext;
|
||||
use crate::DB;
|
||||
use log::info;
|
||||
use std::{fs::OpenOptions, io::{BufWriter, Seek, SeekFrom, Write}};
|
||||
use urlencoding::encode;
|
||||
use std::io::{BufWriter, Seek, SeekFrom, Write};
|
||||
|
||||
pub fn download_game_chunk(ctx: DropDownloadContext) {
|
||||
let base_url = DB.fetch_base_url();
|
||||
@ -14,7 +14,10 @@ pub fn download_game_chunk(ctx: DropDownloadContext) {
|
||||
.join(&format!(
|
||||
"/api/v1/client/chunk?id={}&version={}&name={}&chunk={}",
|
||||
// Encode the parts we don't trust
|
||||
ctx.game_id, encode(&ctx.version), encode(&ctx.file_name), ctx.index
|
||||
ctx.game_id,
|
||||
encode(&ctx.version),
|
||||
encode(&ctx.file_name),
|
||||
ctx.index
|
||||
))
|
||||
.unwrap();
|
||||
|
||||
@ -26,16 +29,15 @@ pub fn download_game_chunk(ctx: DropDownloadContext) {
|
||||
.send()
|
||||
.unwrap();
|
||||
|
||||
let mut file_lock = ctx.file.lock().unwrap();
|
||||
let mut file = OpenOptions::new().write(true).open(ctx.path).unwrap();
|
||||
|
||||
if ctx.offset != 0 {
|
||||
file_lock
|
||||
file
|
||||
.seek(SeekFrom::Start(ctx.offset))
|
||||
.expect("Failed to seek to file offset");
|
||||
}
|
||||
|
||||
let mut stream = BufWriter::with_capacity(1024 * 1024, file_lock.try_clone().unwrap());
|
||||
drop(file_lock);
|
||||
let mut stream = BufWriter::with_capacity(1024 * 1024, file);
|
||||
|
||||
response.copy_to(&mut stream).unwrap();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user