mirror of
https://github.com/versia-pub/versia-go.git
synced 2026-03-13 20:49:15 +01:00
chore: init
This commit is contained in:
commit
320715f3e7
174 changed files with 42083 additions and 0 deletions
28
internal/handlers/meta_handler/handler.go
Normal file
28
internal/handlers/meta_handler/handler.go
Normal 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)
|
||||
}
|
||||
28
internal/handlers/meta_handler/lysand_server_metadata_get.go
Normal file
28
internal/handlers/meta_handler/lysand_server_metadata_get.go
Normal 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{},
|
||||
})
|
||||
}
|
||||
23
internal/handlers/meta_handler/wellknown_host_meta.go
Normal file
23
internal/handlers/meta_handler/wellknown_host_meta.go
Normal 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)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue