]> OzVa Git service - ozva-cloud/commitdiff
feat: remove unzip uploaded feature (#11)
authorsigoden <sigoden@gmail.com>
Sat, 4 Jun 2022 05:01:17 +0000 (13:01 +0800)
committerGitHub <noreply@github.com>
Sat, 4 Jun 2022 05:01:17 +0000 (13:01 +0800)
Use drag&drop/webdav to upload folders

README.md
assets/index.js
src/server.rs

index a57f9ca4ef484a33e5ff14ecea9181a1516f8f15..151cd28026731d1d89dfd30b2461c184b5ee9698 100644 (file)
--- 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
 
 ```
index a9d9498d5867874e0ca6ffb72938c834c99613a3..320c7d4050691b13f95e647f5fd60d21776e0b70 100644 (file)
@@ -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", `
   <tr id="upload${idx}" class="uploader">
     <td class="path cell-name">
index f883f5494548cd8e218dba517ea54362284f156f..95e53b7a54a7da74de021b2e19a4e917dd99a47c 100644 (file)
@@ -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<HeaderValue>) -> Option<PathBuf> {
         let dest = headers.get("Destination")?.to_str().ok()?;
         let uri: Uri = dest.parse().ok()?;