mirror of
https://github.com/versia-pub/versia-go.git
synced 2026-03-13 04:29:15 +01:00
refactor(server): rename stuff from Lysand to Versia
Big diff energy
This commit is contained in:
parent
03e01548dc
commit
cb135706e2
29 changed files with 103 additions and 96 deletions
|
|
@ -29,5 +29,5 @@ func New(followService service.FollowService, federationService service.Federati
|
|||
}
|
||||
|
||||
func (i *Handler) Register(r fiber.Router) {
|
||||
r.Get("/api/follows/:id", i.GetLysandFollow)
|
||||
r.Get("/api/follows/:id", i.GetVersiaFollow)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import (
|
|||
"github.com/lysand-org/versia-go/internal/api_schema"
|
||||
)
|
||||
|
||||
func (i *Handler) GetLysandFollow(c *fiber.Ctx) error {
|
||||
func (i *Handler) GetVersiaFollow(c *fiber.Ctx) error {
|
||||
parsedRequestedFollowID, err := uuid.Parse(c.Params("id"))
|
||||
if err != nil {
|
||||
return api_schema.ErrBadRequest(map[string]any{"reason": "Invalid follow ID"})
|
||||
|
|
@ -24,5 +24,5 @@ func (i *Handler) GetLysandFollow(c *fiber.Ctx) error {
|
|||
})
|
||||
}
|
||||
|
||||
return c.JSON(f.ToLysand())
|
||||
return c.JSON(f.ToVersia())
|
||||
}
|
||||
|
|
@ -27,9 +27,9 @@ func New(instanceMetadataService service.InstanceMetadataService, log logr.Logge
|
|||
}
|
||||
|
||||
func (i *Handler) Register(r fiber.Router) {
|
||||
r.Get("/.well-known/versia", i.GetLysandInstanceMetadata)
|
||||
r.Get("/.well-known/versia/admins", i.GetLysandInstanceMetadata)
|
||||
r.Get("/.well-known/versia/moderators", i.GetLysandInstanceMetadata)
|
||||
r.Get("/.well-known/versia", i.GetVersiaInstanceMetadata)
|
||||
r.Get("/.well-known/versia/admins", i.GetVersiaInstanceMetadata)
|
||||
r.Get("/.well-known/versia/moderators", i.GetVersiaInstanceMetadata)
|
||||
|
||||
// Webfinger host meta spec
|
||||
r.Get("/.well-known/host-meta", i.GetHostMeta)
|
||||
|
|
|
|||
|
|
@ -4,11 +4,12 @@ import (
|
|||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
func (i *Handler) GetLysandInstanceMetadata(c *fiber.Ctx) error {
|
||||
func (i *Handler) GetVersiaInstanceMetadata(c *fiber.Ctx) error {
|
||||
m, err := i.instanceMetadataService.Ours(c.UserContext())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return c.JSON(m.ToLysand())
|
||||
// TODO: Sign with the instance private key
|
||||
return c.JSON(m.ToVersia())
|
||||
}
|
||||
|
|
@ -14,15 +14,26 @@ func (i *Handler) GetNote(c *fiber.Ctx) error {
|
|||
})
|
||||
}
|
||||
|
||||
u, err := i.noteService.GetNote(c.UserContext(), parsedRequestedNoteID)
|
||||
n, err := i.noteService.GetNote(c.UserContext(), parsedRequestedNoteID)
|
||||
if err != nil {
|
||||
i.log.Error(err, "Failed to query note", "id", parsedRequestedNoteID)
|
||||
|
||||
return api_schema.ErrInternalServerError(map[string]any{"reason": "Failed to query note"})
|
||||
}
|
||||
if u == nil {
|
||||
if n == nil {
|
||||
return api_schema.ErrNotFound(nil)
|
||||
}
|
||||
|
||||
return c.JSON(u.ToLysand())
|
||||
if !n.Author.IsRemote {
|
||||
// For local authors we can also sign the note
|
||||
if err := i.requestSigner.SignAndSend(c, n.Author.Signer, n.ToVersia()); err != nil {
|
||||
i.log.Error(err, "Failed to sign response body", "id", parsedRequestedNoteID)
|
||||
|
||||
return api_schema.ErrInternalServerError(map[string]any{
|
||||
"reason": "failed to sign response body",
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return c.JSON(n.ToVersia())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,16 +12,18 @@ import (
|
|||
type Handler struct {
|
||||
noteService service.NoteService
|
||||
bodyValidator validators.BodyValidator
|
||||
requestSigner service.RequestSigner
|
||||
|
||||
hostMeta webfinger.HostMeta
|
||||
|
||||
log logr.Logger
|
||||
}
|
||||
|
||||
func New(noteService service.NoteService, bodyValidator validators.BodyValidator, log logr.Logger) *Handler {
|
||||
func New(noteService service.NoteService, bodyValidator validators.BodyValidator, requestSigner service.RequestSigner, log logr.Logger) *Handler {
|
||||
return &Handler{
|
||||
noteService: noteService,
|
||||
bodyValidator: bodyValidator,
|
||||
requestSigner: requestSigner,
|
||||
|
||||
hostMeta: webfinger.NewHostMeta(config.C.PublicAddress),
|
||||
|
||||
|
|
|
|||
|
|
@ -50,5 +50,5 @@ func (i *Handler) SearchUser(c *fiber.Ctx) error {
|
|||
return api_schema.ErrNotFound(nil)
|
||||
}
|
||||
|
||||
return c.JSON((*api_schema.VersiaUser)(u.ToLysand()))
|
||||
return c.JSON((*api_schema.VersiaUser)(u.ToVersia()))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,6 +46,6 @@ func (i *Handler) Register(r fiber.Router) {
|
|||
r.Get("/api/app/users/:id", i.GetUser)
|
||||
r.Post("/api/app/users/", i.CreateUser)
|
||||
|
||||
r.Get("/api/users/:id", i.GetLysandUser)
|
||||
r.Post("/api/users/:id/inbox", i.LysandInbox)
|
||||
r.Get("/api/users/:id", i.GetVersiaUser)
|
||||
r.Post("/api/users/:id/inbox", i.HandleVersiaInbox)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import (
|
|||
"github.com/lysand-org/versia-go/internal/api_schema"
|
||||
)
|
||||
|
||||
func (i *Handler) LysandInbox(c *fiber.Ctx) error {
|
||||
func (i *Handler) HandleVersiaInbox(c *fiber.Ctx) error {
|
||||
if err := i.requestValidator.ValidateFiberCtx(c.UserContext(), c); err != nil {
|
||||
if errors.Is(err, val_impls.ErrInvalidSignature) {
|
||||
i.log.Error(err, "Invalid signature")
|
||||
|
|
@ -6,7 +6,7 @@ import (
|
|||
"github.com/lysand-org/versia-go/internal/api_schema"
|
||||
)
|
||||
|
||||
func (i *Handler) GetLysandUser(c *fiber.Ctx) error {
|
||||
func (i *Handler) GetVersiaUser(c *fiber.Ctx) error {
|
||||
parsedRequestedUserID, err := uuid.Parse(c.Params("id"))
|
||||
if err != nil {
|
||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||||
|
|
@ -27,5 +27,13 @@ func (i *Handler) GetLysandUser(c *fiber.Ctx) error {
|
|||
return api_schema.ErrNotFound(map[string]any{"id": parsedRequestedUserID})
|
||||
}
|
||||
|
||||
return i.requestSigner.Sign(c, u.Signer, u.ToLysand())
|
||||
if err := i.requestSigner.SignAndSend(c, u.Signer, u.ToVersia()); err != nil {
|
||||
i.log.Error(err, "Failed to sign response body", "id", parsedRequestedUserID)
|
||||
|
||||
return api_schema.ErrInternalServerError(map[string]any{
|
||||
"reason": "failed to sign response body",
|
||||
})
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue