-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
210 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>MOS3 - Upload file</title> | ||
<script src="https://cdn.tailwindcss.com"></script> | ||
</head> | ||
<body class="bg-emerald-950 text-white"> | ||
<header class="bg-emerald-400 text-white p-4 text-center font-black text-4xl"><a href="/s3">MOS3</a></header> | ||
<main class="p-3"> | ||
<div class="mx-auto w-3/4 p-3 bg-emerald-800 rounded-xl"> | ||
<div class="flex justify-between"> | ||
<form id="uploadForm" class="inline" action="/upload" method="post" enctype="multipart/form-data"> | ||
<input id="uploadFile" type="file" name="file"> | ||
<input type="hidden" name="currentPath" value="{{.CurrentPath}}"> | ||
</form> | ||
</div> | ||
</div> | ||
</main> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
package web | ||
|
||
import ( | ||
"log/slog" | ||
"net/http" | ||
"os" | ||
"path/filepath" | ||
"text/template" | ||
|
||
"github.com/tttol/mos3/core/util" | ||
) | ||
|
||
func S3Handler(w http.ResponseWriter, r *http.Request) { | ||
slog.Info("S3Handler is called.") | ||
path := r.URL.Path[len("/s3/"):] | ||
if r.URL.Query().Get("action") == "dl" { | ||
download(path) | ||
return | ||
} | ||
|
||
s3Objects, err := util.GenerateS3Objects(r, UPLOAD_DIR, path) | ||
if err != nil { | ||
slog.Error("GenerateS3Objects error", "error", err) | ||
http.Error(w, err.Error(), http.StatusInternalServerError) | ||
return | ||
} | ||
|
||
dataMap := map[string]interface{}{ | ||
"S3Objects": s3Objects, | ||
"Breadcrumbs": util.GenerateBreadcrumbs(path), | ||
"CurrentPath": path, | ||
} | ||
|
||
tmpl, err := template.ParseFiles("static/index.html") | ||
if err != nil { | ||
slog.Error("template file error", "error", err) | ||
http.Error(w, err.Error(), http.StatusInternalServerError) | ||
return | ||
} | ||
|
||
slog.Info("dataMap", "dataMap", dataMap) | ||
tmpl.Execute(w, dataMap) | ||
} | ||
|
||
func DeleteHandler(w http.ResponseWriter, r *http.Request) { | ||
if r.Method != "POST" { | ||
http.Error(w, "Invalid request method", http.StatusMethodNotAllowed) | ||
return | ||
} | ||
|
||
filename := r.FormValue("filename") | ||
err := os.Remove(filepath.Join(UPLOAD_DIR, filename)) | ||
if err != nil { | ||
http.Error(w, err.Error(), http.StatusInternalServerError) | ||
return | ||
} | ||
|
||
http.Redirect(w, r, "/", http.StatusFound) | ||
} | ||
|
||
func RenameHandler(w http.ResponseWriter, r *http.Request) { | ||
if r.Method != "POST" { | ||
http.Error(w, "Invalid request method", http.StatusMethodNotAllowed) | ||
return | ||
} | ||
|
||
oldFilename := r.FormValue("oldFilename") | ||
newFilename := r.FormValue("newFilename") | ||
err := os.Rename(filepath.Join(UPLOAD_DIR, oldFilename), filepath.Join(UPLOAD_DIR, newFilename)) | ||
if err != nil { | ||
http.Error(w, err.Error(), http.StatusInternalServerError) | ||
return | ||
} | ||
|
||
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) | ||
return | ||
} | ||
|
||
oldDirname := r.FormValue("oldDirname") | ||
newDirname := r.FormValue("newDirname") | ||
err := os.Rename(filepath.Join(UPLOAD_DIR, oldDirname), filepath.Join(UPLOAD_DIR, newDirname)) | ||
if err != nil { | ||
http.Error(w, err.Error(), http.StatusInternalServerError) | ||
return | ||
} | ||
|
||
http.Redirect(w, r, "/", http.StatusFound) | ||
} | ||
|
||
func download(path string) { | ||
slog.Info("Download file", "path", path) | ||
} |
Oops, something went wrong.