Diffstat (limited to 'internal')
| -rw-r--r-- | internal/router/api-v1-blog-search.go | 2 | ||||
| -rw-r--r-- | internal/router/client-cache.go | 46 | ||||
| -rw-r--r-- | internal/router/lang-blog-title.go | 4 | ||||
| -rw-r--r-- | internal/router/lang-blog.go | 2 |
4 files changed, 2 insertions, 52 deletions
diff --git a/internal/router/api-v1-blog-search.go b/internal/router/api-v1-blog-search.go index a809783..51ace85 100644 --- a/internal/router/api-v1-blog-search.go +++ b/internal/router/api-v1-blog-search.go @@ -48,7 +48,7 @@ func Api_V1_BlogSearch(l map[string]*locale.LocaleConfig, langs []string, b2Clie c.Set(fiber.HeaderContentType, fiber.MIMETextPlainCharsetUTF8) return c.Status(fiber.ErrInternalServerError.Code).SendString("failed to generate regex for tags gathering") } - decodedQuery, _ := url.QueryUnescape(string(encodedQuery)) + decodedQuery, err := url.QueryUnescape(string(encodedQuery)) matches := re.FindAllStringSubmatch(decodedQuery, -1) tags := make([]string, 0, len(matches)) diff --git a/internal/router/client-cache.go b/internal/router/client-cache.go deleted file mode 100644 index 192d2ed..0000000 --- a/internal/router/client-cache.go +++ /dev/null @@ -1,46 +0,0 @@ -package router - -import ( - "log/slog" - "sync" - - "golang.org/x/crypto/argon2" -) - -type ClientCache struct { - hashMap map[string][]byte - mutexMap map[string]*sync.Mutex - salt []byte -} - -var CCache *ClientCache - -func NewClientCache(salt []byte) *ClientCache { - return &ClientCache{ - hashMap: make(map[string][]byte), - mutexMap: make(map[string]*sync.Mutex), - salt: salt, - } -} - -func (c *ClientCache) GetHash(id string) []byte { - if val, ok := c.hashMap[id]; ok { - slog.Debug("gave an old hash", slog.String("hash", string(val))) - return val - } - - if _, ok := c.mutexMap[id]; !ok { - c.mutexMap[id] = &sync.Mutex{} - } - c.mutexMap[id].Lock() - defer c.mutexMap[id].Unlock() - - if val, ok := c.hashMap[id]; ok { - slog.Debug("gave a newly generated hash", slog.String("hash", string(val))) - return val - } - - c.hashMap[id] = argon2.IDKey([]byte(id), c.salt, 1, 64*1024, 4, 32) - slog.Debug("generated hash", slog.String("hash", string(c.hashMap[id]))) - return c.hashMap[id] -} diff --git a/internal/router/lang-blog-title.go b/internal/router/lang-blog-title.go index 5b80ec8..b7b5d7e 100644 --- a/internal/router/lang-blog-title.go +++ b/internal/router/lang-blog-title.go @@ -22,10 +22,6 @@ func init() { func Lang_Blog_Title(l map[string]*locale.LocaleConfig, langs []string, b2Client *b2.B2Client, md goldmark.Markdown) func(c *fiber.Ctx) error { return func(c *fiber.Ctx) error { - ip := c.IP() - slog.Debug("client entering blog page", slog.String("ip", ip), slog.String("page", c.Path())) - go CCache.GetHash(ip) - lang := c.Params("lang") if !slices.Contains(langs, lang) { c.Set(fiber.HeaderContentType, fiber.MIMETextPlainCharsetUTF8) diff --git a/internal/router/lang-blog.go b/internal/router/lang-blog.go index 0cbba94..650c4b1 100644 --- a/internal/router/lang-blog.go +++ b/internal/router/lang-blog.go @@ -37,7 +37,7 @@ func Lang_Blog(l map[string]*locale.LocaleConfig, langs []string, b2Client *b2.B c.Set(fiber.HeaderContentType, fiber.MIMETextPlainCharsetUTF8) return c.Status(fiber.ErrInternalServerError.Code).SendString("failed to generate regex for tags gathering") } - decodedQuery, _ := url.QueryUnescape(string(encodedQuery)) + decodedQuery, err := url.QueryUnescape(string(encodedQuery)) matches := re.FindAllStringSubmatch(decodedQuery, -1) queryTags := make([]string, 0, len(matches)) |