Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix mkdir logic #10

Merged
merged 1 commit into from
Jul 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
</svg>
</span>
<span>
<input type="hidden" name="currentPath" value="{{.CurrentPath}}">
<input type="text" name="dirname" class="text-black rounded-full px-2 py-1"
placeholder="Directory name">
<button type="submit"
Expand Down
9 changes: 7 additions & 2 deletions web/dir_controller.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package web

import (
"log/slog"
"net/http"
"os"
"path/filepath"
Expand All @@ -12,14 +13,18 @@ func MkdirHandler(w http.ResponseWriter, r *http.Request) {
return
}

currentPath := r.FormValue("currentPath")
dirname := r.FormValue("dirname")
err := os.Mkdir(filepath.Join(UPLOAD_DIR, dirname), os.ModePerm)
dir := filepath.Join(UPLOAD_DIR, currentPath, dirname)
err := os.Mkdir(dir, os.ModePerm)
if err != nil {
slog.Error("failed to mkdir", "target directory", dir, "error", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
slog.Info("Success mkdir", "target directory", dir)

http.Redirect(w, r, "/s3", http.StatusFound)
http.Redirect(w, r, "/s3/"+currentPath, http.StatusFound)
}

func RmdirHandler(w http.ResponseWriter, r *http.Request) {
Expand Down
Loading