From 0616602659969354d6d125b972f93e7e56c21ed3 Mon Sep 17 00:00:00 2001 From: sigoden Date: Sat, 4 Jun 2022 13:01:17 +0800 Subject: [PATCH] feat: remove unzip uploaded feature (#11) Use drag&drop/webdav to upload folders --- README.md | 9 +-------- assets/index.js | 3 --- src/server.rs | 32 -------------------------------- 3 files changed, 1 insertion(+), 43 deletions(-) diff --git a/README.md b/README.md index a57f9ca..151cd28 100644 --- a/README.md +++ b/README.md @@ -15,9 +15,8 @@ Duf is a fully functional file server. - Upload files and folders (Drag & Drop) - Delete files - Basic authentication -- Upload zip file then unzip - Partial responses (Parallel/Resume download) -- Support https/tls +- Support https - Support webdav - Easy to use with curl @@ -128,12 +127,6 @@ Upload a file curl --upload-file some-file http://127.0.0.1:5000/some-file ``` -Unzip zip file when unload - -``` -curl --upload-file some-folder.zip http://127.0.0.1:5000/some-folder.zip?unzip -``` - Delete a file/folder ``` diff --git a/assets/index.js b/assets/index.js index a9d9498..320c7d4 100644 --- a/assets/index.js +++ b/assets/index.js @@ -45,9 +45,6 @@ class Uploader { upload() { const { file, idx, name } = this; let url = getUrl(name); - if (file.name == baseDir + ".zip") { - url += "?unzip"; - } $uploadersTable.insertAdjacentHTML("beforeend", ` diff --git a/src/server.rs b/src/server.rs index f883f54..95e53b7 100644 --- a/src/server.rs +++ b/src/server.rs @@ -1,7 +1,6 @@ use crate::{Args, BoxResult}; use async_walkdir::WalkDir; -use async_zip::read::seek::ZipFileReader; use async_zip::write::{EntryOptions, ZipFileWriter}; use async_zip::Compression; use chrono::{Local, TimeZone, Utc}; @@ -276,15 +275,6 @@ impl InnerService { io::copy(&mut body_reader, &mut file).await?; - let query = req.uri().query().unwrap_or_default(); - if query == "unzip" { - if let Err(e) = self.unzip_file(path).await { - eprintln!("Failed to unzip {}, {}", path.display(), e); - status!(res, StatusCode::BAD_REQUEST); - } - fs::remove_file(&path).await?; - } - status!(res, StatusCode::CREATED); Ok(()) } @@ -640,28 +630,6 @@ impl InnerService { .unwrap_or_default() } - async fn unzip_file(&self, path: &Path) -> BoxResult<()> { - let root = path.parent().unwrap(); - let mut zip = ZipFileReader::new(File::open(&path).await?).await?; - for i in 0..zip.entries().len() { - let entry = &zip.entries()[i]; - let entry_name = entry.name(); - let entry_path = root.join(entry_name); - if entry_name.ends_with('/') { - fs::create_dir_all(entry_path).await?; - } else { - if !self.args.allow_delete && fs::metadata(&entry_path).await.is_ok() { - continue; - } - ensure_path_parent(&entry_path).await?; - let mut outfile = fs::File::create(&entry_path).await?; - let mut reader = zip.entry_reader(i).await?; - io::copy(&mut reader, &mut outfile).await?; - } - } - Ok(()) - } - fn extract_dest(&self, headers: &HeaderMap) -> Option { let dest = headers.get("Destination")?.to_str().ok()?; let uri: Uri = dest.parse().ok()?;