This commit is contained in:
vysion 2021-07-07 19:22:34 -07:00
parent 2bab0cba3f
commit e09830024d
4 changed files with 7 additions and 14 deletions

View File

@ -12,9 +12,6 @@ security:
# There will always be 2048 bytes added on top of this so that the server can respond. If it were 0 bytes,
# the server would not be able to respond at all LOL
maxsizebytes: 52428800
# Key not required to upload if this is true.
# Enable this if you know what you're doing.
publicmode: false
ratelimit:
# When to reset the limit, in milliseconds.
# The default value here is 1 minute.

View File

@ -2,7 +2,7 @@ package main
import (
"context"
"embed"
_ "embed"
"github.com/go-redis/redis/v8"
"github.com/spf13/viper"
"github.com/valyala/fasthttp"
@ -12,7 +12,7 @@ import (
)
//go:embed conf/favicon.ico
var Favicon embed.FS
var Favicon []byte
const (
Version = "1.1.0"

View File

@ -20,6 +20,7 @@ const (
// Bandwidth checking for uploading is set as BW_UP_192.168.1.1, for another example.
func (b *BaseHandler) limitPath(h fasthttp.RequestHandler) fasthttp.RequestHandler {
return func(ctx *fasthttp.RequestCtx) {
ip := utils.GetIP(ctx)
if b.Config.Security.RateLimit.ResetAfter <= 0 {
h(ctx)
} else {
@ -37,7 +38,7 @@ func (b *BaseHandler) limitPath(h fasthttp.RequestHandler) fasthttp.RequestHandl
} else {
rlString := ""
// Check the global rate limit
isGlobalRateLimitOk, err := Try(ctx, b.RedisClient, fmt.Sprintf("G_%s", utils.GetIP(ctx)), b.Config.Security.RateLimit.Global, b.Config.Security.RateLimit.ResetAfter, 1)
isGlobalRateLimitOk, err := Try(ctx, b.RedisClient, fmt.Sprintf("G_%s", ip), b.Config.Security.RateLimit.Global, b.Config.Security.RateLimit.ResetAfter, 1)
if err != nil {
SendTextResponse(ctx, "Failed to call Try() to get information on global rate limit. "+err.Error(), fasthttp.StatusInternalServerError)
return
@ -48,7 +49,7 @@ func (b *BaseHandler) limitPath(h fasthttp.RequestHandler) fasthttp.RequestHandl
if pathType != LimitGeneralPath {
// Check the route exclusive rate limit
isPathOk, err := Try(ctx, b.RedisClient, fmt.Sprintf("%d_%s", pathType, utils.GetIP(ctx)), reqLimit, b.Config.Security.RateLimit.ResetAfter, 1)
isPathOk, err := Try(ctx, b.RedisClient, fmt.Sprintf("%d_%s", pathType, ip), reqLimit, b.Config.Security.RateLimit.ResetAfter, 1)
if err != nil {
SendTextResponse(ctx, "Failed to call Try() to get information on path-specific rate limit. "+err.Error(), fasthttp.StatusInternalServerError)
return

View File

@ -7,14 +7,9 @@ import (
)
func ServeFavicon(ctx *fasthttp.RequestCtx) {
f, e := Favicon.ReadFile("./conf/favicon.ico")
if e != nil {
ctx.Response.SetStatusCode(fasthttp.StatusInternalServerError)
return
}
b := bytes.NewBuffer(f)
b := bytes.NewBuffer(Favicon)
ctx.Response.Header.Set("Content-Type", "image/x-icon")
_, e = io.Copy(ctx.Response.BodyWriter(), b)
_, e := io.Copy(ctx.Response.BodyWriter(), b)
if e != nil {
ctx.Response.SetStatusCode(fasthttp.StatusInternalServerError)
}