From 252d4e83ce7dd77472223a9a8e1a9c41de531aaf Mon Sep 17 00:00:00 2001 From: t-takahashi Date: Tue, 2 Jul 2024 22:06:55 +0900 Subject: [PATCH] fix upload logic --- static/index.html | 2 +- static/upload.html | 14 ++++++++++++-- web/ui_controller.go | 9 ++++++++- web/upload_controller.go | 8 ++++++-- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/static/index.html b/static/index.html index 6c63849..5bfc5f7 100644 --- a/static/index.html +++ b/static/index.html @@ -23,7 +23,7 @@ {{end}}
- + diff --git a/static/upload.html b/static/upload.html index 09821ed..f8c2a43 100644 --- a/static/upload.html +++ b/static/upload.html @@ -10,10 +10,20 @@
MOS3
-
-
+

Upload file

+

Add a file. The file will be uploaded to {{.CurrentPath}}

+
diff --git a/web/ui_controller.go b/web/ui_controller.go index ca32d4b..ba24c41 100644 --- a/web/ui_controller.go +++ b/web/ui_controller.go @@ -25,10 +25,17 @@ func S3Handler(w http.ResponseWriter, r *http.Request) { return } + var currentPath string + if path == "" { + currentPath = "/" + } else { + currentPath = path + } + dataMap := map[string]interface{}{ "S3Objects": s3Objects, "Breadcrumbs": util.GenerateBreadcrumbs(path), - "CurrentPath": path, + "CurrentPath": currentPath, } tmpl, err := template.ParseFiles("static/index.html") diff --git a/web/upload_controller.go b/web/upload_controller.go index f18d4ea..e33a16a 100644 --- a/web/upload_controller.go +++ b/web/upload_controller.go @@ -17,8 +17,12 @@ func UploadIndexHandler(w http.ResponseWriter, r *http.Request) { return } - tmpl.Execute(w, nil) + dataMap := map[string]interface{}{ + "CurrentPath": r.URL.Query().Get("currentPath"), + } + tmpl.Execute(w, dataMap) } + func UploadHandler(w http.ResponseWriter, r *http.Request) { if r.Method != "POST" { http.Error(w, "Invalid request method", http.StatusMethodNotAllowed) @@ -45,5 +49,5 @@ func UploadHandler(w http.ResponseWriter, r *http.Request) { return } - http.Redirect(w, r, "/", http.StatusFound) + http.Redirect(w, r, filepath.Join("/s3", path), http.StatusFound) }