chore: init

This commit is contained in:
DevMiner 2024-08-11 03:51:22 +02:00
commit 320715f3e7
174 changed files with 42083 additions and 0 deletions

View file

@ -0,0 +1,28 @@
package meta_handler
import (
"github.com/go-logr/logr"
"github.com/gofiber/fiber/v2"
"github.com/lysand-org/versia-go/config"
"github.com/lysand-org/versia-go/pkg/webfinger"
)
type Handler struct {
hostMeta webfinger.HostMeta
log logr.Logger
}
func New(log logr.Logger) *Handler {
return &Handler{
hostMeta: webfinger.NewHostMeta(config.C.PublicAddress),
log: log.WithName("users"),
}
}
func (i *Handler) Register(r fiber.Router) {
r.Get("/.well-known/lysand", i.GetLysandServerMetadata)
r.Get("/.well-known/host-meta", i.GetHostMeta)
r.Get("/.well-known/host-meta.json", i.GetHostMetaJSON)
}

View file

@ -0,0 +1,28 @@
package meta_handler
import (
"github.com/Masterminds/semver"
"github.com/gofiber/fiber/v2"
"github.com/lysand-org/versia-go/config"
"github.com/lysand-org/versia-go/pkg/lysand"
)
func (i *Handler) GetLysandServerMetadata(c *fiber.Ctx) error {
return c.JSON(lysand.ServerMetadata{
// TODO: Get version from build linker flags
Version: semver.MustParse("0.0.0-dev"),
Name: config.C.InstanceName,
Description: config.C.InstanceDescription,
Website: lysand.URLFromStd(config.C.PublicAddress),
// TODO: Get more info
Moderators: nil,
Admins: nil,
Logo: nil,
Banner: nil,
SupportedExtensions: []string{},
Extensions: map[string]any{},
})
}

View file

@ -0,0 +1,23 @@
package meta_handler
import (
"github.com/gofiber/fiber/v2"
)
func (i *Handler) GetHostMeta(c *fiber.Ctx) error {
if c.Accepts(fiber.MIMEApplicationJSON) != "" {
return i.GetHostMetaJSON(c)
}
if c.Accepts(fiber.MIMEApplicationXML) != "" {
c.Set(fiber.HeaderContentType, fiber.MIMEApplicationXMLCharsetUTF8)
return c.Send(i.hostMeta.XML)
}
return c.Status(fiber.StatusNotAcceptable).SendString("Not Acceptable")
}
func (i *Handler) GetHostMetaJSON(c *fiber.Ctx) error {
c.Set(fiber.HeaderContentType, fiber.MIMEApplicationJSONCharsetUTF8)
return c.Send(i.hostMeta.JSON)
}