mirror of
https://github.com/Bluemangoo/sekai-unpacker.git
synced 2026-09-20 00:06:52 +08:00
fix tons of bugs
This commit is contained in:
@@ -7,6 +7,7 @@ use communicator::http::{json_from_request, send, send_error};
|
||||
use h2::RecvStream;
|
||||
use h2::server::SendResponse;
|
||||
use http::{Request, Response};
|
||||
use log::debug;
|
||||
|
||||
pub async fn download(
|
||||
mut request: Request<RecvStream>,
|
||||
@@ -43,58 +44,37 @@ pub async fn download(
|
||||
}
|
||||
let (dir, single_file) = dir.unwrap();
|
||||
|
||||
let dir_base = std::env::temp_dir()
|
||||
.join("sekai-updater")
|
||||
.join("extract")
|
||||
.join(&context.sync_context.region);
|
||||
|
||||
let files = if !dir.is_dir() {
|
||||
if context.sync_context.filters.file_ext.is_empty()
|
||||
|| dir.extension().is_some_and(|t| {
|
||||
context
|
||||
.sync_context
|
||||
.filters
|
||||
.file_ext
|
||||
.contains(&t.to_str().unwrap().to_lowercase())
|
||||
})
|
||||
{
|
||||
vec![(
|
||||
dir.clone(),
|
||||
dir.strip_prefix(&dir_base)
|
||||
.unwrap()
|
||||
.to_string_lossy()
|
||||
.to_string(),
|
||||
)]
|
||||
} else {
|
||||
vec![]
|
||||
}
|
||||
let files = if context.sync_context.filters.file_ext.is_empty() {
|
||||
find_files(&dir)
|
||||
} else {
|
||||
let files = if context.sync_context.filters.file_ext.is_empty() {
|
||||
find_files(&dir)
|
||||
} else {
|
||||
find_files_by_extensions(&dir, &context.sync_context.filters.file_ext)
|
||||
};
|
||||
if let Err(error) = files {
|
||||
send_error(send_response, error.into());
|
||||
return Ok(());
|
||||
}
|
||||
let base = dir.strip_prefix(&dir_base).unwrap();
|
||||
let base_str = if single_file {
|
||||
base.parent().unwrap().to_str().unwrap()
|
||||
} else {
|
||||
base.to_str().unwrap()
|
||||
};
|
||||
files
|
||||
.unwrap()
|
||||
.iter()
|
||||
.map(|p| {
|
||||
let raw = p.clone();
|
||||
let name = p.strip_prefix(&dir).unwrap();
|
||||
let path = format!("{}/{}", base_str, name.to_string_lossy());
|
||||
(raw, path)
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
find_files_by_extensions(&dir, &context.sync_context.filters.file_ext)
|
||||
};
|
||||
if let Err(error) = files {
|
||||
send_error(send_response, error.into());
|
||||
return Ok(());
|
||||
}
|
||||
let files = files
|
||||
.unwrap()
|
||||
.iter()
|
||||
.map(|p| {
|
||||
let raw = p.clone();
|
||||
let name = p.strip_prefix(&dir).unwrap();
|
||||
debug!("{} {}", p.to_string_lossy(), single_file);
|
||||
let path = if context.sync_context.exact_single_file_bundle
|
||||
&& single_file
|
||||
{
|
||||
format!(
|
||||
"{}/{}",
|
||||
name.parent().unwrap().parent().unwrap().to_string_lossy(),
|
||||
p.file_name().unwrap().to_string_lossy()
|
||||
)
|
||||
} else {
|
||||
name.to_string_lossy().to_string()
|
||||
};
|
||||
|
||||
(raw, path)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let response = Response::builder()
|
||||
.status(200)
|
||||
|
||||
Reference in New Issue
Block a user