Skip to content

Commit

Permalink
fix mkdir logic (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
tttol authored Jul 6, 2024
1 parent 240ea4a commit 1fc1bd8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
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

0 comments on commit 1fc1bd8

Please sign in to comment.