-
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
3 changed files
with
109 additions
and
58 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,109 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>MOS3 - My Own S3</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"> | ||
<form action="/mkdir" method="post"> | ||
<input type="text" name="dirname" placeholder="Directory name"> | ||
<button type="submit">Create Directory</button> | ||
</form> | ||
|
||
<main class="p-3"> | ||
<div class="mx-auto w-3/4 p-3 bg-emerald-800 rounded-xl"> | ||
<div class="flex justify-between"> | ||
<div class="text-lg"> | ||
<a href="/s3" class="text-cyan-400 underline-offset-2 hover:opacity-60">s3:</a> | ||
{{range $key, $value := .Breadcrumbs}} | ||
<span> / <a href="{{$value}}" class="text-cyan-400 underline-offset-2 hover:opacity-60">{{$key}}</a></span> | ||
<span> / <a href="{{$value}}" | ||
class="text-cyan-400 underline-offset-2 hover:opacity-60">{{$key}}</a></span> | ||
{{end}} | ||
</div> | ||
<div id="upload" class="inline-block bg-blue-500 text-white w-auto font-bold py-2 px-2 rounded-full mb-3 hover:opacity-60"> | ||
<a href="/uploadpage?currentPath={{.CurrentPath}}"> | ||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="w-6 h-6 inline"> | ||
<path fillRule="evenodd" d="M12 3.75a.75.75 0 01.75.75v6.75h6.75a.75.75 0 010 1.5h-6.75v6.75a.75.75 0 01-1.5 0v-6.75H4.5a.75.75 0 010-1.5h6.75V4.5a.75.75 0 01.75-.75z" clipRule="evenodd" /> | ||
</svg> | ||
New File | ||
</a> | ||
<div> | ||
<div id="upload" | ||
class="inline-block bg-blue-500 text-white w-auto font-bold py-2 px-2 rounded-full mb-3 hover:opacity-60"> | ||
<a href="/uploadpage?currentPath={{.CurrentPath}}"> | ||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" | ||
class="w-6 h-6 inline"> | ||
<path fillRule="evenodd" | ||
d="M12 3.75a.75.75 0 01.75.75v6.75h6.75a.75.75 0 010 1.5h-6.75v6.75a.75.75 0 01-1.5 0v-6.75H4.5a.75.75 0 010-1.5h6.75V4.5a.75.75 0 01.75-.75z" | ||
clipRule="evenodd" /> | ||
</svg> | ||
New File | ||
</a> | ||
</div> | ||
<div id="mkdir" class="inline-block bg-yellow-500 text-white font-bold py-2 px-2 rounded-full mb-3 hover:opacity-60 cursor-pointer"> | ||
<span> | ||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="w-6 h-6 inline"> | ||
<path fillRule="evenodd" | ||
d="M12 3.75a.75.75 0 01.75.75v6.75h6.75a.75.75 0 010 1.5h-6.75v6.75a.75.75 0 01-1.5 0v-6.75H4.5a.75.75 0 010-1.5h6.75V4.5a.75.75 0 01.75-.75z" | ||
clipRule="evenodd" /> | ||
</svg> | ||
New Dir | ||
</span> | ||
</div> | ||
</div> | ||
</div> | ||
<div id="mkdirDiv" class="border-t-2 border-b-2 border-slate-400 py-3 hidden"> | ||
<p> | ||
<form action="/mkdir" method="post"> | ||
<span class="pl-2 mr-2"> | ||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" | ||
stroke="currentColor" class="size-6 inline"> | ||
<path stroke-linecap="round" stroke-linejoin="round" | ||
d="M2.25 12.75V12A2.25 2.25 0 0 1 4.5 9.75h15A2.25 2.25 0 0 1 21.75 12v.75m-8.69-6.44-2.12-2.12a1.5 1.5 0 0 0-1.061-.44H4.5A2.25 2.25 0 0 0 2.25 6v12a2.25 2.25 0 0 0 2.25 2.25h15A2.25 2.25 0 0 0 21.75 18V9a2.25 2.25 0 0 0-2.25-2.25h-5.379a1.5 1.5 0 0 1-1.06-.44Z" /> | ||
</svg> | ||
</span> | ||
<span> | ||
<input type="text" name="dirname" class="text-black rounded-full px-2 py-1" placeholder="Directory name"> | ||
<button type="submit" | ||
class="inline-block bg-yellow-500 text-white w-auto font-bold py-1 px-2 rounded-full hover:opacity-60"> | ||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" | ||
stroke="currentColor" class="size-6 inline"> | ||
<path stroke-linecap="round" stroke-linejoin="round" | ||
d="M3 16.5v2.25A2.25 2.25 0 0 0 5.25 21h13.5A2.25 2.25 0 0 0 21 18.75V16.5m-13.5-9L12 3m0 0 4.5 4.5M12 3v13.5" /> | ||
</svg> | ||
upload | ||
</button> | ||
</span> | ||
</form> | ||
</p> | ||
</div> | ||
{{range .S3Objects}} | ||
<div class="border-b-2 border-slate-400 py-3 hover:opacity-60"> | ||
<p> | ||
{{if .IsDir}} | ||
<span class="pl-2 mr-2"> | ||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-6 inline"> | ||
<path stroke-linecap="round" stroke-linejoin="round" d="M2.25 12.75V12A2.25 2.25 0 0 1 4.5 9.75h15A2.25 2.25 0 0 1 21.75 12v.75m-8.69-6.44-2.12-2.12a1.5 1.5 0 0 0-1.061-.44H4.5A2.25 2.25 0 0 0 2.25 6v12a2.25 2.25 0 0 0 2.25 2.25h15A2.25 2.25 0 0 0 21.75 18V9a2.25 2.25 0 0 0-2.25-2.25h-5.379a1.5 1.5 0 0 1-1.06-.44Z" /> | ||
</svg> | ||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" | ||
stroke="currentColor" class="size-6 inline"> | ||
<path stroke-linecap="round" stroke-linejoin="round" | ||
d="M2.25 12.75V12A2.25 2.25 0 0 1 4.5 9.75h15A2.25 2.25 0 0 1 21.75 12v.75m-8.69-6.44-2.12-2.12a1.5 1.5 0 0 0-1.061-.44H4.5A2.25 2.25 0 0 0 2.25 6v12a2.25 2.25 0 0 0 2.25 2.25h15A2.25 2.25 0 0 0 21.75 18V9a2.25 2.25 0 0 0-2.25-2.25h-5.379a1.5 1.5 0 0 1-1.06-.44Z" /> | ||
</svg> | ||
</span> | ||
<span><a href="{{.FullPath}}" class="text-lg">{{.Name}}</a></span> | ||
{{else}} | ||
<span class="pl-2 mr-2"> | ||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="size-6 inline"> | ||
<path d="M5.625 1.5c-1.036 0-1.875.84-1.875 1.875v17.25c0 1.035.84 1.875 1.875 1.875h12.75c1.035 0 1.875-.84 1.875-1.875V12.75A3.75 3.75 0 0 0 16.5 9h-1.875a1.875 1.875 0 0 1-1.875-1.875V5.25A3.75 3.75 0 0 0 9 1.5H5.625Z" /> | ||
<path d="M12.971 1.816A5.23 5.23 0 0 1 14.25 5.25v1.875c0 .207.168.375.375.375H16.5a5.23 5.23 0 0 1 3.434 1.279 9.768 9.768 0 0 0-6.963-6.963Z" /> | ||
</svg> | ||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" | ||
class="size-6 inline"> | ||
<path | ||
d="M5.625 1.5c-1.036 0-1.875.84-1.875 1.875v17.25c0 1.035.84 1.875 1.875 1.875h12.75c1.035 0 1.875-.84 1.875-1.875V12.75A3.75 3.75 0 0 0 16.5 9h-1.875a1.875 1.875 0 0 1-1.875-1.875V5.25A3.75 3.75 0 0 0 9 1.5H5.625Z" /> | ||
<path | ||
d="M12.971 1.816A5.23 5.23 0 0 1 14.25 5.25v1.875c0 .207.168.375.375.375H16.5a5.23 5.23 0 0 1 3.434 1.279 9.768 9.768 0 0 0-6.963-6.963Z" /> | ||
</svg> | ||
</span> | ||
<span><a href="{{.FullPath}}?action=dl" class="text-lg">{{.Name}}</a></span> | ||
{{end}} | ||
</p> | ||
</div> | ||
</div> | ||
{{end}} | ||
</div> | ||
</main> | ||
</body> | ||
<script> | ||
document.querySelector("#upload").addEventListener("click", () => { | ||
document.querySelector("#uploadFile").click(); | ||
document.querySelector("#uploadForm").classList.remove("hidden"); | ||
document.querySelector("#mkdir").addEventListener("click", () => { | ||
document.querySelector("#mkdirDiv").classList.remove("hidden"); | ||
}); | ||
</script> | ||
</html> | ||
|
||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |
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