diff --git a/static/index.html b/static/index.html index 5bfc5f7..ed4908d 100644 --- a/static/index.html +++ b/static/index.html @@ -1,65 +1,109 @@ + MOS3 - My Own S3 +
MOS3
-
-
- - -
- +
s3: {{range $key, $value := .Breadcrumbs}} - / {{$key}} + / {{$key}} {{end}}
-
- - - - - New File - +
+ +
+ + + + + New Dir + +
+ {{range .S3Objects}}

{{if .IsDir}} - - - + + + {{.Name}} {{else}} - - - - + + + + {{.Name}} {{end}}

-
+
{{end}}
- + + \ No newline at end of file diff --git a/web/dir_controller.go b/web/dir_controller.go new file mode 100644 index 0000000..8da1be7 --- /dev/null +++ b/web/dir_controller.go @@ -0,0 +1,39 @@ +package web + +import ( + "net/http" + "os" + "path/filepath" +) + +func MkdirHandler(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + http.Error(w, "Invalid request method", http.StatusMethodNotAllowed) + return + } + + dirname := r.FormValue("dirname") + err := os.Mkdir(filepath.Join(UPLOAD_DIR, dirname), os.ModePerm) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + http.Redirect(w, r, "/s3", http.StatusFound) +} + +func RmdirHandler(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + http.Error(w, "Invalid request method", http.StatusMethodNotAllowed) + return + } + + dirname := r.FormValue("dirname") + err := os.Remove(filepath.Join(UPLOAD_DIR, dirname)) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + http.Redirect(w, r, "/", http.StatusFound) +} diff --git a/web/ui_controller.go b/web/ui_controller.go index ba24c41..0fb3152 100644 --- a/web/ui_controller.go +++ b/web/ui_controller.go @@ -82,38 +82,6 @@ func RenameHandler(w http.ResponseWriter, r *http.Request) { http.Redirect(w, r, "/", http.StatusFound) } -func MkdirHandler(w http.ResponseWriter, r *http.Request) { - if r.Method != "POST" { - http.Error(w, "Invalid request method", http.StatusMethodNotAllowed) - return - } - - dirname := r.FormValue("dirname") - err := os.Mkdir(filepath.Join(UPLOAD_DIR, dirname), os.ModePerm) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - http.Redirect(w, r, "/", http.StatusFound) -} - -func RmdirHandler(w http.ResponseWriter, r *http.Request) { - if r.Method != "POST" { - http.Error(w, "Invalid request method", http.StatusMethodNotAllowed) - return - } - - dirname := r.FormValue("dirname") - err := os.Remove(filepath.Join(UPLOAD_DIR, dirname)) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - http.Redirect(w, r, "/", http.StatusFound) -} - func RenamedirHandler(w http.ResponseWriter, r *http.Request) { if r.Method != "POST" { http.Error(w, "Invalid request method", http.StatusMethodNotAllowed)