tijl.dev-core/internal/handlers/services.go

78 lines
1.7 KiB
Go
Raw Normal View History

2024-08-31 17:42:51 +02:00
package handlers
import (
2024-08-31 17:45:51 +02:00
"git.tijl.dev/tijl/tijl.dev-core/internal/user"
2024-08-31 17:42:51 +02:00
"git.tijl.dev/tijl/tijl.dev-core/modules/i18n"
"git.tijl.dev/tijl/tijl.dev-core/modules/web"
"github.com/gofiber/fiber/v2"
)
type Service struct {
Name string
Description string
Url string
InfoUrl string
Color string
Scale float64
}
var services = map[string]Service{
"immich": {
Name: "Immich",
Description: "...",
Url: "https://fotos.tijl.dev/photos",
InfoUrl: "https://immich.app",
Color: "white",
Scale: 0,
},
"element": {
Name: "Element",
Description: "...",
Url: "https://element.tijl.dev",
InfoUrl: "https://matrix.org",
Color: "#0DBD8B",
Scale: 0.1,
},
"nextcloud": {
Name: "Nextcloud",
Description: "...",
Url: "https://cloud.tijl.dev",
InfoUrl: "https://nextcloud.com",
Color: "#00679e",
Scale: -0.2,
},
}
func servicesHandler(c *fiber.Ctx) error {
2024-08-31 17:45:51 +02:00
_, err := user.GetSession(c)
if err != nil {
return c.Next()
}
2024-08-31 17:42:51 +02:00
data := *web.Common(c)
data["Title"] = i18n.Translate(c, "services")
data["Services"] = services
return c.Render("services", data, "layouts/base")
}
func serviceHandler(c *fiber.Ctx) error {
2024-08-31 17:45:51 +02:00
_, err := user.GetSession(c)
if err != nil {
return c.Next()
}
2024-08-31 17:42:51 +02:00
if services[c.Params("service")].Url != "" {
return c.Redirect(services[c.Params("service")].Url)
}
return c.Next()
}
func serviceInfoHandler(c *fiber.Ctx) error {
2024-08-31 17:45:51 +02:00
_, err := user.GetSession(c)
if err != nil {
return c.Next()
}
2024-08-31 17:42:51 +02:00
if services[c.Params("service")].Url != "" {
return c.Redirect(services[c.Params("service")].InfoUrl)
}
return c.Next()
}