aboutsummaryrefslogtreecommitdiff
path: root/processors
diff options
context:
space:
mode:
authorBobby <[email protected]>2025-07-16 13:18:20 +0530
committerBobby <[email protected]>2025-07-16 13:18:20 +0530
commitf13506cfba2da90764620dab2c624ac74767de62 (patch)
tree1651ed298d3f7c9dc7f6a5ccc03da7f0d133f5d6 /processors
parentf352d2678f91e4f4ea6902d084fb9590e2819e92 (diff)
downloadimageboard-f13506cfba2da90764620dab2c624ac74767de62.tar.xz
imageboard-f13506cfba2da90764620dab2c624ac74767de62.zip
constants and types refactor; next value for proper redirect on login
Diffstat (limited to 'processors')
-rw-r--r--processors/preferences.go14
-rw-r--r--processors/request.go27
-rw-r--r--processors/sidebar.go11
-rw-r--r--processors/user.go2
4 files changed, 14 insertions, 40 deletions
diff --git a/processors/preferences.go b/processors/preferences.go
index a96d1cb..a74d1e5 100644
--- a/processors/preferences.go
+++ b/processors/preferences.go
@@ -3,21 +3,13 @@ package processors
import (
"encoding/json"
"fmt"
+ "imageboard/config"
"github.com/gofiber/fiber/v2"
)
-type SitePreferences struct {
- SidebarWidth string `json:"sidebar_width"`
- MainContentWidth string `json:"main_content_width"`
- H1FontSize string `json:"h1_font_size"`
- BodyFontSize string `json:"body_font_size"`
- SmallFontSize string `json:"small_font_size"`
- PostsPerPage int `json:"posts_per_page"`
-}
-
func PreferencesContextProcessor(context *fiber.Ctx) error {
- defaultPreferences := SitePreferences{
+ defaultPreferences := config.SitePreferences{
SidebarWidth: "180px",
MainContentWidth: "1200px",
H1FontSize: "16px",
@@ -48,7 +40,7 @@ func PreferencesContextProcessor(context *fiber.Ctx) error {
return context.Next()
}
-func preferencesToCSS(preferences SitePreferences) string {
+func preferencesToCSS(preferences config.SitePreferences) string {
return fmt.Sprintf(`
<style>
main {
diff --git a/processors/request.go b/processors/request.go
index f4fe8d2..173b29d 100644
--- a/processors/request.go
+++ b/processors/request.go
@@ -1,36 +1,23 @@
package processors
import (
+ "imageboard/config"
+
"github.com/gofiber/fiber/v2"
)
-type QueryParam struct {
- Key string
- Value string
-}
-
-type Request struct {
- Path string
- Method string
- Query []QueryParam
- Params []QueryParam
- QueryString string
- IP string
- URL string
-}
-
func RequestContextProcessor(ctx *fiber.Ctx) error {
- queryParams := []QueryParam{}
+ queryParams := []config.QueryParam{}
for k, v := range ctx.Queries() {
- queryParams = append(queryParams, QueryParam{Key: k, Value: v})
+ queryParams = append(queryParams, config.QueryParam{Key: k, Value: v})
}
- routeParams := []QueryParam{}
+ routeParams := []config.QueryParam{}
for k, v := range ctx.AllParams() {
- routeParams = append(routeParams, QueryParam{Key: k, Value: v})
+ routeParams = append(routeParams, config.QueryParam{Key: k, Value: v})
}
- request := Request{
+ request := config.Request{
Path: ctx.Path(),
Method: ctx.Method(),
Query: queryParams,
diff --git a/processors/sidebar.go b/processors/sidebar.go
index 26138f1..6fe2fdf 100644
--- a/processors/sidebar.go
+++ b/processors/sidebar.go
@@ -2,20 +2,13 @@ package processors
import (
"fmt"
+ "imageboard/config"
"imageboard/database"
"imageboard/models"
"github.com/gofiber/fiber/v2"
)
-type SiteStats struct {
- Posts string
- Tags string
- Today string
- Storage string
- Comments string
-}
-
func SidebarContextProcessor(ctx *fiber.Ctx) error {
popularTags, popularTagsErr := database.GetPopularTags(15)
if popularTagsErr != nil || len(popularTags) == 0 {
@@ -64,7 +57,7 @@ func SidebarContextProcessor(ctx *fiber.Ctx) error {
todayCount, todayErr := database.GetTodayPostsCount()
storageSize, storageErr := database.GetTotalStorageSize()
- var stats SiteStats
+ var stats config.SiteStats
if postsErr == nil {
stats.Posts = fmt.Sprintf("%d", postsCount)
diff --git a/processors/user.go b/processors/user.go
index b875c89..e96f1f9 100644
--- a/processors/user.go
+++ b/processors/user.go
@@ -4,6 +4,7 @@ import (
"imageboard/database"
"imageboard/models"
"imageboard/session"
+ "imageboard/utils/auth"
"github.com/gofiber/fiber/v2"
)
@@ -38,6 +39,7 @@ func UserContextProcessor(ctx *fiber.Ctx) error {
ctx.Locals("User", user)
ctx.Locals("IsAuthenticated", user != nil)
+ ctx.Locals("LogoutURL", auth.GetLogoutURLWithRedirect(ctx))
return ctx.Next()
}