Browse Source

feat: remove unzip uploaded feature (#11)

Use drag&drop/webdav to upload folders
pull/13/head
sigoden 3 years ago committed by GitHub
parent
commit
0616602659
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      README.md
  2. 3
      assets/index.js
  3. 32
      src/server.rs

9
README.md

@ -15,9 +15,8 @@ Duf is a fully functional file server. @@ -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 @@ -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
```

3
assets/index.js

@ -45,9 +45,6 @@ class Uploader { @@ -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">

32
src/server.rs

@ -1,7 +1,6 @@ @@ -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 { @@ -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 { @@ -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()?;

Loading…
Cancel
Save