mirror of
https://git.seedno.de/seednode/roulette.git
synced 2024-12-18 04:09:40 +00:00
Compare commits
3 commits
adaa7378ff
...
56c6565cb1
Author | SHA1 | Date | |
---|---|---|---|
|
56c6565cb1 | ||
|
09bff1ed18 | ||
|
de94c5eb49 |
6 changed files with 73 additions and 19 deletions
|
@ -27,7 +27,7 @@ const (
|
|||
<meta name="theme-color" content="#ffffff">`
|
||||
)
|
||||
|
||||
func serveFavicons() httprouter.Handle {
|
||||
func serveFavicons(errorChannel chan<- error) httprouter.Handle {
|
||||
return func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
|
||||
fname := strings.TrimPrefix(r.URL.Path, "/")
|
||||
|
||||
|
@ -36,8 +36,18 @@ func serveFavicons() httprouter.Handle {
|
|||
return
|
||||
}
|
||||
|
||||
w.Header().Write(bytes.NewBufferString("Content-Length: " + strconv.Itoa(len(data))))
|
||||
err = w.Header().Write(bytes.NewBufferString("Content-Length: " + strconv.Itoa(len(data))))
|
||||
if err != nil {
|
||||
errorChannel <- err
|
||||
|
||||
w.Write(data)
|
||||
return
|
||||
}
|
||||
|
||||
_, err = w.Write(data)
|
||||
if err != nil {
|
||||
errorChannel <- err
|
||||
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
21
cmd/index.go
21
cmd/index.go
|
@ -110,9 +110,7 @@ func getReader(format string, file io.Reader) (io.Reader, error) {
|
|||
case "zlib":
|
||||
return zlib.NewReader(file)
|
||||
case "zstd":
|
||||
decoder, err := zstd.NewReader(file)
|
||||
|
||||
return decoder.IOReadCloser(), err
|
||||
return zstd.NewReader(file)
|
||||
}
|
||||
|
||||
return io.NopCloser(file), ErrInvalidCompression
|
||||
|
@ -264,13 +262,28 @@ func (index *fileIndex) Import(path string) error {
|
|||
|
||||
func serveIndexRebuild(args []string, index *fileIndex, formats types.Types, errorChannel chan<- error) httprouter.Handle {
|
||||
return func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
|
||||
startTime := time.Now()
|
||||
|
||||
index.clear()
|
||||
|
||||
fileList(args, &filters{}, "", index, formats, errorChannel)
|
||||
|
||||
w.Header().Set("Content-Type", "text/plain")
|
||||
|
||||
w.Write([]byte("Ok\n"))
|
||||
_, err := w.Write([]byte("Ok\n"))
|
||||
if err != nil {
|
||||
errorChannel <- err
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if Verbose {
|
||||
fmt.Printf("%s | SERVE: Index rebuild requested by %s took %s\n",
|
||||
startTime.Format(logDate),
|
||||
realIP(r),
|
||||
time.Since(startTime).Round(time.Microsecond),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -145,7 +145,7 @@ func serveIndexHtml(args []string, index *fileIndex, shouldPaginate bool) httpro
|
|||
|
||||
htmlBody.WriteString(`</table></body></html>`)
|
||||
|
||||
length, err := io.WriteString(w, gohtml.Format(htmlBody.String()))
|
||||
written, err := io.WriteString(w, gohtml.Format(htmlBody.String()))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
@ -153,7 +153,7 @@ func serveIndexHtml(args []string, index *fileIndex, shouldPaginate bool) httpro
|
|||
if Verbose {
|
||||
fmt.Printf("%s | SERVE: HTML index page (%s) to %s in %s\n",
|
||||
startTime.Format(logDate),
|
||||
humanReadableSize(length),
|
||||
humanReadableSize(written),
|
||||
realIP(r),
|
||||
time.Since(startTime).Round(time.Microsecond),
|
||||
)
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"fmt"
|
||||
"net/http"
|
||||
"net/http/pprof"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/julienschmidt/httprouter"
|
||||
|
@ -16,6 +17,10 @@ import (
|
|||
func registerProfileHandler(mux *httprouter.Router, verb, path string, handler http.HandlerFunc) {
|
||||
mux.HandlerFunc(verb, path, handler)
|
||||
|
||||
if Redact && AdminPrefix != "" {
|
||||
path = strings.ReplaceAll(path, AdminPrefix, "/<admin_prefix>")
|
||||
}
|
||||
|
||||
if Handlers {
|
||||
fmt.Printf("%s | SERVE: Registered handler for %s\n",
|
||||
time.Now().Format(logDate),
|
||||
|
|
|
@ -17,7 +17,7 @@ import (
|
|||
|
||||
const (
|
||||
AllowedCharacters string = `^[A-z0-9.\-_]+$`
|
||||
ReleaseVersion string = "4.0.1"
|
||||
ReleaseVersion string = "4.0.4"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
44
cmd/web.go
44
cmd/web.go
|
@ -253,6 +253,8 @@ func serveRoot(paths []string, regexes *regexes, index *fileIndex, formats types
|
|||
|
||||
func serveMedia(paths []string, regexes *regexes, index *fileIndex, formats types.Types, errorChannel chan<- error) httprouter.Handle {
|
||||
return func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
|
||||
startTime := time.Now()
|
||||
|
||||
filters := &filters{
|
||||
included: splitQueryParams(r.URL.Query().Get("include"), regexes),
|
||||
excluded: splitQueryParams(r.URL.Query().Get("exclude"), regexes),
|
||||
|
@ -384,8 +386,6 @@ func serveMedia(paths []string, regexes *regexes, index *fileIndex, formats type
|
|||
|
||||
htmlBody.WriteString(`</body></html>`)
|
||||
|
||||
startTime := time.Now()
|
||||
|
||||
formattedPage := gohtml.Format(htmlBody.String())
|
||||
|
||||
written, err := io.WriteString(w, formattedPage)
|
||||
|
@ -409,19 +409,45 @@ func serveMedia(paths []string, regexes *regexes, index *fileIndex, formats type
|
|||
}
|
||||
|
||||
if Russian {
|
||||
kill(path, index)
|
||||
err := kill(path, index)
|
||||
if err != nil {
|
||||
errorChannel <- err
|
||||
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func serveVersion() httprouter.Handle {
|
||||
func serveVersion(errorChannel chan<- error) httprouter.Handle {
|
||||
return func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
|
||||
startTime := time.Now()
|
||||
|
||||
data := []byte(fmt.Sprintf("roulette v%s\n", ReleaseVersion))
|
||||
|
||||
w.Header().Write(bytes.NewBufferString("Content-Length: " + strconv.Itoa(len(data))))
|
||||
err := w.Header().Write(bytes.NewBufferString("Content-Length: " + strconv.Itoa(len(data))))
|
||||
if err != nil {
|
||||
errorChannel <- err
|
||||
|
||||
w.Write(data)
|
||||
return
|
||||
}
|
||||
|
||||
written, err := w.Write(data)
|
||||
if err != nil {
|
||||
errorChannel <- err
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if Verbose {
|
||||
fmt.Printf("%s | SERVE: Version page (%s) to %s in %s\n",
|
||||
startTime.Format(logDate),
|
||||
humanReadableSize(written),
|
||||
realIP(r),
|
||||
time.Since(startTime).Round(time.Microsecond),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -578,15 +604,15 @@ func ServePage(args []string) error {
|
|||
registerHandler(mux, "/", redirectRoot())
|
||||
}
|
||||
|
||||
registerHandler(mux, Prefix+"/favicons/*favicon", serveFavicons())
|
||||
registerHandler(mux, Prefix+"/favicons/*favicon", serveFavicons(errorChannel))
|
||||
|
||||
registerHandler(mux, Prefix+"/favicon.ico", serveFavicons())
|
||||
registerHandler(mux, Prefix+"/favicon.ico", serveFavicons(errorChannel))
|
||||
|
||||
registerHandler(mux, Prefix+mediaPrefix+"/*media", serveMedia(paths, regexes, index, formats, errorChannel))
|
||||
|
||||
registerHandler(mux, Prefix+sourcePrefix+"/*static", serveStaticFile(paths, index, errorChannel))
|
||||
|
||||
registerHandler(mux, Prefix+"/version", serveVersion())
|
||||
registerHandler(mux, Prefix+"/version", serveVersion(errorChannel))
|
||||
|
||||
if Index {
|
||||
registerHandler(mux, Prefix+AdminPrefix+"/index/rebuild", serveIndexRebuild(args, index, formats, errorChannel))
|
||||
|
|
Loading…
Reference in a new issue