feat: remove unzip uploaded feature (#11)

Use drag&drop/webdav to upload folders
This commit is contained in:
sigoden 2022-06-04 13:01:17 +08:00 committed by GitHub
parent 0a64762df4
commit 0616602659
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 1 additions and 43 deletions

View file

@ -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
```

View 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">

View 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()?;