Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6ae09962ad | ||
|
|
17e3e21e56 | ||
|
|
334b64ca6d | ||
|
|
9dc505af17 |
30
main.go
30
main.go
@@ -99,6 +99,7 @@ func endpoints(foo http.HandlerFunc) http.HandlerFunc {
|
|||||||
fmt.Fprintln(w, err.Error())
|
fmt.Fprintln(w, err.Error())
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
setContentTypeIfMedia(w, r)
|
||||||
foo(w, r)
|
foo(w, r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -145,7 +146,7 @@ func withDel(foo http.HandlerFunc) http.HandlerFunc {
|
|||||||
if len(match) > 0 {
|
if len(match) > 0 {
|
||||||
match = bytes.Split(match, []byte(`href="`))[1]
|
match = bytes.Split(match, []byte(`href="`))[1]
|
||||||
match = match[:len(match)-1]
|
match = match[:len(match)-1]
|
||||||
b[i] = []byte(fmt.Sprintf(`<a href="%s/%s"><input type="button" value="❌" style="padding: .40em 1em .10em 1em; margin-right: .5em"/></a> %s`, match, ENDPOINT_DELETE, b[i]))
|
b[i] = []byte(fmt.Sprintf(`<a href="%s/%s"><input type="button" value="❌" style="padding: .40em 1em .10em 1em; margin-right: .5em" onclick='return confirm("Delete "+%q+"?");'></input></a> %s`, match, ENDPOINT_DELETE, match, b[i]))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
buff.Write(b[i])
|
buff.Write(b[i])
|
||||||
@@ -189,7 +190,7 @@ func del(w http.ResponseWriter, r *http.Request) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
err = os.Remove(p)
|
err = os.RemoveAll(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -201,3 +202,28 @@ func toRealPath(p string) string {
|
|||||||
d := path.Join(fs.Get("d").GetString())
|
d := path.Join(fs.Get("d").GetString())
|
||||||
return path.Join(d, p)
|
return path.Join(d, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func setContentTypeIfMedia(w http.ResponseWriter, r *http.Request) {
|
||||||
|
switch strings.ToLower(path.Ext(r.URL.Path)) {
|
||||||
|
case ".mp4":
|
||||||
|
w.Header().Set("Content-Type", "video/mp4")
|
||||||
|
case ".webm":
|
||||||
|
w.Header().Set("Content-Type", "video/webm")
|
||||||
|
case ".mkv":
|
||||||
|
w.Header().Set("Content-Type", "video/x-matroska")
|
||||||
|
case ".mp3":
|
||||||
|
w.Header().Set("Content-Type", "audio/mpeg3")
|
||||||
|
case ".epub", ".mobi":
|
||||||
|
w.Header().Set("Content-Disposition", "attachment")
|
||||||
|
case ".jpg", ".jpeg":
|
||||||
|
w.Header().Set("Content-Type", "image/jpeg")
|
||||||
|
case ".gif":
|
||||||
|
w.Header().Set("Content-Type", "image/gif")
|
||||||
|
case ".png":
|
||||||
|
w.Header().Set("Content-Type", "image/png")
|
||||||
|
case ".ico":
|
||||||
|
w.Header().Set("Content-Type", "image/x-icon")
|
||||||
|
case ".svg":
|
||||||
|
w.Header().Set("Content-Type", "image/svg+xml")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
0
public/DIR2/e.md
Normal file → Executable file
0
public/DIR2/e.md
Normal file → Executable file
@@ -1 +0,0 @@
|
|||||||
hi
|
|
||||||
0
public/b.md
Normal file → Executable file
0
public/b.md
Normal file → Executable file
Reference in New Issue
Block a user