Add support for HEAD method and parent folder link

This commit is contained in:
Melon 2024-03-18 21:01:18 +00:00
parent d7b6f38f40
commit f2a9788c49
Signed by: melon
GPG Key ID: 6C9D970C50D26A25
3 changed files with 10 additions and 0 deletions

View File

@ -49,6 +49,9 @@ type fileInfo struct {
}
func (r *routeCtx) handleDirList(rw http.ResponseWriter, req *http.Request) {
if req.Method == http.MethodHead {
return
}
openDir, err := os.ReadDir(filepath.Join(r.basePath, req.URL.Path))
if err != nil {
http.Error(rw, "404 Not Found", http.StatusNotFound)

View File

@ -29,6 +29,11 @@
<th>Last Modified</th>
<th>Size</th>
</tr>
<tr>
<td class="bold"><a href="../">../</a></td>
<td></td>
<td></td>
</tr>
{{range .Files}}
<tr>
<td class="bold"><a href="{{ .URL }}">{{ .Name }}</a></td>

View File

@ -59,8 +59,10 @@ func Router(db *database.Queries, name, basePath string, repository []string) ht
rWeb := httprouter.New()
rWeb.PUT("/*filepath", base.repoAuth(base.handlePut))
rWeb.GET("/", base.handleFiles)
rWeb.HEAD("/", base.handleFiles)
for _, repo := range repository {
rWeb.GET(path.Join("/", repo, "*filepath"), base.handleFiles)
rWeb.HEAD(path.Join("/", repo, "*filepath"), base.handleFiles)
}
mux := http.NewServeMux()