mirror of
https://github.com/versia-pub/versia-go.git
synced 2025-12-06 06:28:18 +01:00
refactor!: add missing fields and docs
This commit is contained in:
parent
61891d891a
commit
6e59386f60
|
|
@ -13,7 +13,7 @@ import (
|
|||
"github.com/google/uuid"
|
||||
"github.com/lysand-org/versia-go/ent/attachment"
|
||||
"github.com/lysand-org/versia-go/ent/user"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
"github.com/lysand-org/versia-go/pkg/versia"
|
||||
)
|
||||
|
||||
// Attachment is the model entity for the Attachment schema.
|
||||
|
|
@ -26,7 +26,7 @@ type Attachment struct {
|
|||
// URI holds the value of the "uri" field.
|
||||
URI string `json:"uri,omitempty"`
|
||||
// Extensions holds the value of the "extensions" field.
|
||||
Extensions lysand.Extensions `json:"extensions,omitempty"`
|
||||
Extensions versia.Extensions `json:"extensions,omitempty"`
|
||||
// CreatedAt holds the value of the "created_at" field.
|
||||
CreatedAt time.Time `json:"created_at,omitempty"`
|
||||
// UpdatedAt holds the value of the "updated_at" field.
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import (
|
|||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"github.com/google/uuid"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
"github.com/lysand-org/versia-go/pkg/versia"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -99,7 +99,7 @@ var (
|
|||
// URIValidator is a validator for the "uri" field. It is called by the builders before save.
|
||||
URIValidator func(string) error
|
||||
// DefaultExtensions holds the default value on creation for the "extensions" field.
|
||||
DefaultExtensions lysand.Extensions
|
||||
DefaultExtensions versia.Extensions
|
||||
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
|
||||
DefaultCreatedAt func() time.Time
|
||||
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ import (
|
|||
"github.com/google/uuid"
|
||||
"github.com/lysand-org/versia-go/ent/attachment"
|
||||
"github.com/lysand-org/versia-go/ent/user"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
"github.com/lysand-org/versia-go/pkg/versia"
|
||||
)
|
||||
|
||||
// AttachmentCreate is the builder for creating a Attachment entity.
|
||||
|
|
@ -39,8 +39,8 @@ func (ac *AttachmentCreate) SetURI(s string) *AttachmentCreate {
|
|||
}
|
||||
|
||||
// SetExtensions sets the "extensions" field.
|
||||
func (ac *AttachmentCreate) SetExtensions(l lysand.Extensions) *AttachmentCreate {
|
||||
ac.mutation.SetExtensions(l)
|
||||
func (ac *AttachmentCreate) SetExtensions(v versia.Extensions) *AttachmentCreate {
|
||||
ac.mutation.SetExtensions(v)
|
||||
return ac
|
||||
}
|
||||
|
||||
|
|
@ -454,7 +454,7 @@ func (u *AttachmentUpsert) UpdateURI() *AttachmentUpsert {
|
|||
}
|
||||
|
||||
// SetExtensions sets the "extensions" field.
|
||||
func (u *AttachmentUpsert) SetExtensions(v lysand.Extensions) *AttachmentUpsert {
|
||||
func (u *AttachmentUpsert) SetExtensions(v versia.Extensions) *AttachmentUpsert {
|
||||
u.Set(attachment.FieldExtensions, v)
|
||||
return u
|
||||
}
|
||||
|
|
@ -701,7 +701,7 @@ func (u *AttachmentUpsertOne) UpdateURI() *AttachmentUpsertOne {
|
|||
}
|
||||
|
||||
// SetExtensions sets the "extensions" field.
|
||||
func (u *AttachmentUpsertOne) SetExtensions(v lysand.Extensions) *AttachmentUpsertOne {
|
||||
func (u *AttachmentUpsertOne) SetExtensions(v versia.Extensions) *AttachmentUpsertOne {
|
||||
return u.Update(func(s *AttachmentUpsert) {
|
||||
s.SetExtensions(v)
|
||||
})
|
||||
|
|
@ -1143,7 +1143,7 @@ func (u *AttachmentUpsertBulk) UpdateURI() *AttachmentUpsertBulk {
|
|||
}
|
||||
|
||||
// SetExtensions sets the "extensions" field.
|
||||
func (u *AttachmentUpsertBulk) SetExtensions(v lysand.Extensions) *AttachmentUpsertBulk {
|
||||
func (u *AttachmentUpsertBulk) SetExtensions(v versia.Extensions) *AttachmentUpsertBulk {
|
||||
return u.Update(func(s *AttachmentUpsert) {
|
||||
s.SetExtensions(v)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ import (
|
|||
"github.com/lysand-org/versia-go/ent/attachment"
|
||||
"github.com/lysand-org/versia-go/ent/predicate"
|
||||
"github.com/lysand-org/versia-go/ent/user"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
"github.com/lysand-org/versia-go/pkg/versia"
|
||||
)
|
||||
|
||||
// AttachmentUpdate is the builder for updating Attachment entities.
|
||||
|
|
@ -60,8 +60,8 @@ func (au *AttachmentUpdate) SetNillableURI(s *string) *AttachmentUpdate {
|
|||
}
|
||||
|
||||
// SetExtensions sets the "extensions" field.
|
||||
func (au *AttachmentUpdate) SetExtensions(l lysand.Extensions) *AttachmentUpdate {
|
||||
au.mutation.SetExtensions(l)
|
||||
func (au *AttachmentUpdate) SetExtensions(v versia.Extensions) *AttachmentUpdate {
|
||||
au.mutation.SetExtensions(v)
|
||||
return au
|
||||
}
|
||||
|
||||
|
|
@ -453,8 +453,8 @@ func (auo *AttachmentUpdateOne) SetNillableURI(s *string) *AttachmentUpdateOne {
|
|||
}
|
||||
|
||||
// SetExtensions sets the "extensions" field.
|
||||
func (auo *AttachmentUpdateOne) SetExtensions(l lysand.Extensions) *AttachmentUpdateOne {
|
||||
auo.mutation.SetExtensions(l)
|
||||
func (auo *AttachmentUpdateOne) SetExtensions(v versia.Extensions) *AttachmentUpdateOne {
|
||||
auo.mutation.SetExtensions(v)
|
||||
return auo
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import (
|
|||
"github.com/google/uuid"
|
||||
"github.com/lysand-org/versia-go/ent/follow"
|
||||
"github.com/lysand-org/versia-go/ent/user"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
"github.com/lysand-org/versia-go/pkg/versia"
|
||||
)
|
||||
|
||||
// Follow is the model entity for the Follow schema.
|
||||
|
|
@ -26,7 +26,7 @@ type Follow struct {
|
|||
// URI holds the value of the "uri" field.
|
||||
URI string `json:"uri,omitempty"`
|
||||
// Extensions holds the value of the "extensions" field.
|
||||
Extensions lysand.Extensions `json:"extensions,omitempty"`
|
||||
Extensions versia.Extensions `json:"extensions,omitempty"`
|
||||
// CreatedAt holds the value of the "created_at" field.
|
||||
CreatedAt time.Time `json:"created_at,omitempty"`
|
||||
// UpdatedAt holds the value of the "updated_at" field.
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import (
|
|||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"github.com/google/uuid"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
"github.com/lysand-org/versia-go/pkg/versia"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -88,7 +88,7 @@ var (
|
|||
// URIValidator is a validator for the "uri" field. It is called by the builders before save.
|
||||
URIValidator func(string) error
|
||||
// DefaultExtensions holds the default value on creation for the "extensions" field.
|
||||
DefaultExtensions lysand.Extensions
|
||||
DefaultExtensions versia.Extensions
|
||||
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
|
||||
DefaultCreatedAt func() time.Time
|
||||
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ import (
|
|||
"github.com/google/uuid"
|
||||
"github.com/lysand-org/versia-go/ent/follow"
|
||||
"github.com/lysand-org/versia-go/ent/user"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
"github.com/lysand-org/versia-go/pkg/versia"
|
||||
)
|
||||
|
||||
// FollowCreate is the builder for creating a Follow entity.
|
||||
|
|
@ -39,8 +39,8 @@ func (fc *FollowCreate) SetURI(s string) *FollowCreate {
|
|||
}
|
||||
|
||||
// SetExtensions sets the "extensions" field.
|
||||
func (fc *FollowCreate) SetExtensions(l lysand.Extensions) *FollowCreate {
|
||||
fc.mutation.SetExtensions(l)
|
||||
func (fc *FollowCreate) SetExtensions(v versia.Extensions) *FollowCreate {
|
||||
fc.mutation.SetExtensions(v)
|
||||
return fc
|
||||
}
|
||||
|
||||
|
|
@ -386,7 +386,7 @@ func (u *FollowUpsert) UpdateURI() *FollowUpsert {
|
|||
}
|
||||
|
||||
// SetExtensions sets the "extensions" field.
|
||||
func (u *FollowUpsert) SetExtensions(v lysand.Extensions) *FollowUpsert {
|
||||
func (u *FollowUpsert) SetExtensions(v versia.Extensions) *FollowUpsert {
|
||||
u.Set(follow.FieldExtensions, v)
|
||||
return u
|
||||
}
|
||||
|
|
@ -501,7 +501,7 @@ func (u *FollowUpsertOne) UpdateURI() *FollowUpsertOne {
|
|||
}
|
||||
|
||||
// SetExtensions sets the "extensions" field.
|
||||
func (u *FollowUpsertOne) SetExtensions(v lysand.Extensions) *FollowUpsertOne {
|
||||
func (u *FollowUpsertOne) SetExtensions(v versia.Extensions) *FollowUpsertOne {
|
||||
return u.Update(func(s *FollowUpsert) {
|
||||
s.SetExtensions(v)
|
||||
})
|
||||
|
|
@ -789,7 +789,7 @@ func (u *FollowUpsertBulk) UpdateURI() *FollowUpsertBulk {
|
|||
}
|
||||
|
||||
// SetExtensions sets the "extensions" field.
|
||||
func (u *FollowUpsertBulk) SetExtensions(v lysand.Extensions) *FollowUpsertBulk {
|
||||
func (u *FollowUpsertBulk) SetExtensions(v versia.Extensions) *FollowUpsertBulk {
|
||||
return u.Update(func(s *FollowUpsert) {
|
||||
s.SetExtensions(v)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ import (
|
|||
"github.com/lysand-org/versia-go/ent/follow"
|
||||
"github.com/lysand-org/versia-go/ent/predicate"
|
||||
"github.com/lysand-org/versia-go/ent/user"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
"github.com/lysand-org/versia-go/pkg/versia"
|
||||
)
|
||||
|
||||
// FollowUpdate is the builder for updating Follow entities.
|
||||
|
|
@ -60,8 +60,8 @@ func (fu *FollowUpdate) SetNillableURI(s *string) *FollowUpdate {
|
|||
}
|
||||
|
||||
// SetExtensions sets the "extensions" field.
|
||||
func (fu *FollowUpdate) SetExtensions(l lysand.Extensions) *FollowUpdate {
|
||||
fu.mutation.SetExtensions(l)
|
||||
func (fu *FollowUpdate) SetExtensions(v versia.Extensions) *FollowUpdate {
|
||||
fu.mutation.SetExtensions(v)
|
||||
return fu
|
||||
}
|
||||
|
||||
|
|
@ -315,8 +315,8 @@ func (fuo *FollowUpdateOne) SetNillableURI(s *string) *FollowUpdateOne {
|
|||
}
|
||||
|
||||
// SetExtensions sets the "extensions" field.
|
||||
func (fuo *FollowUpdateOne) SetExtensions(l lysand.Extensions) *FollowUpdateOne {
|
||||
fuo.mutation.SetExtensions(l)
|
||||
func (fuo *FollowUpdateOne) SetExtensions(v versia.Extensions) *FollowUpdateOne {
|
||||
fuo.mutation.SetExtensions(v)
|
||||
return fuo
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import (
|
|||
"entgo.io/ent/dialect/sql"
|
||||
"github.com/google/uuid"
|
||||
"github.com/lysand-org/versia-go/ent/instancemetadata"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
"github.com/lysand-org/versia-go/pkg/versia"
|
||||
)
|
||||
|
||||
// InstanceMetadata is the model entity for the InstanceMetadata schema.
|
||||
|
|
@ -25,7 +25,7 @@ type InstanceMetadata struct {
|
|||
// URI holds the value of the "uri" field.
|
||||
URI string `json:"uri,omitempty"`
|
||||
// Extensions holds the value of the "extensions" field.
|
||||
Extensions lysand.Extensions `json:"extensions,omitempty"`
|
||||
Extensions versia.Extensions `json:"extensions,omitempty"`
|
||||
// CreatedAt holds the value of the "created_at" field.
|
||||
CreatedAt time.Time `json:"created_at,omitempty"`
|
||||
// UpdatedAt holds the value of the "updated_at" field.
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import (
|
|||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"github.com/google/uuid"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
"github.com/lysand-org/versia-go/pkg/versia"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -138,7 +138,7 @@ var (
|
|||
// URIValidator is a validator for the "uri" field. It is called by the builders before save.
|
||||
URIValidator func(string) error
|
||||
// DefaultExtensions holds the default value on creation for the "extensions" field.
|
||||
DefaultExtensions lysand.Extensions
|
||||
DefaultExtensions versia.Extensions
|
||||
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
|
||||
DefaultCreatedAt func() time.Time
|
||||
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ import (
|
|||
"github.com/google/uuid"
|
||||
"github.com/lysand-org/versia-go/ent/instancemetadata"
|
||||
"github.com/lysand-org/versia-go/ent/user"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
"github.com/lysand-org/versia-go/pkg/versia"
|
||||
)
|
||||
|
||||
// InstanceMetadataCreate is the builder for creating a InstanceMetadata entity.
|
||||
|
|
@ -39,8 +39,8 @@ func (imc *InstanceMetadataCreate) SetURI(s string) *InstanceMetadataCreate {
|
|||
}
|
||||
|
||||
// SetExtensions sets the "extensions" field.
|
||||
func (imc *InstanceMetadataCreate) SetExtensions(l lysand.Extensions) *InstanceMetadataCreate {
|
||||
imc.mutation.SetExtensions(l)
|
||||
func (imc *InstanceMetadataCreate) SetExtensions(v versia.Extensions) *InstanceMetadataCreate {
|
||||
imc.mutation.SetExtensions(v)
|
||||
return imc
|
||||
}
|
||||
|
||||
|
|
@ -703,7 +703,7 @@ func (u *InstanceMetadataUpsert) UpdateURI() *InstanceMetadataUpsert {
|
|||
}
|
||||
|
||||
// SetExtensions sets the "extensions" field.
|
||||
func (u *InstanceMetadataUpsert) SetExtensions(v lysand.Extensions) *InstanceMetadataUpsert {
|
||||
func (u *InstanceMetadataUpsert) SetExtensions(v versia.Extensions) *InstanceMetadataUpsert {
|
||||
u.Set(instancemetadata.FieldExtensions, v)
|
||||
return u
|
||||
}
|
||||
|
|
@ -1058,7 +1058,7 @@ func (u *InstanceMetadataUpsertOne) UpdateURI() *InstanceMetadataUpsertOne {
|
|||
}
|
||||
|
||||
// SetExtensions sets the "extensions" field.
|
||||
func (u *InstanceMetadataUpsertOne) SetExtensions(v lysand.Extensions) *InstanceMetadataUpsertOne {
|
||||
func (u *InstanceMetadataUpsertOne) SetExtensions(v versia.Extensions) *InstanceMetadataUpsertOne {
|
||||
return u.Update(func(s *InstanceMetadataUpsert) {
|
||||
s.SetExtensions(v)
|
||||
})
|
||||
|
|
@ -1626,7 +1626,7 @@ func (u *InstanceMetadataUpsertBulk) UpdateURI() *InstanceMetadataUpsertBulk {
|
|||
}
|
||||
|
||||
// SetExtensions sets the "extensions" field.
|
||||
func (u *InstanceMetadataUpsertBulk) SetExtensions(v lysand.Extensions) *InstanceMetadataUpsertBulk {
|
||||
func (u *InstanceMetadataUpsertBulk) SetExtensions(v versia.Extensions) *InstanceMetadataUpsertBulk {
|
||||
return u.Update(func(s *InstanceMetadataUpsert) {
|
||||
s.SetExtensions(v)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ import (
|
|||
"github.com/lysand-org/versia-go/ent/instancemetadata"
|
||||
"github.com/lysand-org/versia-go/ent/predicate"
|
||||
"github.com/lysand-org/versia-go/ent/user"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
"github.com/lysand-org/versia-go/pkg/versia"
|
||||
)
|
||||
|
||||
// InstanceMetadataUpdate is the builder for updating InstanceMetadata entities.
|
||||
|
|
@ -61,8 +61,8 @@ func (imu *InstanceMetadataUpdate) SetNillableURI(s *string) *InstanceMetadataUp
|
|||
}
|
||||
|
||||
// SetExtensions sets the "extensions" field.
|
||||
func (imu *InstanceMetadataUpdate) SetExtensions(l lysand.Extensions) *InstanceMetadataUpdate {
|
||||
imu.mutation.SetExtensions(l)
|
||||
func (imu *InstanceMetadataUpdate) SetExtensions(v versia.Extensions) *InstanceMetadataUpdate {
|
||||
imu.mutation.SetExtensions(v)
|
||||
return imu
|
||||
}
|
||||
|
||||
|
|
@ -845,8 +845,8 @@ func (imuo *InstanceMetadataUpdateOne) SetNillableURI(s *string) *InstanceMetada
|
|||
}
|
||||
|
||||
// SetExtensions sets the "extensions" field.
|
||||
func (imuo *InstanceMetadataUpdateOne) SetExtensions(l lysand.Extensions) *InstanceMetadataUpdateOne {
|
||||
imuo.mutation.SetExtensions(l)
|
||||
func (imuo *InstanceMetadataUpdateOne) SetExtensions(v versia.Extensions) *InstanceMetadataUpdateOne {
|
||||
imuo.mutation.SetExtensions(v)
|
||||
return imuo
|
||||
}
|
||||
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -19,7 +19,7 @@ import (
|
|||
"github.com/lysand-org/versia-go/ent/note"
|
||||
"github.com/lysand-org/versia-go/ent/predicate"
|
||||
"github.com/lysand-org/versia-go/ent/user"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
"github.com/lysand-org/versia-go/pkg/versia"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -47,7 +47,7 @@ type AttachmentMutation struct {
|
|||
id *uuid.UUID
|
||||
isRemote *bool
|
||||
uri *string
|
||||
extensions *lysand.Extensions
|
||||
extensions *versia.Extensions
|
||||
created_at *time.Time
|
||||
updated_at *time.Time
|
||||
description *string
|
||||
|
|
@ -247,12 +247,12 @@ func (m *AttachmentMutation) ResetURI() {
|
|||
}
|
||||
|
||||
// SetExtensions sets the "extensions" field.
|
||||
func (m *AttachmentMutation) SetExtensions(l lysand.Extensions) {
|
||||
m.extensions = &l
|
||||
func (m *AttachmentMutation) SetExtensions(v versia.Extensions) {
|
||||
m.extensions = &v
|
||||
}
|
||||
|
||||
// Extensions returns the value of the "extensions" field in the mutation.
|
||||
func (m *AttachmentMutation) Extensions() (r lysand.Extensions, exists bool) {
|
||||
func (m *AttachmentMutation) Extensions() (r versia.Extensions, exists bool) {
|
||||
v := m.extensions
|
||||
if v == nil {
|
||||
return
|
||||
|
|
@ -263,7 +263,7 @@ func (m *AttachmentMutation) Extensions() (r lysand.Extensions, exists bool) {
|
|||
// OldExtensions returns the old "extensions" field's value of the Attachment entity.
|
||||
// If the Attachment object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *AttachmentMutation) OldExtensions(ctx context.Context) (v lysand.Extensions, err error) {
|
||||
func (m *AttachmentMutation) OldExtensions(ctx context.Context) (v versia.Extensions, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, errors.New("OldExtensions is only allowed on UpdateOne operations")
|
||||
}
|
||||
|
|
@ -983,7 +983,7 @@ func (m *AttachmentMutation) SetField(name string, value ent.Value) error {
|
|||
m.SetURI(v)
|
||||
return nil
|
||||
case attachment.FieldExtensions:
|
||||
v, ok := value.(lysand.Extensions)
|
||||
v, ok := value.(versia.Extensions)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
|
|
@ -1311,7 +1311,7 @@ type FollowMutation struct {
|
|||
id *uuid.UUID
|
||||
isRemote *bool
|
||||
uri *string
|
||||
extensions *lysand.Extensions
|
||||
extensions *versia.Extensions
|
||||
created_at *time.Time
|
||||
updated_at *time.Time
|
||||
status *follow.Status
|
||||
|
|
@ -1502,12 +1502,12 @@ func (m *FollowMutation) ResetURI() {
|
|||
}
|
||||
|
||||
// SetExtensions sets the "extensions" field.
|
||||
func (m *FollowMutation) SetExtensions(l lysand.Extensions) {
|
||||
m.extensions = &l
|
||||
func (m *FollowMutation) SetExtensions(v versia.Extensions) {
|
||||
m.extensions = &v
|
||||
}
|
||||
|
||||
// Extensions returns the value of the "extensions" field in the mutation.
|
||||
func (m *FollowMutation) Extensions() (r lysand.Extensions, exists bool) {
|
||||
func (m *FollowMutation) Extensions() (r versia.Extensions, exists bool) {
|
||||
v := m.extensions
|
||||
if v == nil {
|
||||
return
|
||||
|
|
@ -1518,7 +1518,7 @@ func (m *FollowMutation) Extensions() (r lysand.Extensions, exists bool) {
|
|||
// OldExtensions returns the old "extensions" field's value of the Follow entity.
|
||||
// If the Follow object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *FollowMutation) OldExtensions(ctx context.Context) (v lysand.Extensions, err error) {
|
||||
func (m *FollowMutation) OldExtensions(ctx context.Context) (v versia.Extensions, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, errors.New("OldExtensions is only allowed on UpdateOne operations")
|
||||
}
|
||||
|
|
@ -1841,7 +1841,7 @@ func (m *FollowMutation) SetField(name string, value ent.Value) error {
|
|||
m.SetURI(v)
|
||||
return nil
|
||||
case follow.FieldExtensions:
|
||||
v, ok := value.(lysand.Extensions)
|
||||
v, ok := value.(versia.Extensions)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
|
|
@ -2419,7 +2419,7 @@ type InstanceMetadataMutation struct {
|
|||
id *uuid.UUID
|
||||
isRemote *bool
|
||||
uri *string
|
||||
extensions *lysand.Extensions
|
||||
extensions *versia.Extensions
|
||||
created_at *time.Time
|
||||
updated_at *time.Time
|
||||
name *string
|
||||
|
|
@ -2633,12 +2633,12 @@ func (m *InstanceMetadataMutation) ResetURI() {
|
|||
}
|
||||
|
||||
// SetExtensions sets the "extensions" field.
|
||||
func (m *InstanceMetadataMutation) SetExtensions(l lysand.Extensions) {
|
||||
m.extensions = &l
|
||||
func (m *InstanceMetadataMutation) SetExtensions(v versia.Extensions) {
|
||||
m.extensions = &v
|
||||
}
|
||||
|
||||
// Extensions returns the value of the "extensions" field in the mutation.
|
||||
func (m *InstanceMetadataMutation) Extensions() (r lysand.Extensions, exists bool) {
|
||||
func (m *InstanceMetadataMutation) Extensions() (r versia.Extensions, exists bool) {
|
||||
v := m.extensions
|
||||
if v == nil {
|
||||
return
|
||||
|
|
@ -2649,7 +2649,7 @@ func (m *InstanceMetadataMutation) Extensions() (r lysand.Extensions, exists boo
|
|||
// OldExtensions returns the old "extensions" field's value of the InstanceMetadata entity.
|
||||
// If the InstanceMetadata object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *InstanceMetadataMutation) OldExtensions(ctx context.Context) (v lysand.Extensions, err error) {
|
||||
func (m *InstanceMetadataMutation) OldExtensions(ctx context.Context) (v versia.Extensions, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, errors.New("OldExtensions is only allowed on UpdateOne operations")
|
||||
}
|
||||
|
|
@ -3878,7 +3878,7 @@ func (m *InstanceMetadataMutation) SetField(name string, value ent.Value) error
|
|||
m.SetURI(v)
|
||||
return nil
|
||||
case instancemetadata.FieldExtensions:
|
||||
v, ok := value.(lysand.Extensions)
|
||||
v, ok := value.(versia.Extensions)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
|
|
@ -4331,7 +4331,7 @@ type NoteMutation struct {
|
|||
id *uuid.UUID
|
||||
isRemote *bool
|
||||
uri *string
|
||||
extensions *lysand.Extensions
|
||||
extensions *versia.Extensions
|
||||
created_at *time.Time
|
||||
updated_at *time.Time
|
||||
subject *string
|
||||
|
|
@ -4529,12 +4529,12 @@ func (m *NoteMutation) ResetURI() {
|
|||
}
|
||||
|
||||
// SetExtensions sets the "extensions" field.
|
||||
func (m *NoteMutation) SetExtensions(l lysand.Extensions) {
|
||||
m.extensions = &l
|
||||
func (m *NoteMutation) SetExtensions(v versia.Extensions) {
|
||||
m.extensions = &v
|
||||
}
|
||||
|
||||
// Extensions returns the value of the "extensions" field in the mutation.
|
||||
func (m *NoteMutation) Extensions() (r lysand.Extensions, exists bool) {
|
||||
func (m *NoteMutation) Extensions() (r versia.Extensions, exists bool) {
|
||||
v := m.extensions
|
||||
if v == nil {
|
||||
return
|
||||
|
|
@ -4545,7 +4545,7 @@ func (m *NoteMutation) Extensions() (r lysand.Extensions, exists bool) {
|
|||
// OldExtensions returns the old "extensions" field's value of the Note entity.
|
||||
// If the Note object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *NoteMutation) OldExtensions(ctx context.Context) (v lysand.Extensions, err error) {
|
||||
func (m *NoteMutation) OldExtensions(ctx context.Context) (v versia.Extensions, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, errors.New("OldExtensions is only allowed on UpdateOne operations")
|
||||
}
|
||||
|
|
@ -5079,7 +5079,7 @@ func (m *NoteMutation) SetField(name string, value ent.Value) error {
|
|||
m.SetURI(v)
|
||||
return nil
|
||||
case note.FieldExtensions:
|
||||
v, ok := value.(lysand.Extensions)
|
||||
v, ok := value.(versia.Extensions)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
|
|
@ -5352,7 +5352,7 @@ type UserMutation struct {
|
|||
id *uuid.UUID
|
||||
isRemote *bool
|
||||
uri *string
|
||||
extensions *lysand.Extensions
|
||||
extensions *versia.Extensions
|
||||
created_at *time.Time
|
||||
updated_at *time.Time
|
||||
username *string
|
||||
|
|
@ -5365,8 +5365,8 @@ type UserMutation struct {
|
|||
privateKey *[]byte
|
||||
indexable *bool
|
||||
privacyLevel *user.PrivacyLevel
|
||||
fields *[]lysand.Field
|
||||
appendfields []lysand.Field
|
||||
fields *[]versia.UserField
|
||||
appendfields []versia.UserField
|
||||
inbox *string
|
||||
featured *string
|
||||
followers *string
|
||||
|
|
@ -5574,12 +5574,12 @@ func (m *UserMutation) ResetURI() {
|
|||
}
|
||||
|
||||
// SetExtensions sets the "extensions" field.
|
||||
func (m *UserMutation) SetExtensions(l lysand.Extensions) {
|
||||
m.extensions = &l
|
||||
func (m *UserMutation) SetExtensions(v versia.Extensions) {
|
||||
m.extensions = &v
|
||||
}
|
||||
|
||||
// Extensions returns the value of the "extensions" field in the mutation.
|
||||
func (m *UserMutation) Extensions() (r lysand.Extensions, exists bool) {
|
||||
func (m *UserMutation) Extensions() (r versia.Extensions, exists bool) {
|
||||
v := m.extensions
|
||||
if v == nil {
|
||||
return
|
||||
|
|
@ -5590,7 +5590,7 @@ func (m *UserMutation) Extensions() (r lysand.Extensions, exists bool) {
|
|||
// OldExtensions returns the old "extensions" field's value of the User entity.
|
||||
// If the User object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *UserMutation) OldExtensions(ctx context.Context) (v lysand.Extensions, err error) {
|
||||
func (m *UserMutation) OldExtensions(ctx context.Context) (v versia.Extensions, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, errors.New("OldExtensions is only allowed on UpdateOne operations")
|
||||
}
|
||||
|
|
@ -6094,13 +6094,13 @@ func (m *UserMutation) ResetPrivacyLevel() {
|
|||
}
|
||||
|
||||
// SetFields sets the "fields" field.
|
||||
func (m *UserMutation) SetFields(l []lysand.Field) {
|
||||
m.fields = &l
|
||||
func (m *UserMutation) SetFields(vf []versia.UserField) {
|
||||
m.fields = &vf
|
||||
m.appendfields = nil
|
||||
}
|
||||
|
||||
// GetFields returns the value of the "fields" field in the mutation.
|
||||
func (m *UserMutation) GetFields() (r []lysand.Field, exists bool) {
|
||||
func (m *UserMutation) GetFields() (r []versia.UserField, exists bool) {
|
||||
v := m.fields
|
||||
if v == nil {
|
||||
return
|
||||
|
|
@ -6111,7 +6111,7 @@ func (m *UserMutation) GetFields() (r []lysand.Field, exists bool) {
|
|||
// OldFields returns the old "fields" field's value of the User entity.
|
||||
// If the User object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *UserMutation) OldFields(ctx context.Context) (v []lysand.Field, err error) {
|
||||
func (m *UserMutation) OldFields(ctx context.Context) (v []versia.UserField, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, errors.New("OldFields is only allowed on UpdateOne operations")
|
||||
}
|
||||
|
|
@ -6125,13 +6125,13 @@ func (m *UserMutation) OldFields(ctx context.Context) (v []lysand.Field, err err
|
|||
return oldValue.Fields, nil
|
||||
}
|
||||
|
||||
// AppendFields adds l to the "fields" field.
|
||||
func (m *UserMutation) AppendFields(l []lysand.Field) {
|
||||
m.appendfields = append(m.appendfields, l...)
|
||||
// AppendFields adds vf to the "fields" field.
|
||||
func (m *UserMutation) AppendFields(vf []versia.UserField) {
|
||||
m.appendfields = append(m.appendfields, vf...)
|
||||
}
|
||||
|
||||
// AppendedFields returns the list of values that were appended to the "fields" field in this mutation.
|
||||
func (m *UserMutation) AppendedFields() ([]lysand.Field, bool) {
|
||||
func (m *UserMutation) AppendedFields() ([]versia.UserField, bool) {
|
||||
if len(m.appendfields) == 0 {
|
||||
return nil, false
|
||||
}
|
||||
|
|
@ -6895,7 +6895,7 @@ func (m *UserMutation) SetField(name string, value ent.Value) error {
|
|||
m.SetURI(v)
|
||||
return nil
|
||||
case user.FieldExtensions:
|
||||
v, ok := value.(lysand.Extensions)
|
||||
v, ok := value.(versia.Extensions)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
|
|
@ -6986,7 +6986,7 @@ func (m *UserMutation) SetField(name string, value ent.Value) error {
|
|||
m.SetPrivacyLevel(v)
|
||||
return nil
|
||||
case user.FieldFields:
|
||||
v, ok := value.([]lysand.Field)
|
||||
v, ok := value.([]versia.UserField)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import (
|
|||
"github.com/google/uuid"
|
||||
"github.com/lysand-org/versia-go/ent/note"
|
||||
"github.com/lysand-org/versia-go/ent/user"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
"github.com/lysand-org/versia-go/pkg/versia"
|
||||
)
|
||||
|
||||
// Note is the model entity for the Note schema.
|
||||
|
|
@ -26,7 +26,7 @@ type Note struct {
|
|||
// URI holds the value of the "uri" field.
|
||||
URI string `json:"uri,omitempty"`
|
||||
// Extensions holds the value of the "extensions" field.
|
||||
Extensions lysand.Extensions `json:"extensions,omitempty"`
|
||||
Extensions versia.Extensions `json:"extensions,omitempty"`
|
||||
// CreatedAt holds the value of the "created_at" field.
|
||||
CreatedAt time.Time `json:"created_at,omitempty"`
|
||||
// UpdatedAt holds the value of the "updated_at" field.
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import (
|
|||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"github.com/google/uuid"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
"github.com/lysand-org/versia-go/pkg/versia"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -109,7 +109,7 @@ var (
|
|||
// URIValidator is a validator for the "uri" field. It is called by the builders before save.
|
||||
URIValidator func(string) error
|
||||
// DefaultExtensions holds the default value on creation for the "extensions" field.
|
||||
DefaultExtensions lysand.Extensions
|
||||
DefaultExtensions versia.Extensions
|
||||
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
|
||||
DefaultCreatedAt func() time.Time
|
||||
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ import (
|
|||
"github.com/lysand-org/versia-go/ent/attachment"
|
||||
"github.com/lysand-org/versia-go/ent/note"
|
||||
"github.com/lysand-org/versia-go/ent/user"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
"github.com/lysand-org/versia-go/pkg/versia"
|
||||
)
|
||||
|
||||
// NoteCreate is the builder for creating a Note entity.
|
||||
|
|
@ -40,8 +40,8 @@ func (nc *NoteCreate) SetURI(s string) *NoteCreate {
|
|||
}
|
||||
|
||||
// SetExtensions sets the "extensions" field.
|
||||
func (nc *NoteCreate) SetExtensions(l lysand.Extensions) *NoteCreate {
|
||||
nc.mutation.SetExtensions(l)
|
||||
func (nc *NoteCreate) SetExtensions(v versia.Extensions) *NoteCreate {
|
||||
nc.mutation.SetExtensions(v)
|
||||
return nc
|
||||
}
|
||||
|
||||
|
|
@ -479,7 +479,7 @@ func (u *NoteUpsert) UpdateURI() *NoteUpsert {
|
|||
}
|
||||
|
||||
// SetExtensions sets the "extensions" field.
|
||||
func (u *NoteUpsert) SetExtensions(v lysand.Extensions) *NoteUpsert {
|
||||
func (u *NoteUpsert) SetExtensions(v versia.Extensions) *NoteUpsert {
|
||||
u.Set(note.FieldExtensions, v)
|
||||
return u
|
||||
}
|
||||
|
|
@ -636,7 +636,7 @@ func (u *NoteUpsertOne) UpdateURI() *NoteUpsertOne {
|
|||
}
|
||||
|
||||
// SetExtensions sets the "extensions" field.
|
||||
func (u *NoteUpsertOne) SetExtensions(v lysand.Extensions) *NoteUpsertOne {
|
||||
func (u *NoteUpsertOne) SetExtensions(v versia.Extensions) *NoteUpsertOne {
|
||||
return u.Update(func(s *NoteUpsert) {
|
||||
s.SetExtensions(v)
|
||||
})
|
||||
|
|
@ -973,7 +973,7 @@ func (u *NoteUpsertBulk) UpdateURI() *NoteUpsertBulk {
|
|||
}
|
||||
|
||||
// SetExtensions sets the "extensions" field.
|
||||
func (u *NoteUpsertBulk) SetExtensions(v lysand.Extensions) *NoteUpsertBulk {
|
||||
func (u *NoteUpsertBulk) SetExtensions(v versia.Extensions) *NoteUpsertBulk {
|
||||
return u.Update(func(s *NoteUpsert) {
|
||||
s.SetExtensions(v)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ import (
|
|||
"github.com/lysand-org/versia-go/ent/note"
|
||||
"github.com/lysand-org/versia-go/ent/predicate"
|
||||
"github.com/lysand-org/versia-go/ent/user"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
"github.com/lysand-org/versia-go/pkg/versia"
|
||||
)
|
||||
|
||||
// NoteUpdate is the builder for updating Note entities.
|
||||
|
|
@ -61,8 +61,8 @@ func (nu *NoteUpdate) SetNillableURI(s *string) *NoteUpdate {
|
|||
}
|
||||
|
||||
// SetExtensions sets the "extensions" field.
|
||||
func (nu *NoteUpdate) SetExtensions(l lysand.Extensions) *NoteUpdate {
|
||||
nu.mutation.SetExtensions(l)
|
||||
func (nu *NoteUpdate) SetExtensions(v versia.Extensions) *NoteUpdate {
|
||||
nu.mutation.SetExtensions(v)
|
||||
return nu
|
||||
}
|
||||
|
||||
|
|
@ -494,8 +494,8 @@ func (nuo *NoteUpdateOne) SetNillableURI(s *string) *NoteUpdateOne {
|
|||
}
|
||||
|
||||
// SetExtensions sets the "extensions" field.
|
||||
func (nuo *NoteUpdateOne) SetExtensions(l lysand.Extensions) *NoteUpdateOne {
|
||||
nuo.mutation.SetExtensions(l)
|
||||
func (nuo *NoteUpdateOne) SetExtensions(v versia.Extensions) *NoteUpdateOne {
|
||||
nuo.mutation.SetExtensions(v)
|
||||
return nuo
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import (
|
|||
"github.com/lysand-org/versia-go/ent/note"
|
||||
"github.com/lysand-org/versia-go/ent/schema"
|
||||
"github.com/lysand-org/versia-go/ent/user"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
"github.com/lysand-org/versia-go/pkg/versia"
|
||||
)
|
||||
|
||||
// The init function reads all schema descriptors with runtime code
|
||||
|
|
@ -32,7 +32,7 @@ func init() {
|
|||
// attachmentDescExtensions is the schema descriptor for extensions field.
|
||||
attachmentDescExtensions := attachmentMixinFields0[3].Descriptor()
|
||||
// attachment.DefaultExtensions holds the default value on creation for the extensions field.
|
||||
attachment.DefaultExtensions = attachmentDescExtensions.Default.(lysand.Extensions)
|
||||
attachment.DefaultExtensions = attachmentDescExtensions.Default.(versia.Extensions)
|
||||
// attachmentDescCreatedAt is the schema descriptor for created_at field.
|
||||
attachmentDescCreatedAt := attachmentMixinFields0[4].Descriptor()
|
||||
// attachment.DefaultCreatedAt holds the default value on creation for the created_at field.
|
||||
|
|
@ -63,7 +63,7 @@ func init() {
|
|||
// followDescExtensions is the schema descriptor for extensions field.
|
||||
followDescExtensions := followMixinFields0[3].Descriptor()
|
||||
// follow.DefaultExtensions holds the default value on creation for the extensions field.
|
||||
follow.DefaultExtensions = followDescExtensions.Default.(lysand.Extensions)
|
||||
follow.DefaultExtensions = followDescExtensions.Default.(versia.Extensions)
|
||||
// followDescCreatedAt is the schema descriptor for created_at field.
|
||||
followDescCreatedAt := followMixinFields0[4].Descriptor()
|
||||
// follow.DefaultCreatedAt holds the default value on creation for the created_at field.
|
||||
|
|
@ -96,7 +96,7 @@ func init() {
|
|||
// instancemetadataDescExtensions is the schema descriptor for extensions field.
|
||||
instancemetadataDescExtensions := instancemetadataMixinFields0[3].Descriptor()
|
||||
// instancemetadata.DefaultExtensions holds the default value on creation for the extensions field.
|
||||
instancemetadata.DefaultExtensions = instancemetadataDescExtensions.Default.(lysand.Extensions)
|
||||
instancemetadata.DefaultExtensions = instancemetadataDescExtensions.Default.(versia.Extensions)
|
||||
// instancemetadataDescCreatedAt is the schema descriptor for created_at field.
|
||||
instancemetadataDescCreatedAt := instancemetadataMixinFields0[4].Descriptor()
|
||||
// instancemetadata.DefaultCreatedAt holds the default value on creation for the created_at field.
|
||||
|
|
@ -175,7 +175,7 @@ func init() {
|
|||
// noteDescExtensions is the schema descriptor for extensions field.
|
||||
noteDescExtensions := noteMixinFields0[3].Descriptor()
|
||||
// note.DefaultExtensions holds the default value on creation for the extensions field.
|
||||
note.DefaultExtensions = noteDescExtensions.Default.(lysand.Extensions)
|
||||
note.DefaultExtensions = noteDescExtensions.Default.(versia.Extensions)
|
||||
// noteDescCreatedAt is the schema descriptor for created_at field.
|
||||
noteDescCreatedAt := noteMixinFields0[4].Descriptor()
|
||||
// note.DefaultCreatedAt holds the default value on creation for the created_at field.
|
||||
|
|
@ -210,7 +210,7 @@ func init() {
|
|||
// userDescExtensions is the schema descriptor for extensions field.
|
||||
userDescExtensions := userMixinFields0[3].Descriptor()
|
||||
// user.DefaultExtensions holds the default value on creation for the extensions field.
|
||||
user.DefaultExtensions = userDescExtensions.Default.(lysand.Extensions)
|
||||
user.DefaultExtensions = userDescExtensions.Default.(versia.Extensions)
|
||||
// userDescCreatedAt is the schema descriptor for created_at field.
|
||||
userDescCreatedAt := userMixinFields0[4].Descriptor()
|
||||
// user.DefaultCreatedAt holds the default value on creation for the created_at field.
|
||||
|
|
@ -250,7 +250,7 @@ func init() {
|
|||
// userDescFields is the schema descriptor for fields field.
|
||||
userDescFields := userFields[10].Descriptor()
|
||||
// user.DefaultFields holds the default value on creation for the fields field.
|
||||
user.DefaultFields = userDescFields.Default.([]lysand.Field)
|
||||
user.DefaultFields = userDescFields.Default.([]versia.UserField)
|
||||
// userDescInbox is the schema descriptor for inbox field.
|
||||
userDescInbox := userFields[11].Descriptor()
|
||||
// user.InboxValidator is a validator for the "inbox" field. It is called by the builders before save.
|
||||
|
|
|
|||
|
|
@ -1,14 +1,13 @@
|
|||
package schema
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/field"
|
||||
"entgo.io/ent/schema/mixin"
|
||||
"github.com/google/uuid"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
"github.com/lysand-org/versia-go/pkg/versia"
|
||||
"net/url"
|
||||
"time"
|
||||
)
|
||||
|
||||
type LysandEntityMixin struct{ mixin.Schema }
|
||||
|
|
@ -23,7 +22,7 @@ func (LysandEntityMixin) Fields() []ent.Field {
|
|||
field.Bool("isRemote"),
|
||||
field.String("uri").Validate(ValidateURI),
|
||||
|
||||
field.JSON("extensions", lysand.Extensions{}).Default(lysand.Extensions{}),
|
||||
field.JSON("extensions", versia.Extensions{}).Default(versia.Extensions{}),
|
||||
|
||||
field.Time("created_at").
|
||||
Immutable().
|
||||
|
|
|
|||
|
|
@ -1,13 +1,12 @@
|
|||
package schema
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"regexp"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
"errors"
|
||||
"github.com/lysand-org/versia-go/pkg/versia"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
@ -45,7 +44,7 @@ func (User) Fields() []ent.Field {
|
|||
Values("public", "restricted", "private").
|
||||
Default("public"),
|
||||
|
||||
field.JSON("fields", []lysand.Field{}).Default([]lysand.Field{}),
|
||||
field.JSON("fields", []versia.UserField{}).Default([]versia.UserField{}),
|
||||
|
||||
field.String("inbox").Validate(ValidateURI),
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import (
|
|||
"github.com/google/uuid"
|
||||
"github.com/lysand-org/versia-go/ent/image"
|
||||
"github.com/lysand-org/versia-go/ent/user"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
"github.com/lysand-org/versia-go/pkg/versia"
|
||||
)
|
||||
|
||||
// User is the model entity for the User schema.
|
||||
|
|
@ -26,7 +26,7 @@ type User struct {
|
|||
// URI holds the value of the "uri" field.
|
||||
URI string `json:"uri,omitempty"`
|
||||
// Extensions holds the value of the "extensions" field.
|
||||
Extensions lysand.Extensions `json:"extensions,omitempty"`
|
||||
Extensions versia.Extensions `json:"extensions,omitempty"`
|
||||
// CreatedAt holds the value of the "created_at" field.
|
||||
CreatedAt time.Time `json:"created_at,omitempty"`
|
||||
// UpdatedAt holds the value of the "updated_at" field.
|
||||
|
|
@ -52,7 +52,7 @@ type User struct {
|
|||
// PrivacyLevel holds the value of the "privacyLevel" field.
|
||||
PrivacyLevel user.PrivacyLevel `json:"privacyLevel,omitempty"`
|
||||
// Fields holds the value of the "fields" field.
|
||||
Fields []lysand.Field `json:"fields,omitempty"`
|
||||
Fields []versia.UserField `json:"fields,omitempty"`
|
||||
// Inbox holds the value of the "inbox" field.
|
||||
Inbox string `json:"inbox,omitempty"`
|
||||
// Featured holds the value of the "featured" field.
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import (
|
|||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"github.com/google/uuid"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
"github.com/lysand-org/versia-go/pkg/versia"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -185,7 +185,7 @@ var (
|
|||
// URIValidator is a validator for the "uri" field. It is called by the builders before save.
|
||||
URIValidator func(string) error
|
||||
// DefaultExtensions holds the default value on creation for the "extensions" field.
|
||||
DefaultExtensions lysand.Extensions
|
||||
DefaultExtensions versia.Extensions
|
||||
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
|
||||
DefaultCreatedAt func() time.Time
|
||||
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
|
||||
|
|
@ -199,7 +199,7 @@ var (
|
|||
// DefaultIndexable holds the default value on creation for the "indexable" field.
|
||||
DefaultIndexable bool
|
||||
// DefaultFields holds the default value on creation for the "fields" field.
|
||||
DefaultFields []lysand.Field
|
||||
DefaultFields []versia.UserField
|
||||
// InboxValidator is a validator for the "inbox" field. It is called by the builders before save.
|
||||
InboxValidator func(string) error
|
||||
// FeaturedValidator is a validator for the "featured" field. It is called by the builders before save.
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ import (
|
|||
"github.com/lysand-org/versia-go/ent/instancemetadata"
|
||||
"github.com/lysand-org/versia-go/ent/note"
|
||||
"github.com/lysand-org/versia-go/ent/user"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
"github.com/lysand-org/versia-go/pkg/versia"
|
||||
)
|
||||
|
||||
// UserCreate is the builder for creating a User entity.
|
||||
|
|
@ -41,8 +41,8 @@ func (uc *UserCreate) SetURI(s string) *UserCreate {
|
|||
}
|
||||
|
||||
// SetExtensions sets the "extensions" field.
|
||||
func (uc *UserCreate) SetExtensions(l lysand.Extensions) *UserCreate {
|
||||
uc.mutation.SetExtensions(l)
|
||||
func (uc *UserCreate) SetExtensions(v versia.Extensions) *UserCreate {
|
||||
uc.mutation.SetExtensions(v)
|
||||
return uc
|
||||
}
|
||||
|
||||
|
|
@ -167,8 +167,8 @@ func (uc *UserCreate) SetNillablePrivacyLevel(ul *user.PrivacyLevel) *UserCreate
|
|||
}
|
||||
|
||||
// SetFields sets the "fields" field.
|
||||
func (uc *UserCreate) SetFields(l []lysand.Field) *UserCreate {
|
||||
uc.mutation.SetFields(l)
|
||||
func (uc *UserCreate) SetFields(vf []versia.UserField) *UserCreate {
|
||||
uc.mutation.SetFields(vf)
|
||||
return uc
|
||||
}
|
||||
|
||||
|
|
@ -803,7 +803,7 @@ func (u *UserUpsert) UpdateURI() *UserUpsert {
|
|||
}
|
||||
|
||||
// SetExtensions sets the "extensions" field.
|
||||
func (u *UserUpsert) SetExtensions(v lysand.Extensions) *UserUpsert {
|
||||
func (u *UserUpsert) SetExtensions(v versia.Extensions) *UserUpsert {
|
||||
u.Set(user.FieldExtensions, v)
|
||||
return u
|
||||
}
|
||||
|
|
@ -971,7 +971,7 @@ func (u *UserUpsert) UpdatePrivacyLevel() *UserUpsert {
|
|||
}
|
||||
|
||||
// SetFields sets the "fields" field.
|
||||
func (u *UserUpsert) SetFields(v []lysand.Field) *UserUpsert {
|
||||
func (u *UserUpsert) SetFields(v []versia.UserField) *UserUpsert {
|
||||
u.Set(user.FieldFields, v)
|
||||
return u
|
||||
}
|
||||
|
|
@ -1122,7 +1122,7 @@ func (u *UserUpsertOne) UpdateURI() *UserUpsertOne {
|
|||
}
|
||||
|
||||
// SetExtensions sets the "extensions" field.
|
||||
func (u *UserUpsertOne) SetExtensions(v lysand.Extensions) *UserUpsertOne {
|
||||
func (u *UserUpsertOne) SetExtensions(v versia.Extensions) *UserUpsertOne {
|
||||
return u.Update(func(s *UserUpsert) {
|
||||
s.SetExtensions(v)
|
||||
})
|
||||
|
|
@ -1318,7 +1318,7 @@ func (u *UserUpsertOne) UpdatePrivacyLevel() *UserUpsertOne {
|
|||
}
|
||||
|
||||
// SetFields sets the "fields" field.
|
||||
func (u *UserUpsertOne) SetFields(v []lysand.Field) *UserUpsertOne {
|
||||
func (u *UserUpsertOne) SetFields(v []versia.UserField) *UserUpsertOne {
|
||||
return u.Update(func(s *UserUpsert) {
|
||||
s.SetFields(v)
|
||||
})
|
||||
|
|
@ -1648,7 +1648,7 @@ func (u *UserUpsertBulk) UpdateURI() *UserUpsertBulk {
|
|||
}
|
||||
|
||||
// SetExtensions sets the "extensions" field.
|
||||
func (u *UserUpsertBulk) SetExtensions(v lysand.Extensions) *UserUpsertBulk {
|
||||
func (u *UserUpsertBulk) SetExtensions(v versia.Extensions) *UserUpsertBulk {
|
||||
return u.Update(func(s *UserUpsert) {
|
||||
s.SetExtensions(v)
|
||||
})
|
||||
|
|
@ -1844,7 +1844,7 @@ func (u *UserUpsertBulk) UpdatePrivacyLevel() *UserUpsertBulk {
|
|||
}
|
||||
|
||||
// SetFields sets the "fields" field.
|
||||
func (u *UserUpsertBulk) SetFields(v []lysand.Field) *UserUpsertBulk {
|
||||
func (u *UserUpsertBulk) SetFields(v []versia.UserField) *UserUpsertBulk {
|
||||
return u.Update(func(s *UserUpsert) {
|
||||
s.SetFields(v)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ import (
|
|||
"github.com/lysand-org/versia-go/ent/note"
|
||||
"github.com/lysand-org/versia-go/ent/predicate"
|
||||
"github.com/lysand-org/versia-go/ent/user"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
"github.com/lysand-org/versia-go/pkg/versia"
|
||||
)
|
||||
|
||||
// UserUpdate is the builder for updating User entities.
|
||||
|
|
@ -63,8 +63,8 @@ func (uu *UserUpdate) SetNillableURI(s *string) *UserUpdate {
|
|||
}
|
||||
|
||||
// SetExtensions sets the "extensions" field.
|
||||
func (uu *UserUpdate) SetExtensions(l lysand.Extensions) *UserUpdate {
|
||||
uu.mutation.SetExtensions(l)
|
||||
func (uu *UserUpdate) SetExtensions(v versia.Extensions) *UserUpdate {
|
||||
uu.mutation.SetExtensions(v)
|
||||
return uu
|
||||
}
|
||||
|
||||
|
|
@ -215,14 +215,14 @@ func (uu *UserUpdate) SetNillablePrivacyLevel(ul *user.PrivacyLevel) *UserUpdate
|
|||
}
|
||||
|
||||
// SetFields sets the "fields" field.
|
||||
func (uu *UserUpdate) SetFields(l []lysand.Field) *UserUpdate {
|
||||
uu.mutation.SetFields(l)
|
||||
func (uu *UserUpdate) SetFields(vf []versia.UserField) *UserUpdate {
|
||||
uu.mutation.SetFields(vf)
|
||||
return uu
|
||||
}
|
||||
|
||||
// AppendFields appends l to the "fields" field.
|
||||
func (uu *UserUpdate) AppendFields(l []lysand.Field) *UserUpdate {
|
||||
uu.mutation.AppendFields(l)
|
||||
// AppendFields appends vf to the "fields" field.
|
||||
func (uu *UserUpdate) AppendFields(vf []versia.UserField) *UserUpdate {
|
||||
uu.mutation.AppendFields(vf)
|
||||
return uu
|
||||
}
|
||||
|
||||
|
|
@ -1038,8 +1038,8 @@ func (uuo *UserUpdateOne) SetNillableURI(s *string) *UserUpdateOne {
|
|||
}
|
||||
|
||||
// SetExtensions sets the "extensions" field.
|
||||
func (uuo *UserUpdateOne) SetExtensions(l lysand.Extensions) *UserUpdateOne {
|
||||
uuo.mutation.SetExtensions(l)
|
||||
func (uuo *UserUpdateOne) SetExtensions(v versia.Extensions) *UserUpdateOne {
|
||||
uuo.mutation.SetExtensions(v)
|
||||
return uuo
|
||||
}
|
||||
|
||||
|
|
@ -1190,14 +1190,14 @@ func (uuo *UserUpdateOne) SetNillablePrivacyLevel(ul *user.PrivacyLevel) *UserUp
|
|||
}
|
||||
|
||||
// SetFields sets the "fields" field.
|
||||
func (uuo *UserUpdateOne) SetFields(l []lysand.Field) *UserUpdateOne {
|
||||
uuo.mutation.SetFields(l)
|
||||
func (uuo *UserUpdateOne) SetFields(vf []versia.UserField) *UserUpdateOne {
|
||||
uuo.mutation.SetFields(vf)
|
||||
return uuo
|
||||
}
|
||||
|
||||
// AppendFields appends l to the "fields" field.
|
||||
func (uuo *UserUpdateOne) AppendFields(l []lysand.Field) *UserUpdateOne {
|
||||
uuo.mutation.AppendFields(l)
|
||||
// AppendFields appends vf to the "fields" field.
|
||||
func (uuo *UserUpdateOne) AppendFields(vf []versia.UserField) *UserUpdateOne {
|
||||
uuo.mutation.AppendFields(vf)
|
||||
return uuo
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,8 @@ package api_schema
|
|||
|
||||
import (
|
||||
"github.com/google/uuid"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
"github.com/lysand-org/versia-go/pkg/versia"
|
||||
versiautils "github.com/lysand-org/versia-go/pkg/versia/utils"
|
||||
)
|
||||
|
||||
type Note struct {
|
||||
|
|
@ -12,7 +13,7 @@ type Note struct {
|
|||
type FetchNoteResponse = APIResponse[Note]
|
||||
|
||||
type CreateNoteRequest struct {
|
||||
Content string `json:"content" validate:"required,min=1,max=1024"`
|
||||
Visibility lysand.PublicationVisibility `json:"visibility" validate:"required,oneof=public private direct"`
|
||||
Mentions []lysand.URL `json:"mentions"`
|
||||
Content string `json:"content" validate:"required,min=1,max=1024"`
|
||||
Visibility versia.NoteVisibility `json:"visibility" validate:"required,oneof=public unlisted private direct"`
|
||||
Mentions []versiautils.URL `json:"mentions"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package api_schema
|
|||
|
||||
import (
|
||||
"github.com/google/uuid"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
"github.com/lysand-org/versia-go/pkg/versia"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
|
|
@ -10,7 +10,7 @@ type User struct {
|
|||
Username string `json:"username"`
|
||||
}
|
||||
|
||||
type LysandUser lysand.User
|
||||
type LysandUser versia.User
|
||||
|
||||
type FetchUserResponse = APIResponse[User]
|
||||
|
||||
|
|
@ -23,3 +23,32 @@ type SearchUserRequest struct {
|
|||
Username string `query:"username" validate:"required,username_regex,min=1,max=32"`
|
||||
Domain *string `query:"domain" validate:"domain_regex"`
|
||||
}
|
||||
|
||||
//var ErrInvalidUserMention = errors.New("invalid user mention")
|
||||
//func (r *SearchUserRequest) UnmarshalJSON(raw []byte) error {
|
||||
// var s string
|
||||
// if err := json.Unmarshal(raw, &s); err != nil {
|
||||
// return err
|
||||
// }
|
||||
//
|
||||
// s = strings.TrimPrefix(s, "@")
|
||||
// spl := strings.Split(s, "@")
|
||||
//
|
||||
// if len(spl) > 2 {
|
||||
// return ErrInvalidUserMention
|
||||
// }
|
||||
//
|
||||
// username := spl[0]
|
||||
//
|
||||
// var domain *string
|
||||
// if len(spl) > 1 {
|
||||
// domain = &spl[1]
|
||||
// }
|
||||
//
|
||||
// *r = SearchUserRequest{
|
||||
// Username: username,
|
||||
// Domain: domain,
|
||||
// }
|
||||
//
|
||||
// return nil
|
||||
//}
|
||||
|
|
|
|||
|
|
@ -2,15 +2,16 @@ package entity
|
|||
|
||||
import (
|
||||
"github.com/lysand-org/versia-go/ent"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
"github.com/lysand-org/versia-go/pkg/versia"
|
||||
versiautils "github.com/lysand-org/versia-go/pkg/versia/utils"
|
||||
)
|
||||
|
||||
type Follow struct {
|
||||
*ent.Follow
|
||||
|
||||
URI *lysand.URL
|
||||
FollowerURI *lysand.URL
|
||||
FolloweeURI *lysand.URL
|
||||
URI *versiautils.URL
|
||||
FollowerURI *versiautils.URL
|
||||
FolloweeURI *versiautils.URL
|
||||
}
|
||||
|
||||
func NewFollow(dbFollow *ent.Follow) (*Follow, error) {
|
||||
|
|
@ -18,17 +19,17 @@ func NewFollow(dbFollow *ent.Follow) (*Follow, error) {
|
|||
|
||||
var err error
|
||||
|
||||
f.URI, err = lysand.ParseURL(dbFollow.URI)
|
||||
f.URI, err = versiautils.ParseURL(dbFollow.URI)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
f.FollowerURI, err = lysand.ParseURL(dbFollow.Edges.Follower.URI)
|
||||
f.FollowerURI, err = versiautils.ParseURL(dbFollow.Edges.Follower.URI)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
f.FolloweeURI, err = lysand.ParseURL(dbFollow.Edges.Followee.URI)
|
||||
f.FolloweeURI, err = versiautils.ParseURL(dbFollow.Edges.Followee.URI)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -36,12 +37,12 @@ func NewFollow(dbFollow *ent.Follow) (*Follow, error) {
|
|||
return f, nil
|
||||
}
|
||||
|
||||
func (f Follow) ToLysand() *lysand.Follow {
|
||||
return &lysand.Follow{
|
||||
Entity: lysand.Entity{
|
||||
func (f Follow) ToLysand() *versia.Follow {
|
||||
return &versia.Follow{
|
||||
Entity: versia.Entity{
|
||||
ID: f.ID,
|
||||
URI: f.URI,
|
||||
CreatedAt: lysand.TimeFromStd(f.CreatedAt),
|
||||
CreatedAt: versiautils.Time(f.CreatedAt),
|
||||
Extensions: f.Extensions,
|
||||
},
|
||||
Author: f.FollowerURI,
|
||||
|
|
@ -49,12 +50,12 @@ func (f Follow) ToLysand() *lysand.Follow {
|
|||
}
|
||||
}
|
||||
|
||||
func (f Follow) ToLysandAccept() *lysand.FollowAccept {
|
||||
return &lysand.FollowAccept{
|
||||
Entity: lysand.Entity{
|
||||
func (f Follow) ToLysandAccept() *versia.FollowAccept {
|
||||
return &versia.FollowAccept{
|
||||
Entity: versia.Entity{
|
||||
ID: f.ID,
|
||||
URI: f.URI,
|
||||
CreatedAt: lysand.TimeFromStd(f.CreatedAt),
|
||||
CreatedAt: versiautils.Time(f.CreatedAt),
|
||||
Extensions: f.Extensions,
|
||||
},
|
||||
Author: f.FolloweeURI,
|
||||
|
|
@ -62,12 +63,12 @@ func (f Follow) ToLysandAccept() *lysand.FollowAccept {
|
|||
}
|
||||
}
|
||||
|
||||
func (f Follow) ToLysandReject() *lysand.FollowReject {
|
||||
return &lysand.FollowReject{
|
||||
Entity: lysand.Entity{
|
||||
func (f Follow) ToLysandReject() *versia.FollowReject {
|
||||
return &versia.FollowReject{
|
||||
Entity: versia.Entity{
|
||||
ID: f.ID,
|
||||
URI: f.URI,
|
||||
CreatedAt: lysand.TimeFromStd(f.CreatedAt),
|
||||
CreatedAt: versiautils.Time(f.CreatedAt),
|
||||
Extensions: f.Extensions,
|
||||
},
|
||||
Author: f.FolloweeURI,
|
||||
|
|
|
|||
|
|
@ -2,30 +2,31 @@ package entity
|
|||
|
||||
import (
|
||||
"github.com/lysand-org/versia-go/ent"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
"github.com/lysand-org/versia-go/pkg/versia"
|
||||
versiautils "github.com/lysand-org/versia-go/pkg/versia/utils"
|
||||
)
|
||||
|
||||
type Note struct {
|
||||
*ent.Note
|
||||
URI *lysand.URL
|
||||
Content lysand.TextContentTypeMap
|
||||
URI *versiautils.URL
|
||||
Content versiautils.TextContentTypeMap
|
||||
Author *User
|
||||
Mentions []User
|
||||
MentionURIs []lysand.URL
|
||||
MentionURIs []versiautils.URL
|
||||
}
|
||||
|
||||
func NewNote(dbNote *ent.Note) (*Note, error) {
|
||||
n := &Note{
|
||||
Note: dbNote,
|
||||
Content: lysand.TextContentTypeMap{
|
||||
"text/plain": lysand.TextContent{Content: dbNote.Content},
|
||||
Content: versiautils.TextContentTypeMap{
|
||||
"text/plain": versiautils.TextContent{Content: dbNote.Content},
|
||||
},
|
||||
Mentions: make([]User, 0, len(dbNote.Edges.Mentions)),
|
||||
MentionURIs: make([]lysand.URL, 0, len(dbNote.Edges.Mentions)),
|
||||
MentionURIs: make([]versiautils.URL, 0, len(dbNote.Edges.Mentions)),
|
||||
}
|
||||
|
||||
var err error
|
||||
if n.URI, err = lysand.ParseURL(dbNote.URI); err != nil {
|
||||
if n.URI, err = versiautils.ParseURL(dbNote.URI); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if n.Author, err = NewUser(dbNote.Edges.Author); err != nil {
|
||||
|
|
@ -45,12 +46,12 @@ func NewNote(dbNote *ent.Note) (*Note, error) {
|
|||
return n, nil
|
||||
}
|
||||
|
||||
func (n Note) ToLysand() lysand.Note {
|
||||
return lysand.Note{
|
||||
Entity: lysand.Entity{
|
||||
func (n Note) ToLysand() versia.Note {
|
||||
return versia.Note{
|
||||
Entity: versia.Entity{
|
||||
ID: n.ID,
|
||||
URI: n.URI,
|
||||
CreatedAt: lysand.TimeFromStd(n.CreatedAt),
|
||||
CreatedAt: versiautils.Time(n.CreatedAt),
|
||||
Extensions: n.Extensions,
|
||||
},
|
||||
Author: n.Author.URI,
|
||||
|
|
@ -65,6 +66,6 @@ func (n Note) ToLysand() lysand.Note {
|
|||
Mentions: n.MentionURIs,
|
||||
Subject: n.Subject,
|
||||
IsSensitive: &n.IsSensitive,
|
||||
Visibility: lysand.PublicationVisibility(n.Visibility),
|
||||
Visibility: versia.NoteVisibility(n.Visibility),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,31 +2,32 @@ package entity
|
|||
|
||||
import (
|
||||
"github.com/lysand-org/versia-go/ent"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
versiacrypto "github.com/lysand-org/versia-go/pkg/lysand/crypto"
|
||||
"github.com/lysand-org/versia-go/pkg/versia"
|
||||
versiacrypto "github.com/lysand-org/versia-go/pkg/versia/crypto"
|
||||
versiautils "github.com/lysand-org/versia-go/pkg/versia/utils"
|
||||
)
|
||||
|
||||
type InstanceMetadata struct {
|
||||
*ent.InstanceMetadata
|
||||
|
||||
Moderators []User
|
||||
ModeratorsCollection *lysand.URL
|
||||
ModeratorsCollection *versiautils.URL
|
||||
|
||||
Admins []User
|
||||
AdminsCollection *lysand.URL
|
||||
AdminsCollection *versiautils.URL
|
||||
|
||||
SharedInbox *lysand.URL
|
||||
SharedInbox *versiautils.URL
|
||||
|
||||
PublicKey *lysand.SPKIPublicKey
|
||||
PublicKey *versiacrypto.SPKIPublicKey
|
||||
|
||||
Logo *lysand.ImageContentTypeMap
|
||||
Banner *lysand.ImageContentTypeMap
|
||||
Logo *versiautils.ImageContentTypeMap
|
||||
Banner *versiautils.ImageContentTypeMap
|
||||
}
|
||||
|
||||
func NewInstanceMetadata(dbData *ent.InstanceMetadata) (*InstanceMetadata, error) {
|
||||
n := &InstanceMetadata{
|
||||
InstanceMetadata: dbData,
|
||||
PublicKey: &lysand.SPKIPublicKey{},
|
||||
PublicKey: &versiacrypto.SPKIPublicKey{},
|
||||
}
|
||||
|
||||
var err error
|
||||
|
|
@ -34,16 +35,16 @@ func NewInstanceMetadata(dbData *ent.InstanceMetadata) (*InstanceMetadata, error
|
|||
return nil, err
|
||||
}
|
||||
|
||||
if n.SharedInbox, err = lysand.ParseURL(dbData.SharedInboxURI); err != nil {
|
||||
if n.SharedInbox, err = versiautils.ParseURL(dbData.SharedInboxURI); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if dbData.ModeratorsURI != nil {
|
||||
if n.ModeratorsCollection, err = lysand.ParseURL(*dbData.ModeratorsURI); err != nil {
|
||||
if n.ModeratorsCollection, err = versiautils.ParseURL(*dbData.ModeratorsURI); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if dbData.AdminsURI != nil {
|
||||
if n.AdminsCollection, err = lysand.ParseURL(*dbData.AdminsURI); err != nil {
|
||||
if n.AdminsCollection, err = versiautils.ParseURL(*dbData.AdminsURI); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
|
@ -69,8 +70,8 @@ func NewInstanceMetadata(dbData *ent.InstanceMetadata) (*InstanceMetadata, error
|
|||
return n, nil
|
||||
}
|
||||
|
||||
func (m InstanceMetadata) ToLysand() lysand.InstanceMetadata {
|
||||
return lysand.InstanceMetadata{
|
||||
func (m InstanceMetadata) ToLysand() versia.InstanceMetadata {
|
||||
return versia.InstanceMetadata{
|
||||
Extensions: m.Extensions,
|
||||
Name: m.Name,
|
||||
Description: m.Description,
|
||||
|
|
@ -80,15 +81,15 @@ func (m InstanceMetadata) ToLysand() lysand.InstanceMetadata {
|
|||
Admins: m.AdminsCollection,
|
||||
Logo: m.Logo,
|
||||
Banner: m.Banner,
|
||||
PublicKey: lysand.InstancePublicKey{
|
||||
PublicKey: versia.InstancePublicKey{
|
||||
Algorithm: m.PublicKeyAlgorithm,
|
||||
Key: m.PublicKey,
|
||||
},
|
||||
Software: lysand.InstanceSoftware{
|
||||
Software: versia.InstanceSoftware{
|
||||
Name: m.SoftwareName,
|
||||
Version: m.SoftwareVersion,
|
||||
},
|
||||
Compatibility: lysand.InstanceCompatibility{
|
||||
Compatibility: versia.InstanceCompatibility{
|
||||
Versions: m.SupportedVersions,
|
||||
Extensions: m.SupportedExtensions,
|
||||
},
|
||||
|
|
|
|||
|
|
@ -2,36 +2,37 @@ package entity
|
|||
|
||||
import (
|
||||
"github.com/lysand-org/versia-go/internal/helpers"
|
||||
versiacrypto "github.com/lysand-org/versia-go/pkg/lysand/crypto"
|
||||
"github.com/lysand-org/versia-go/pkg/versia"
|
||||
versiacrypto "github.com/lysand-org/versia-go/pkg/versia/crypto"
|
||||
versiautils "github.com/lysand-org/versia-go/pkg/versia/utils"
|
||||
"net/url"
|
||||
|
||||
"github.com/lysand-org/versia-go/ent"
|
||||
"github.com/lysand-org/versia-go/internal/utils"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
*ent.User
|
||||
|
||||
URI *lysand.URL
|
||||
PKActorURI *lysand.URL
|
||||
PublicKey *lysand.SPKIPublicKey
|
||||
Inbox *lysand.URL
|
||||
Outbox *lysand.URL
|
||||
Featured *lysand.URL
|
||||
Followers *lysand.URL
|
||||
Following *lysand.URL
|
||||
URI *versiautils.URL
|
||||
PKActorURI *versiautils.URL
|
||||
PublicKey *versiacrypto.SPKIPublicKey
|
||||
Inbox *versiautils.URL
|
||||
Outbox *versiautils.URL
|
||||
Featured *versiautils.URL
|
||||
Followers *versiautils.URL
|
||||
Following *versiautils.URL
|
||||
|
||||
DisplayName string
|
||||
LysandAvatar lysand.ImageContentTypeMap
|
||||
LysandBiography lysand.TextContentTypeMap
|
||||
Signer lysand.Signer
|
||||
LysandAvatar versiautils.ImageContentTypeMap
|
||||
LysandBiography versiautils.TextContentTypeMap
|
||||
Signer versiacrypto.Signer
|
||||
}
|
||||
|
||||
func NewUser(dbData *ent.User) (*User, error) {
|
||||
u := &User{
|
||||
User: dbData,
|
||||
PublicKey: &lysand.SPKIPublicKey{
|
||||
PublicKey: &versiacrypto.SPKIPublicKey{
|
||||
Key: nil,
|
||||
Algorithm: dbData.PublicKeyAlgorithm,
|
||||
},
|
||||
|
|
@ -50,29 +51,29 @@ func NewUser(dbData *ent.User) (*User, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
if u.URI, err = lysand.ParseURL(dbData.URI); err != nil {
|
||||
if u.URI, err = versiautils.ParseURL(dbData.URI); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if u.PKActorURI, err = lysand.ParseURL(dbData.PublicKeyActor); err != nil {
|
||||
if u.PKActorURI, err = versiautils.ParseURL(dbData.PublicKeyActor); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if u.Inbox, err = lysand.ParseURL(dbData.Inbox); err != nil {
|
||||
if u.Inbox, err = versiautils.ParseURL(dbData.Inbox); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if u.Outbox, err = lysand.ParseURL(dbData.Outbox); err != nil {
|
||||
if u.Outbox, err = versiautils.ParseURL(dbData.Outbox); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if u.Featured, err = lysand.ParseURL(dbData.Featured); err != nil {
|
||||
if u.Featured, err = versiautils.ParseURL(dbData.Featured); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if u.Followers, err = lysand.ParseURL(dbData.Followers); err != nil {
|
||||
if u.Followers, err = versiautils.ParseURL(dbData.Followers); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if u.Following, err = lysand.ParseURL(dbData.Following); err != nil {
|
||||
if u.Following, err = versiautils.ParseURL(dbData.Following); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
u.Signer = lysand.Signer{
|
||||
u.Signer = versiacrypto.Signer{
|
||||
PrivateKey: dbData.PrivateKey,
|
||||
UserURL: u.URI.ToStd(),
|
||||
}
|
||||
|
|
@ -80,12 +81,12 @@ func NewUser(dbData *ent.User) (*User, error) {
|
|||
return u, nil
|
||||
}
|
||||
|
||||
func (u User) ToLysand() *lysand.User {
|
||||
return &lysand.User{
|
||||
Entity: lysand.Entity{
|
||||
func (u User) ToLysand() *versia.User {
|
||||
return &versia.User{
|
||||
Entity: versia.Entity{
|
||||
ID: u.ID,
|
||||
URI: u.URI,
|
||||
CreatedAt: lysand.TimeFromStd(u.CreatedAt),
|
||||
CreatedAt: versiautils.Time(u.CreatedAt),
|
||||
Extensions: u.Extensions,
|
||||
},
|
||||
DisplayName: helpers.StringPtr(u.DisplayName),
|
||||
|
|
@ -93,7 +94,7 @@ func (u User) ToLysand() *lysand.User {
|
|||
Avatar: u.LysandAvatar,
|
||||
Header: imageMap(u.Edges.HeaderImage),
|
||||
Indexable: u.Indexable,
|
||||
PublicKey: lysand.UserPublicKey{
|
||||
PublicKey: versia.UserPublicKey{
|
||||
Actor: u.PKActorURI,
|
||||
Algorithm: u.PublicKeyAlgorithm,
|
||||
Key: u.PublicKey,
|
||||
|
|
@ -109,33 +110,33 @@ func (u User) ToLysand() *lysand.User {
|
|||
}
|
||||
}
|
||||
|
||||
func lysandAvatar(u *ent.User) lysand.ImageContentTypeMap {
|
||||
func lysandAvatar(u *ent.User) versiautils.ImageContentTypeMap {
|
||||
if avatar := imageMap(u.Edges.AvatarImage); avatar != nil {
|
||||
return avatar
|
||||
}
|
||||
|
||||
return lysand.ImageContentTypeMap{
|
||||
"image/svg+xml": lysand.ImageContent{
|
||||
return versiautils.ImageContentTypeMap{
|
||||
"image/svg+xml": versiautils.ImageContent{
|
||||
Content: utils.DefaultAvatarURL(u.ID),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func lysandBiography(u *ent.User) lysand.TextContentTypeMap {
|
||||
func lysandBiography(u *ent.User) versiautils.TextContentTypeMap {
|
||||
if u.Biography == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// TODO: Render HTML
|
||||
|
||||
return lysand.TextContentTypeMap{
|
||||
"text/html": lysand.TextContent{
|
||||
return versiautils.TextContentTypeMap{
|
||||
"text/html": versiautils.TextContent{
|
||||
Content: *u.Biography,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func imageMap(i *ent.Image) lysand.ImageContentTypeMap {
|
||||
func imageMap(i *ent.Image) versiautils.ImageContentTypeMap {
|
||||
if i == nil {
|
||||
return nil
|
||||
}
|
||||
|
|
@ -145,9 +146,9 @@ func imageMap(i *ent.Image) lysand.ImageContentTypeMap {
|
|||
return nil
|
||||
}
|
||||
|
||||
return lysand.ImageContentTypeMap{
|
||||
return versiautils.ImageContentTypeMap{
|
||||
i.MimeType: {
|
||||
Content: (*lysand.URL)(u),
|
||||
Content: (*versiautils.URL)(u),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,11 +5,11 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"github.com/lysand-org/versia-go/internal/validators/val_impls"
|
||||
"github.com/lysand-org/versia-go/pkg/versia"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/google/uuid"
|
||||
"github.com/lysand-org/versia-go/internal/api_schema"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
)
|
||||
|
||||
func (i *Handler) LysandInbox(c *fiber.Ctx) error {
|
||||
|
|
@ -29,13 +29,13 @@ func (i *Handler) LysandInbox(c *fiber.Ctx) error {
|
|||
return api_schema.ErrBadRequest(nil)
|
||||
}
|
||||
|
||||
obj, err := lysand.ParseInboxObject(raw)
|
||||
obj, err := versia.ParseInboxObject(raw)
|
||||
if err != nil {
|
||||
i.log.Error(err, "Failed to parse inbox object")
|
||||
|
||||
if errors.Is(err, lysand.ErrUnknownType{}) {
|
||||
if errors.Is(err, versia.UnknownEntityTypeError{}) {
|
||||
return api_schema.ErrNotFound(map[string]any{
|
||||
"error": fmt.Sprintf("Unknown object type: %s", err.(lysand.ErrUnknownType).Type),
|
||||
"error": fmt.Sprintf("Unknown object type: %s", err.(versia.UnknownEntityTypeError).Type),
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import (
|
|||
"github.com/lysand-org/versia-go/internal/entity"
|
||||
"github.com/lysand-org/versia-go/internal/repository"
|
||||
"github.com/lysand-org/versia-go/internal/service"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
versiautils "github.com/lysand-org/versia-go/pkg/versia/utils"
|
||||
)
|
||||
|
||||
var _ repository.InstanceMetadataRepository = (*InstanceMetadataRepositoryImpl)(nil)
|
||||
|
|
@ -50,7 +50,7 @@ func (i *InstanceMetadataRepositoryImpl) GetByHost(ctx context.Context, host str
|
|||
return entity.NewInstanceMetadata(m)
|
||||
}
|
||||
|
||||
func (i *InstanceMetadataRepositoryImpl) ImportFromLysandByURI(ctx context.Context, uri *lysand.URL) (*entity.InstanceMetadata, error) {
|
||||
func (i *InstanceMetadataRepositoryImpl) ImportFromLysandByURI(ctx context.Context, uri *versiautils.URL) (*entity.InstanceMetadata, error) {
|
||||
s := i.telemetry.StartSpan(ctx, "function", "repo_impls/InstanceMetadataRepositoryImpl.ImportFromLysandByURI").
|
||||
AddAttribute("uri", uri.String())
|
||||
defer s.End()
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package repo_impls
|
|||
import (
|
||||
"context"
|
||||
"github.com/lysand-org/versia-go/internal/repository"
|
||||
"github.com/lysand-org/versia-go/pkg/versia"
|
||||
|
||||
"git.devminer.xyz/devminer/unitel"
|
||||
"github.com/go-logr/logr"
|
||||
|
|
@ -11,7 +12,6 @@ import (
|
|||
"github.com/lysand-org/versia-go/ent/note"
|
||||
"github.com/lysand-org/versia-go/internal/entity"
|
||||
"github.com/lysand-org/versia-go/internal/utils"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
)
|
||||
|
||||
var _ repository.NoteRepository = (*NoteRepositoryImpl)(nil)
|
||||
|
|
@ -62,7 +62,7 @@ func (i *NoteRepositoryImpl) NewNote(ctx context.Context, author *entity.User, c
|
|||
return entity.NewNote(n)
|
||||
}
|
||||
|
||||
func (i *NoteRepositoryImpl) ImportLysandNote(ctx context.Context, lNote *lysand.Note) (*entity.Note, error) {
|
||||
func (i *NoteRepositoryImpl) ImportLysandNote(ctx context.Context, lNote *versia.Note) (*entity.Note, error) {
|
||||
s := i.telemetry.StartSpan(ctx, "function", "repo_impls/NoteRepositoryImpl.ImportLysandNote")
|
||||
defer s.End()
|
||||
ctx = s.Context()
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import (
|
|||
"github.com/lysand-org/versia-go/config"
|
||||
"github.com/lysand-org/versia-go/internal/repository"
|
||||
"github.com/lysand-org/versia-go/internal/service"
|
||||
versiautils "github.com/lysand-org/versia-go/pkg/versia/utils"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
|
||||
"git.devminer.xyz/devminer/unitel"
|
||||
|
|
@ -17,7 +18,6 @@ import (
|
|||
"github.com/lysand-org/versia-go/ent/user"
|
||||
"github.com/lysand-org/versia-go/internal/entity"
|
||||
"github.com/lysand-org/versia-go/internal/utils"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
)
|
||||
|
||||
const bcryptCost = 12
|
||||
|
|
@ -84,7 +84,7 @@ func (i *UserRepositoryImpl) NewUser(ctx context.Context, username, password str
|
|||
return entity.NewUser(u)
|
||||
}
|
||||
|
||||
func (i *UserRepositoryImpl) ImportLysandUserByURI(ctx context.Context, uri *lysand.URL) (*entity.User, error) {
|
||||
func (i *UserRepositoryImpl) ImportLysandUserByURI(ctx context.Context, uri *versiautils.URL) (*entity.User, error) {
|
||||
s := i.telemetry.StartSpan(ctx, "function", "repo_impls/UserRepositoryImpl.ImportLysandUserByURI")
|
||||
defer s.End()
|
||||
ctx = s.Context()
|
||||
|
|
@ -163,7 +163,7 @@ func (i *UserRepositoryImpl) Discover(ctx context.Context, domain, username stri
|
|||
|
||||
l.V(2).Info("Found remote user", "userURI", wf.URI)
|
||||
|
||||
u, err := i.Resolve(ctx, lysand.URLFromStd(wf.URI))
|
||||
u, err := i.Resolve(ctx, versiautils.URLFromStd(wf.URI))
|
||||
if err != nil {
|
||||
l.Error(err, "Failed to resolve user")
|
||||
return nil, err
|
||||
|
|
@ -185,7 +185,7 @@ func (i *UserRepositoryImpl) Discover(ctx context.Context, domain, username stri
|
|||
return u, nil
|
||||
}
|
||||
|
||||
func (i *UserRepositoryImpl) Resolve(ctx context.Context, uri *lysand.URL) (*entity.User, error) {
|
||||
func (i *UserRepositoryImpl) Resolve(ctx context.Context, uri *versiautils.URL) (*entity.User, error) {
|
||||
s := i.telemetry.StartSpan(ctx, "function", "repo_impls/UserRepositoryImpl.Resolve")
|
||||
defer s.End()
|
||||
ctx = s.Context()
|
||||
|
|
@ -215,7 +215,7 @@ func (i *UserRepositoryImpl) Resolve(ctx context.Context, uri *lysand.URL) (*ent
|
|||
return u, nil
|
||||
}
|
||||
|
||||
func (i *UserRepositoryImpl) ResolveMultiple(ctx context.Context, uris []lysand.URL) ([]*entity.User, error) {
|
||||
func (i *UserRepositoryImpl) ResolveMultiple(ctx context.Context, uris []versiautils.URL) ([]*entity.User, error) {
|
||||
s := i.telemetry.StartSpan(ctx, "function", "repo_impls/UserRepositoryImpl.ResolveMultiple")
|
||||
defer s.End()
|
||||
ctx = s.Context()
|
||||
|
|
@ -340,7 +340,7 @@ func (i *UserRepositoryImpl) GetLocalByUsername(ctx context.Context, username st
|
|||
return entity.NewUser(u)
|
||||
}
|
||||
|
||||
func (i *UserRepositoryImpl) LookupByURI(ctx context.Context, uri *lysand.URL) (*entity.User, error) {
|
||||
func (i *UserRepositoryImpl) LookupByURI(ctx context.Context, uri *versiautils.URL) (*entity.User, error) {
|
||||
s := i.telemetry.StartSpan(ctx, "function", "repo_impls/UserRepositoryImpl.LookupByURI")
|
||||
defer s.End()
|
||||
ctx = s.Context()
|
||||
|
|
@ -367,7 +367,7 @@ func (i *UserRepositoryImpl) LookupByURI(ctx context.Context, uri *lysand.URL) (
|
|||
return entity.NewUser(u)
|
||||
}
|
||||
|
||||
func (i *UserRepositoryImpl) LookupByURIs(ctx context.Context, uris []lysand.URL) ([]*entity.User, error) {
|
||||
func (i *UserRepositoryImpl) LookupByURIs(ctx context.Context, uris []versiautils.URL) ([]*entity.User, error) {
|
||||
s := i.telemetry.StartSpan(ctx, "function", "repo_impls/UserRepositoryImpl.LookupByURIs")
|
||||
defer s.End()
|
||||
ctx = s.Context()
|
||||
|
|
|
|||
|
|
@ -3,15 +3,16 @@ package repository
|
|||
import (
|
||||
"context"
|
||||
"crypto/ed25519"
|
||||
"github.com/lysand-org/versia-go/pkg/versia"
|
||||
versiautils "github.com/lysand-org/versia-go/pkg/versia/utils"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/lysand-org/versia-go/internal/entity"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
)
|
||||
|
||||
type UserRepository interface {
|
||||
NewUser(ctx context.Context, username, password string, privateKey ed25519.PrivateKey, publicKey ed25519.PublicKey) (*entity.User, error)
|
||||
ImportLysandUserByURI(ctx context.Context, uri *lysand.URL) (*entity.User, error)
|
||||
ImportLysandUserByURI(ctx context.Context, uri *versiautils.URL) (*entity.User, error)
|
||||
|
||||
GetByID(ctx context.Context, id uuid.UUID) (*entity.User, error)
|
||||
GetLocalByID(ctx context.Context, id uuid.UUID) (*entity.User, error)
|
||||
|
|
@ -19,11 +20,11 @@ type UserRepository interface {
|
|||
|
||||
Discover(ctx context.Context, host, username string) (*entity.User, error)
|
||||
|
||||
Resolve(ctx context.Context, uri *lysand.URL) (*entity.User, error)
|
||||
ResolveMultiple(ctx context.Context, uris []lysand.URL) ([]*entity.User, error)
|
||||
Resolve(ctx context.Context, uri *versiautils.URL) (*entity.User, error)
|
||||
ResolveMultiple(ctx context.Context, uris []versiautils.URL) ([]*entity.User, error)
|
||||
|
||||
LookupByURI(ctx context.Context, uri *lysand.URL) (*entity.User, error)
|
||||
LookupByURIs(ctx context.Context, uris []lysand.URL) ([]*entity.User, error)
|
||||
LookupByURI(ctx context.Context, uri *versiautils.URL) (*entity.User, error)
|
||||
LookupByURIs(ctx context.Context, uris []versiautils.URL) ([]*entity.User, error)
|
||||
LookupByIDOrUsername(ctx context.Context, idOrUsername string) (*entity.User, error)
|
||||
}
|
||||
|
||||
|
|
@ -38,14 +39,14 @@ type FollowRepository interface {
|
|||
|
||||
type NoteRepository interface {
|
||||
NewNote(ctx context.Context, author *entity.User, content string, mentions []*entity.User) (*entity.Note, error)
|
||||
ImportLysandNote(ctx context.Context, lNote *lysand.Note) (*entity.Note, error)
|
||||
ImportLysandNote(ctx context.Context, lNote *versia.Note) (*entity.Note, error)
|
||||
|
||||
GetByID(ctx context.Context, idOrUsername uuid.UUID) (*entity.Note, error)
|
||||
}
|
||||
|
||||
type InstanceMetadataRepository interface {
|
||||
GetByHost(ctx context.Context, host string) (*entity.InstanceMetadata, error)
|
||||
ImportFromLysandByURI(ctx context.Context, uri *lysand.URL) (*entity.InstanceMetadata, error)
|
||||
ImportFromLysandByURI(ctx context.Context, uri *versiautils.URL) (*entity.InstanceMetadata, error)
|
||||
}
|
||||
|
||||
type Manager interface {
|
||||
|
|
|
|||
|
|
@ -4,11 +4,13 @@ import (
|
|||
"context"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/lysand-org/versia-go/internal/repository"
|
||||
"github.com/lysand-org/versia-go/pkg/versia"
|
||||
versiacrypto "github.com/lysand-org/versia-go/pkg/versia/crypto"
|
||||
versiautils "github.com/lysand-org/versia-go/pkg/versia/utils"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/lysand-org/versia-go/internal/api_schema"
|
||||
"github.com/lysand-org/versia-go/internal/entity"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
"github.com/lysand-org/versia-go/pkg/webfinger"
|
||||
)
|
||||
|
||||
|
|
@ -26,10 +28,10 @@ type UserService interface {
|
|||
|
||||
type FederationService interface {
|
||||
SendToInbox(ctx context.Context, author *entity.User, target *entity.User, object any) ([]byte, error)
|
||||
GetUser(ctx context.Context, uri *lysand.URL) (*lysand.User, error)
|
||||
GetUser(ctx context.Context, uri *versiautils.URL) (*versia.User, error)
|
||||
|
||||
DiscoverUser(ctx context.Context, baseURL, username string) (*webfinger.User, error)
|
||||
DiscoverInstance(ctx context.Context, baseURL string) (*lysand.InstanceMetadata, error)
|
||||
DiscoverInstance(ctx context.Context, baseURL string) (*versia.InstanceMetadata, error)
|
||||
}
|
||||
|
||||
type InboxService interface {
|
||||
|
|
@ -40,14 +42,14 @@ type NoteService interface {
|
|||
CreateNote(ctx context.Context, req api_schema.CreateNoteRequest) (*entity.Note, error)
|
||||
GetNote(ctx context.Context, id uuid.UUID) (*entity.Note, error)
|
||||
|
||||
ImportLysandNote(ctx context.Context, lNote *lysand.Note) (*entity.Note, error)
|
||||
ImportLysandNote(ctx context.Context, lNote *versia.Note) (*entity.Note, error)
|
||||
}
|
||||
|
||||
type FollowService interface {
|
||||
NewFollow(ctx context.Context, follower, followee *entity.User) (*entity.Follow, error)
|
||||
GetFollow(ctx context.Context, id uuid.UUID) (*entity.Follow, error)
|
||||
|
||||
ImportLysandFollow(ctx context.Context, lFollow *lysand.Follow) (*entity.Follow, error)
|
||||
ImportLysandFollow(ctx context.Context, lFollow *versia.Follow) (*entity.Follow, error)
|
||||
}
|
||||
|
||||
type InstanceMetadataService interface {
|
||||
|
|
@ -59,5 +61,5 @@ type TaskService interface {
|
|||
}
|
||||
|
||||
type RequestSigner interface {
|
||||
Sign(c *fiber.Ctx, signer lysand.Signer, body any) error
|
||||
Sign(c *fiber.Ctx, signer versiacrypto.Signer, body any) error
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import (
|
|||
"github.com/google/uuid"
|
||||
"github.com/lysand-org/versia-go/internal/repository"
|
||||
"github.com/lysand-org/versia-go/internal/service"
|
||||
"github.com/lysand-org/versia-go/pkg/versia"
|
||||
|
||||
"git.devminer.xyz/devminer/unitel"
|
||||
"github.com/go-logr/logr"
|
||||
|
|
@ -12,7 +13,6 @@ import (
|
|||
"github.com/lysand-org/versia-go/ent/user"
|
||||
"github.com/lysand-org/versia-go/internal/api_schema"
|
||||
"github.com/lysand-org/versia-go/internal/entity"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
)
|
||||
|
||||
var _ service.InboxService = (*InboxServiceImpl)(nil)
|
||||
|
|
@ -63,22 +63,17 @@ func (i InboxServiceImpl) Handle(ctx context.Context, obj any, userId uuid.UUID)
|
|||
|
||||
// TODO: Implement more types
|
||||
switch o := obj.(type) {
|
||||
case lysand.Note:
|
||||
case versia.Note:
|
||||
i.log.Info("Received note", "note", o)
|
||||
if err := i.handleNote(ctx, o, u); err != nil {
|
||||
i.log.Error(err, "Failed to handle note", "note", o)
|
||||
return err
|
||||
}
|
||||
|
||||
case lysand.Patch:
|
||||
i.log.Info("Received patch", "patch", o)
|
||||
case lysand.Follow:
|
||||
case versia.Follow:
|
||||
if err := i.handleFollow(ctx, o, u); err != nil {
|
||||
i.log.Error(err, "Failed to handle follow", "follow", o)
|
||||
return err
|
||||
}
|
||||
case lysand.Undo:
|
||||
i.log.Info("Received undo", "undo", o)
|
||||
default:
|
||||
i.log.Info("Unimplemented object type", "object", obj)
|
||||
return api_schema.ErrNotImplemented(nil)
|
||||
|
|
@ -88,7 +83,7 @@ func (i InboxServiceImpl) Handle(ctx context.Context, obj any, userId uuid.UUID)
|
|||
})
|
||||
}
|
||||
|
||||
func (i InboxServiceImpl) handleFollow(ctx context.Context, o lysand.Follow, u *entity.User) error {
|
||||
func (i InboxServiceImpl) handleFollow(ctx context.Context, o versia.Follow, u *entity.User) error {
|
||||
s := i.telemetry.StartSpan(ctx, "function", "svc_impls/InboxServiceImpl.handleFollow")
|
||||
defer s.End()
|
||||
ctx = s.Context()
|
||||
|
|
@ -130,7 +125,7 @@ func (i InboxServiceImpl) handleFollow(ctx context.Context, o lysand.Follow, u *
|
|||
return nil
|
||||
}
|
||||
|
||||
func (i InboxServiceImpl) handleNote(ctx context.Context, o lysand.Note, u *entity.User) error {
|
||||
func (i InboxServiceImpl) handleNote(ctx context.Context, o versia.Note, u *entity.User) error {
|
||||
s := i.telemetry.StartSpan(ctx, "function", "svc_impls/InboxServiceImpl.handleNote")
|
||||
defer s.End()
|
||||
ctx = s.Context()
|
||||
|
|
|
|||
|
|
@ -12,9 +12,10 @@ import (
|
|||
"github.com/go-logr/logr"
|
||||
"github.com/lysand-org/versia-go/internal/entity"
|
||||
"github.com/lysand-org/versia-go/internal/service"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
versiacrypto "github.com/lysand-org/versia-go/pkg/lysand/crypto"
|
||||
"github.com/lysand-org/versia-go/pkg/protoretry"
|
||||
"github.com/lysand-org/versia-go/pkg/versia"
|
||||
versiacrypto "github.com/lysand-org/versia-go/pkg/versia/crypto"
|
||||
versiautils "github.com/lysand-org/versia-go/pkg/versia/utils"
|
||||
"github.com/lysand-org/versia-go/pkg/webfinger"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
|
@ -29,14 +30,14 @@ var (
|
|||
type FederationServiceImpl struct {
|
||||
httpC *protoretry.Client
|
||||
|
||||
federationClient *lysand.FederationClient
|
||||
federationClient *versia.FederationClient
|
||||
|
||||
telemetry *unitel.Telemetry
|
||||
|
||||
log logr.Logger
|
||||
}
|
||||
|
||||
func NewFederationServiceImpl(httpClient *http.Client, federationClient *lysand.FederationClient, telemetry *unitel.Telemetry, log logr.Logger) *FederationServiceImpl {
|
||||
func NewFederationServiceImpl(httpClient *http.Client, federationClient *versia.FederationClient, telemetry *unitel.Telemetry, log logr.Logger) *FederationServiceImpl {
|
||||
return &FederationServiceImpl{
|
||||
httpC: protoretry.New(httpClient),
|
||||
federationClient: federationClient,
|
||||
|
|
@ -45,7 +46,7 @@ func NewFederationServiceImpl(httpClient *http.Client, federationClient *lysand.
|
|||
}
|
||||
}
|
||||
|
||||
func (i *FederationServiceImpl) GetUser(ctx context.Context, uri *lysand.URL) (*lysand.User, error) {
|
||||
func (i *FederationServiceImpl) GetUser(ctx context.Context, uri *versiautils.URL) (*versia.User, error) {
|
||||
s := i.telemetry.StartSpan(ctx, "function", "svc_impls/FederationServiceImpl.GetUser").
|
||||
AddAttribute("userURI", uri.String())
|
||||
defer s.End()
|
||||
|
|
@ -57,19 +58,19 @@ func (i *FederationServiceImpl) GetUser(ctx context.Context, uri *lysand.URL) (*
|
|||
return nil, err
|
||||
}
|
||||
|
||||
u := &lysand.User{}
|
||||
u := &versia.User{}
|
||||
if err := json.Unmarshal(body, u); err != nil {
|
||||
s.SetSimpleStatus(unitel.Error, err.Error())
|
||||
return nil, err
|
||||
}
|
||||
|
||||
fedHeaders, err := lysand.ExtractFederationHeaders(resp.Header)
|
||||
fedHeaders, err := versiacrypto.ExtractFederationHeaders(resp.Header)
|
||||
if err != nil {
|
||||
s.SetSimpleStatus(unitel.Error, err.Error())
|
||||
return nil, err
|
||||
}
|
||||
|
||||
v := lysand.Verifier{PublicKey: u.PublicKey.Key.Key}
|
||||
v := versiacrypto.Verifier{PublicKey: u.PublicKey.Key.Key}
|
||||
if !v.Verify("GET", uri.ToStd(), body, fedHeaders) {
|
||||
s.SetSimpleStatus(unitel.Error, ErrSignatureValidationFailed.Error())
|
||||
i.log.V(1).Error(ErrSignatureValidationFailed, "signature validation failed", "user", u.URI.String())
|
||||
|
|
@ -100,7 +101,7 @@ func (i *FederationServiceImpl) DiscoverUser(ctx context.Context, baseURL, usern
|
|||
return wf, nil
|
||||
}
|
||||
|
||||
func (i *FederationServiceImpl) DiscoverInstance(ctx context.Context, baseURL string) (*lysand.InstanceMetadata, error) {
|
||||
func (i *FederationServiceImpl) DiscoverInstance(ctx context.Context, baseURL string) (*versia.InstanceMetadata, error) {
|
||||
s := i.telemetry.StartSpan(ctx, "function", "svc_impls/FederationServiceImpl.DiscoverInstance").
|
||||
AddAttribute("baseURL", baseURL)
|
||||
defer s.End()
|
||||
|
|
@ -112,10 +113,10 @@ func (i *FederationServiceImpl) DiscoverInstance(ctx context.Context, baseURL st
|
|||
return nil, err
|
||||
} else if resp.StatusCode >= http.StatusBadRequest {
|
||||
s.SetSimpleStatus(unitel.Error, fmt.Sprintf("unexpected response code: %d", resp.StatusCode))
|
||||
return nil, &lysand.ResponseError{StatusCode: resp.StatusCode, URL: resp.Request.URL}
|
||||
return nil, &versia.ResponseError{StatusCode: resp.StatusCode, URL: resp.Request.URL}
|
||||
}
|
||||
|
||||
var metadata lysand.InstanceMetadata
|
||||
var metadata versia.InstanceMetadata
|
||||
if err := json.Unmarshal(body, &metadata); err != nil {
|
||||
s.SetSimpleStatus(unitel.Error, err.Error())
|
||||
return nil, err
|
||||
|
|
@ -150,7 +151,7 @@ func (i *FederationServiceImpl) SendToInbox(ctx context.Context, author *entity.
|
|||
return nil, err
|
||||
}
|
||||
|
||||
sigData := lysand.NewSignatureData("POST", base64.StdEncoding.EncodeToString(nonce), uri, versiacrypto.SHA256(body))
|
||||
sigData := versiacrypto.NewSignatureData("POST", base64.StdEncoding.EncodeToString(nonce), uri, versiacrypto.SHA256(body))
|
||||
sig := author.Signer.Sign(*sigData)
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "POST", uri.String(), bytes.NewReader(body))
|
||||
|
|
|
|||
|
|
@ -4,12 +4,12 @@ import (
|
|||
"context"
|
||||
"github.com/lysand-org/versia-go/internal/repository"
|
||||
"github.com/lysand-org/versia-go/internal/service"
|
||||
"github.com/lysand-org/versia-go/pkg/versia"
|
||||
|
||||
"git.devminer.xyz/devminer/unitel"
|
||||
"github.com/go-logr/logr"
|
||||
"github.com/google/uuid"
|
||||
"github.com/lysand-org/versia-go/internal/entity"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
)
|
||||
|
||||
var _ service.FollowService = (*FollowServiceImpl)(nil)
|
||||
|
|
@ -69,7 +69,7 @@ func (i FollowServiceImpl) GetFollow(ctx context.Context, id uuid.UUID) (*entity
|
|||
return f, nil
|
||||
}
|
||||
|
||||
func (i FollowServiceImpl) ImportLysandFollow(ctx context.Context, lFollow *lysand.Follow) (*entity.Follow, error) {
|
||||
func (i FollowServiceImpl) ImportLysandFollow(ctx context.Context, lFollow *versia.Follow) (*entity.Follow, error) {
|
||||
s := i.telemetry.StartSpan(ctx, "function", "svc_impls/FollowServiceImpl.ImportLysandFollow").
|
||||
AddAttribute("uri", lFollow.URI.String())
|
||||
defer s.End()
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"github.com/lysand-org/versia-go/internal/repository"
|
||||
"github.com/lysand-org/versia-go/internal/service"
|
||||
"github.com/lysand-org/versia-go/pkg/versia"
|
||||
"slices"
|
||||
|
||||
"git.devminer.xyz/devminer/unitel"
|
||||
|
|
@ -12,7 +13,6 @@ import (
|
|||
"github.com/lysand-org/versia-go/internal/api_schema"
|
||||
"github.com/lysand-org/versia-go/internal/entity"
|
||||
"github.com/lysand-org/versia-go/internal/tasks"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
)
|
||||
|
||||
var _ service.NoteService = (*NoteServiceImpl)(nil)
|
||||
|
|
@ -89,7 +89,7 @@ func (i NoteServiceImpl) GetNote(ctx context.Context, id uuid.UUID) (*entity.Not
|
|||
return i.repositories.Notes().GetByID(ctx, id)
|
||||
}
|
||||
|
||||
func (i NoteServiceImpl) ImportLysandNote(ctx context.Context, lNote *lysand.Note) (*entity.Note, error) {
|
||||
func (i NoteServiceImpl) ImportLysandNote(ctx context.Context, lNote *versia.Note) (*entity.Note, error) {
|
||||
s := i.telemetry.StartSpan(ctx, "function", "svc_impls/NoteServiceImpl.ImportLysandNote")
|
||||
defer s.End()
|
||||
ctx = s.Context()
|
||||
|
|
|
|||
|
|
@ -8,8 +8,7 @@ import (
|
|||
"github.com/go-logr/logr"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/lysand-org/versia-go/internal/service"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
versiacrypto "github.com/lysand-org/versia-go/pkg/lysand/crypto"
|
||||
versiacrypto "github.com/lysand-org/versia-go/pkg/versia/crypto"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
|
|
@ -28,7 +27,7 @@ func NewRequestSignerImpl(telemetry *unitel.Telemetry, log logr.Logger) *Request
|
|||
}
|
||||
}
|
||||
|
||||
func (i *RequestSignerImpl) Sign(c *fiber.Ctx, signer lysand.Signer, body any) error {
|
||||
func (i *RequestSignerImpl) Sign(c *fiber.Ctx, signer versiacrypto.Signer, body any) error {
|
||||
s := i.telemetry.StartSpan(c.UserContext(), "function", "svc_impls/RequestSignerImpl.Sign")
|
||||
defer s.End()
|
||||
|
||||
|
|
@ -50,7 +49,7 @@ func (i *RequestSignerImpl) Sign(c *fiber.Ctx, signer lysand.Signer, body any) e
|
|||
|
||||
digest := versiacrypto.SHA256(j)
|
||||
|
||||
d := lysand.NewSignatureData(c.Method(), nonce, uri, digest)
|
||||
d := versiacrypto.NewSignatureData(c.Method(), nonce, uri, digest)
|
||||
|
||||
signed := signer.Sign(*d)
|
||||
for k, v := range signed.Headers() {
|
||||
|
|
|
|||
|
|
@ -2,11 +2,10 @@ package utils
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/lysand-org/versia-go/config"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
versiautils "github.com/lysand-org/versia-go/pkg/versia/utils"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
var dicebearURL = &url.URL{
|
||||
|
|
@ -15,81 +14,81 @@ var dicebearURL = &url.URL{
|
|||
Path: "9.x/adventurer/svg",
|
||||
}
|
||||
|
||||
func UserAPIURL(uuid uuid.UUID) *lysand.URL {
|
||||
func UserAPIURL(uuid uuid.UUID) *versiautils.URL {
|
||||
newPath := &url.URL{Path: fmt.Sprintf("/api/users/%s/", uuid.String())}
|
||||
return lysand.URLFromStd(config.C.PublicAddress.ResolveReference(newPath))
|
||||
return versiautils.URLFromStd(config.C.PublicAddress.ResolveReference(newPath))
|
||||
}
|
||||
|
||||
func DefaultAvatarURL(uuid uuid.UUID) *lysand.URL {
|
||||
func DefaultAvatarURL(uuid uuid.UUID) *versiautils.URL {
|
||||
u := &url.URL{}
|
||||
q := u.Query()
|
||||
q.Set("seed", uuid.String())
|
||||
u.RawQuery = q.Encode()
|
||||
|
||||
return lysand.URLFromStd(dicebearURL.ResolveReference(u))
|
||||
return versiautils.URLFromStd(dicebearURL.ResolveReference(u))
|
||||
}
|
||||
|
||||
func UserInboxAPIURL(uuid uuid.UUID) *lysand.URL {
|
||||
func UserInboxAPIURL(uuid uuid.UUID) *versiautils.URL {
|
||||
newPath := &url.URL{Path: "./inbox"}
|
||||
return UserAPIURL(uuid).ResolveReference(newPath)
|
||||
}
|
||||
|
||||
func UserOutboxAPIURL(uuid uuid.UUID) *lysand.URL {
|
||||
func UserOutboxAPIURL(uuid uuid.UUID) *versiautils.URL {
|
||||
newPath := &url.URL{Path: "./outbox"}
|
||||
return UserAPIURL(uuid).ResolveReference(newPath)
|
||||
}
|
||||
|
||||
func UserFollowersAPIURL(uuid uuid.UUID) *lysand.URL {
|
||||
func UserFollowersAPIURL(uuid uuid.UUID) *versiautils.URL {
|
||||
newPath := &url.URL{Path: "./followers"}
|
||||
return UserAPIURL(uuid).ResolveReference(newPath)
|
||||
}
|
||||
|
||||
func UserFollowingAPIURL(uuid uuid.UUID) *lysand.URL {
|
||||
func UserFollowingAPIURL(uuid uuid.UUID) *versiautils.URL {
|
||||
newPath := &url.URL{Path: "./following"}
|
||||
return UserAPIURL(uuid).ResolveReference(newPath)
|
||||
}
|
||||
|
||||
func UserFeaturedAPIURL(uuid uuid.UUID) *lysand.URL {
|
||||
func UserFeaturedAPIURL(uuid uuid.UUID) *versiautils.URL {
|
||||
newPath := &url.URL{Path: "./featured"}
|
||||
return UserAPIURL(uuid).ResolveReference(newPath)
|
||||
}
|
||||
|
||||
func UserLikesAPIURL(uuid uuid.UUID) *lysand.URL {
|
||||
func UserLikesAPIURL(uuid uuid.UUID) *versiautils.URL {
|
||||
newPath := &url.URL{Path: "./likes"}
|
||||
return UserAPIURL(uuid).ResolveReference(newPath)
|
||||
}
|
||||
|
||||
func UserDislikesAPIURL(uuid uuid.UUID) *lysand.URL {
|
||||
func UserDislikesAPIURL(uuid uuid.UUID) *versiautils.URL {
|
||||
newPath := &url.URL{Path: "./dislikes"}
|
||||
return UserAPIURL(uuid).ResolveReference(newPath)
|
||||
}
|
||||
|
||||
func FollowAPIURL(uuid uuid.UUID) *lysand.URL {
|
||||
func FollowAPIURL(uuid uuid.UUID) *versiautils.URL {
|
||||
newPath := &url.URL{Path: fmt.Sprintf("/api/follows/%s/", uuid.String())}
|
||||
return lysand.URLFromStd(config.C.PublicAddress.ResolveReference(newPath))
|
||||
return versiautils.URLFromStd(config.C.PublicAddress.ResolveReference(newPath))
|
||||
}
|
||||
|
||||
func NoteAPIURL(uuid uuid.UUID) *lysand.URL {
|
||||
func NoteAPIURL(uuid uuid.UUID) *versiautils.URL {
|
||||
newPath := &url.URL{Path: fmt.Sprintf("/api/notes/%s/", uuid.String())}
|
||||
return lysand.URLFromStd(config.C.PublicAddress.ResolveReference(newPath))
|
||||
return versiautils.URLFromStd(config.C.PublicAddress.ResolveReference(newPath))
|
||||
}
|
||||
|
||||
func InstanceMetadataAPIURL() *lysand.URL {
|
||||
func InstanceMetadataAPIURL() *versiautils.URL {
|
||||
newPath := &url.URL{Path: "/.well-known/versia/"}
|
||||
return lysand.URLFromStd(config.C.PublicAddress.ResolveReference(newPath))
|
||||
return versiautils.URLFromStd(config.C.PublicAddress.ResolveReference(newPath))
|
||||
}
|
||||
|
||||
func InstanceMetadataAdminsAPIURL() *lysand.URL {
|
||||
func InstanceMetadataAdminsAPIURL() *versiautils.URL {
|
||||
newPath := &url.URL{Path: "/.well-known/versia/admins/"}
|
||||
return lysand.URLFromStd(config.C.PublicAddress.ResolveReference(newPath))
|
||||
return versiautils.URLFromStd(config.C.PublicAddress.ResolveReference(newPath))
|
||||
}
|
||||
|
||||
func InstanceMetadataModeratorsAPIURL() *lysand.URL {
|
||||
func InstanceMetadataModeratorsAPIURL() *versiautils.URL {
|
||||
newPath := &url.URL{Path: "/.well-known/versia/moderators/"}
|
||||
return lysand.URLFromStd(config.C.PublicAddress.ResolveReference(newPath))
|
||||
return versiautils.URLFromStd(config.C.PublicAddress.ResolveReference(newPath))
|
||||
}
|
||||
|
||||
func SharedInboxAPIURL() *lysand.URL {
|
||||
func SharedInboxAPIURL() *versiautils.URL {
|
||||
newPath := &url.URL{Path: "/api/inbox/"}
|
||||
return lysand.URLFromStd(config.C.PublicAddress.ResolveReference(newPath))
|
||||
return versiautils.URLFromStd(config.C.PublicAddress.ResolveReference(newPath))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,8 @@ import (
|
|||
"github.com/lysand-org/versia-go/internal/repository"
|
||||
"github.com/lysand-org/versia-go/internal/utils"
|
||||
"github.com/lysand-org/versia-go/internal/validators"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
versiacrypto "github.com/lysand-org/versia-go/pkg/versia/crypto"
|
||||
versiautils "github.com/lysand-org/versia-go/pkg/versia/utils"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
|
|
@ -42,13 +43,13 @@ func (i RequestValidatorImpl) Validate(ctx context.Context, r *http.Request) err
|
|||
|
||||
r = r.WithContext(ctx)
|
||||
|
||||
fedHeaders, err := lysand.ExtractFederationHeaders(r.Header)
|
||||
fedHeaders, err := versiacrypto.ExtractFederationHeaders(r.Header)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// TODO: Fetch user from database instead of using the URI
|
||||
user, err := i.repositories.Users().Resolve(ctx, lysand.URLFromStd(fedHeaders.SignedBy))
|
||||
user, err := i.repositories.Users().Resolve(ctx, versiautils.URLFromStd(fedHeaders.SignedBy))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -58,7 +59,7 @@ func (i RequestValidatorImpl) Validate(ctx context.Context, r *http.Request) err
|
|||
return err
|
||||
}
|
||||
|
||||
if !(lysand.Verifier{PublicKey: user.PublicKey.Key}).Verify(r.Method, r.URL, body, fedHeaders) {
|
||||
if !(versiacrypto.Verifier{PublicKey: user.PublicKey.Key}).Verify(r.Method, r.URL, body, fedHeaders) {
|
||||
i.log.WithCallDepth(1).Info("signature verification failed", "user", user.URI, "url", r.URL.Path)
|
||||
s.CaptureError(ErrInvalidSignature)
|
||||
|
||||
|
|
|
|||
8
main.go
8
main.go
|
|
@ -16,6 +16,7 @@ import (
|
|||
"github.com/lysand-org/versia-go/internal/repository/repo_impls"
|
||||
"github.com/lysand-org/versia-go/internal/service/svc_impls"
|
||||
"github.com/lysand-org/versia-go/internal/validators/val_impls"
|
||||
"github.com/lysand-org/versia-go/pkg/versia"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
|
|
@ -37,7 +38,6 @@ import (
|
|||
"github.com/lysand-org/versia-go/internal/handlers/user_handler"
|
||||
"github.com/lysand-org/versia-go/internal/tasks"
|
||||
"github.com/lysand-org/versia-go/internal/utils"
|
||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
||||
"github.com/lysand-org/versia-go/pkg/taskqueue"
|
||||
"github.com/nats-io/nats.go"
|
||||
"github.com/rs/zerolog"
|
||||
|
|
@ -73,9 +73,9 @@ func main() {
|
|||
),
|
||||
}
|
||||
|
||||
federationClient := lysand.NewClient(
|
||||
lysand.WithHTTPClient(httpClient),
|
||||
lysand.WithLogger(zerologr.New(&log.Logger).WithName("federation-client")),
|
||||
federationClient := versia.NewClient(
|
||||
versia.WithHTTPClient(httpClient),
|
||||
versia.WithLogger(zerologr.New(&log.Logger).WithName("federation-client")),
|
||||
)
|
||||
|
||||
log.Debug().Msg("Opening database connection")
|
||||
|
|
|
|||
|
|
@ -1,51 +0,0 @@
|
|||
package lysand
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
type Follow struct {
|
||||
Entity
|
||||
|
||||
// Author is the URL to the user that triggered the follow
|
||||
Author *URL `json:"author"`
|
||||
// Followee is the URL to the user that is being followed
|
||||
Followee *URL `json:"followee"`
|
||||
}
|
||||
|
||||
func (f Follow) MarshalJSON() ([]byte, error) {
|
||||
type follow Follow
|
||||
f2 := follow(f)
|
||||
f2.Type = "Follow"
|
||||
return json.Marshal(f2)
|
||||
}
|
||||
|
||||
type FollowAccept struct {
|
||||
Entity
|
||||
|
||||
// Author is the URL to the user that accepted the follow
|
||||
Author *URL `json:"author"`
|
||||
// Follower is the URL to the user that is now following the followee
|
||||
Follower *URL `json:"follower"`
|
||||
}
|
||||
|
||||
func (f FollowAccept) MarshalJSON() ([]byte, error) {
|
||||
type followAccept FollowAccept
|
||||
f2 := followAccept(f)
|
||||
f2.Type = "FollowAccept"
|
||||
return json.Marshal(f2)
|
||||
}
|
||||
|
||||
type FollowReject struct {
|
||||
Entity
|
||||
|
||||
// Author is the URL to the user that rejected the follow
|
||||
Author *URL `json:"author"`
|
||||
// Follower is the URL to the user that is no longer following the followee
|
||||
Follower *URL `json:"follower"`
|
||||
}
|
||||
|
||||
func (f FollowReject) MarshalJSON() ([]byte, error) {
|
||||
type followReject FollowReject
|
||||
f2 := followReject(f)
|
||||
f2.Type = "FollowReject"
|
||||
return json.Marshal(f2)
|
||||
}
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
package lysand
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
type Undo struct {
|
||||
Entity
|
||||
|
||||
// Author is the URL to the user that triggered the undo action
|
||||
Author *URL `json:"author"`
|
||||
// Object is the URL to the object that was undone
|
||||
Object *URL `json:"object"`
|
||||
}
|
||||
|
||||
func (u Undo) MarshalJSON() ([]byte, error) {
|
||||
type undo Undo
|
||||
u2 := undo(u)
|
||||
u2.Type = "Undo"
|
||||
return json.Marshal(u2)
|
||||
}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
package lysand
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
type Note Publication
|
||||
|
||||
func (n Note) MarshalJSON() ([]byte, error) {
|
||||
type note Note
|
||||
n2 := note(n)
|
||||
n2.Type = "Note"
|
||||
return json.Marshal(n2)
|
||||
}
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
package lysand
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// Patch is a type that represents a modification to a note. For more information, see the [Spec].
|
||||
//
|
||||
// [Spec]: https://lysand.org/objects/patch
|
||||
type Patch struct {
|
||||
Note
|
||||
|
||||
// PatchedID is the ID of the publication that was patched.
|
||||
// https://lysand.org/objects/patch#patched-id
|
||||
PatchedID uuid.UUID `json:"patched_id"`
|
||||
|
||||
// PatchedAt is the time that the publication was patched.
|
||||
// https://lysand.org/objects/patch#patched-at
|
||||
PatchedAt Time `json:"patched_at"`
|
||||
}
|
||||
|
||||
func (p Patch) MarshalJSON() ([]byte, error) {
|
||||
type patch Patch
|
||||
p2 := patch(p)
|
||||
p2.Type = "Patch"
|
||||
return json.Marshal(p2)
|
||||
}
|
||||
32
pkg/versia/action_delete.go
Normal file
32
pkg/versia/action_delete.go
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
package versia
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
versiautils "github.com/lysand-org/versia-go/pkg/versia/utils"
|
||||
)
|
||||
|
||||
// Delete signals the deletion of an entity. For more information, see the [Spec].
|
||||
// This entity does not have a URI.
|
||||
//
|
||||
// Implementations must ensure that the author of the Delete entity has the authorization to delete the target entity.
|
||||
//
|
||||
// [Spec]: https://versia.pub/entities/delete
|
||||
type Delete struct {
|
||||
Entity
|
||||
|
||||
// Author is the URL to the user that triggered the deletion
|
||||
Author *versiautils.URL `json:"author"`
|
||||
|
||||
// DeletedType is the type of the object that is being deleted
|
||||
DeletedType string `json:"deleted_type"`
|
||||
|
||||
// Deleted is the URL to the object that is being deleted
|
||||
Deleted *versiautils.URL `json:"deleted"`
|
||||
}
|
||||
|
||||
func (d Delete) MarshalJSON() ([]byte, error) {
|
||||
type a Delete
|
||||
d2 := a(d)
|
||||
d2.Type = "Delete"
|
||||
return json.Marshal(d2)
|
||||
}
|
||||
99
pkg/versia/action_follow.go
Normal file
99
pkg/versia/action_follow.go
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
package versia
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
versiautils "github.com/lysand-org/versia-go/pkg/versia/utils"
|
||||
)
|
||||
|
||||
// Follow defines a follow relationship between two users. For more information, see the [Spec].
|
||||
//
|
||||
// Once a follow relationship is established, the followee's instance should send all new notes from the followee to
|
||||
// the follower's inbox.
|
||||
//
|
||||
// [Spec]: https://versia.pub/entities/follow
|
||||
type Follow struct {
|
||||
Entity
|
||||
|
||||
// Author is the URL to the user that triggered the follow
|
||||
Author *versiautils.URL `json:"author"`
|
||||
|
||||
// Followee is the URL to the user that is being followed
|
||||
Followee *versiautils.URL `json:"followee"`
|
||||
}
|
||||
|
||||
func (f Follow) MarshalJSON() ([]byte, error) {
|
||||
type follow Follow
|
||||
f2 := follow(f)
|
||||
f2.Type = "Follow"
|
||||
return json.Marshal(f2)
|
||||
}
|
||||
|
||||
// FollowAccept accepts a Follow request, which will form the follow relationship between the two parties.
|
||||
// For more information, see the [Spec].
|
||||
//
|
||||
// This can only be sent by the Followee.
|
||||
//
|
||||
// [Spec]: https://versia.pub/entities/follow-accept
|
||||
type FollowAccept struct {
|
||||
Entity
|
||||
|
||||
// Author is the URL to the user that accepted the follow
|
||||
Author *versiautils.URL `json:"author"`
|
||||
|
||||
// Follower is the URL to the user that is now following the followee
|
||||
Follower *versiautils.URL `json:"follower"`
|
||||
}
|
||||
|
||||
func (f FollowAccept) MarshalJSON() ([]byte, error) {
|
||||
type followAccept FollowAccept
|
||||
f2 := followAccept(f)
|
||||
f2.Type = "FollowAccept"
|
||||
return json.Marshal(f2)
|
||||
}
|
||||
|
||||
// FollowReject rejects a Follow request, which will dismiss the follow relationship between the two parties.
|
||||
// For more information, see the [Spec].
|
||||
//
|
||||
// This can only be sent by the Followee and should not be confused with Unfollow, which can only be sent by the Follower.
|
||||
// FollowReject can still be sent after the relationship has been formed.
|
||||
//
|
||||
// [Spec]: https://versia.pub/entities/follow-reject
|
||||
type FollowReject struct {
|
||||
Entity
|
||||
|
||||
// Author is the URL to the user that rejected the follow
|
||||
Author *versiautils.URL `json:"author"`
|
||||
|
||||
// Follower is the URL to the user that is no longer following the followee
|
||||
Follower *versiautils.URL `json:"follower"`
|
||||
}
|
||||
|
||||
func (f FollowReject) MarshalJSON() ([]byte, error) {
|
||||
type followReject FollowReject
|
||||
f2 := followReject(f)
|
||||
f2.Type = "FollowReject"
|
||||
return json.Marshal(f2)
|
||||
}
|
||||
|
||||
// Unfollow disbands request, which will disband the follow relationship between the two parties.
|
||||
// For more information, see the [Spec].
|
||||
//
|
||||
// This can only be sent by the Follower and should not be confused with FollowReject, which can only be sent by the Followee.
|
||||
//
|
||||
// [Spec]: https://versia.pub/entities/unfollow
|
||||
type Unfollow struct {
|
||||
Entity
|
||||
|
||||
// Author is the URL to the user that unfollowed the followee
|
||||
Author *versiautils.URL `json:"author"`
|
||||
|
||||
// Followee is the URL to the user that has been followed
|
||||
Followee *versiautils.URL `json:"follower"`
|
||||
}
|
||||
|
||||
func (f Unfollow) MarshalJSON() ([]byte, error) {
|
||||
type a Unfollow
|
||||
u := a(f)
|
||||
u.Type = "Unfollow"
|
||||
return json.Marshal(u)
|
||||
}
|
||||
32
pkg/versia/actor_group.go
Normal file
32
pkg/versia/actor_group.go
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
package versia
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
versiautils "github.com/lysand-org/versia-go/pkg/versia/utils"
|
||||
)
|
||||
|
||||
// Group is a way to organize users and notes into communities. For more information, see the [Spec].
|
||||
//
|
||||
// [Spec]: https://versia.pub/entities/pub
|
||||
type Group struct {
|
||||
Entity
|
||||
|
||||
// Name is the group's name / title.
|
||||
Name versiautils.TextContentTypeMap `json:"name"`
|
||||
|
||||
// Description is a description of the group's contents / purpose.
|
||||
Description versiautils.TextContentTypeMap `json:"description"`
|
||||
|
||||
// Members is a list of URLs of the group's members.
|
||||
Members []versiautils.URL `json:"members"`
|
||||
|
||||
// Notes is a URL to the collection of notes associated with this group.
|
||||
Notes *versiautils.URL `json:"notes"`
|
||||
}
|
||||
|
||||
func (g Group) MarshalJSON() ([]byte, error) {
|
||||
type a Group
|
||||
g2 := a(g)
|
||||
g2.Type = "Group"
|
||||
return json.Marshal(g2)
|
||||
}
|
||||
|
|
@ -1,7 +1,9 @@
|
|||
package lysand
|
||||
package versia
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
versiacrypto "github.com/lysand-org/versia-go/pkg/versia/crypto"
|
||||
versiautils "github.com/lysand-org/versia-go/pkg/versia/utils"
|
||||
)
|
||||
|
||||
// User represents a user object in the Lysand protocol. For more information, see the [Spec].
|
||||
|
|
@ -32,39 +34,39 @@ type User struct {
|
|||
|
||||
// Avatar is the avatar of the user in different image content types.
|
||||
// https://lysand.org/objects/user#avatar
|
||||
Avatar ImageContentTypeMap `json:"avatar,omitempty"`
|
||||
Avatar versiautils.ImageContentTypeMap `json:"avatar,omitempty"`
|
||||
|
||||
// Header is the header image of the user in different image content types.
|
||||
// https://lysand.org/objects/user#header
|
||||
Header ImageContentTypeMap `json:"header,omitempty"`
|
||||
Header versiautils.ImageContentTypeMap `json:"header,omitempty"`
|
||||
|
||||
// Bio is the biography of the user in different text content types.
|
||||
// https://lysand.org/objects/user#bio
|
||||
Bio TextContentTypeMap `json:"bio"`
|
||||
Bio versiautils.TextContentTypeMap `json:"bio"`
|
||||
|
||||
// Fields is a list of fields that the user has filled out.
|
||||
// https://lysand.org/objects/user#fields
|
||||
Fields []Field `json:"fields,omitempty"`
|
||||
Fields []UserField `json:"fields,omitempty"`
|
||||
|
||||
// Featured is the featured posts of the user.
|
||||
// https://lysand.org/objects/user#featured
|
||||
Featured *URL `json:"featured"`
|
||||
Featured *versiautils.URL `json:"featured"`
|
||||
|
||||
// Followers is the followers of the user.
|
||||
// https://lysand.org/objects/user#followers
|
||||
Followers *URL `json:"followers"`
|
||||
Followers *versiautils.URL `json:"followers"`
|
||||
|
||||
// Following is the users that the user is following.
|
||||
// https://lysand.org/objects/user#following
|
||||
Following *URL `json:"following"`
|
||||
Following *versiautils.URL `json:"following"`
|
||||
|
||||
// Inbox is the inbox of the user.
|
||||
// https://lysand.org/objects/user#posts
|
||||
Inbox *URL `json:"inbox"`
|
||||
Inbox *versiautils.URL `json:"inbox"`
|
||||
|
||||
// Outbox is the outbox of the user.
|
||||
// https://lysand.org/objects/user#outbox
|
||||
Outbox *URL `json:"outbox"`
|
||||
Outbox *versiautils.URL `json:"outbox"`
|
||||
}
|
||||
|
||||
func (u User) MarshalJSON() ([]byte, error) {
|
||||
|
|
@ -74,7 +76,50 @@ func (u User) MarshalJSON() ([]byte, error) {
|
|||
return json.Marshal(u2)
|
||||
}
|
||||
|
||||
type Field struct {
|
||||
Key TextContentTypeMap `json:"key"`
|
||||
Value TextContentTypeMap `json:"value"`
|
||||
type UserField struct {
|
||||
Key versiautils.TextContentTypeMap `json:"key"`
|
||||
Value versiautils.TextContentTypeMap `json:"value"`
|
||||
}
|
||||
|
||||
// UserPublicKey represents a public key for a user. For more information, see the [Spec].
|
||||
//
|
||||
// [Spec]: https://lysand.org/security/keys#public-key-cryptography
|
||||
type UserPublicKey struct {
|
||||
Actor *versiautils.URL `json:"actor"`
|
||||
|
||||
// Algorithm can only be `ed25519` for now
|
||||
Algorithm string `json:"algorithm"`
|
||||
|
||||
Key *versiacrypto.SPKIPublicKey `json:"-"`
|
||||
RawKey json.RawMessage `json:"key"`
|
||||
}
|
||||
|
||||
func (k *UserPublicKey) UnmarshalJSON(raw []byte) error {
|
||||
type t UserPublicKey
|
||||
k2 := (*t)(k)
|
||||
|
||||
if err := json.Unmarshal(raw, k2); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var err error
|
||||
if k2.Key, err = versiacrypto.UnmarshalSPKIPubKey(k2.Algorithm, k2.RawKey); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*k = UserPublicKey(*k2)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (k UserPublicKey) MarshalJSON() ([]byte, error) {
|
||||
type t UserPublicKey
|
||||
k2 := t(k)
|
||||
|
||||
var err error
|
||||
if k2.RawKey, err = k2.Key.MarshalJSON(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return json.Marshal(k2)
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package lysand
|
||||
package versia
|
||||
|
||||
// Attachment is a file or other piece of content that is attached to a post. For more information, see the [Spec].
|
||||
//
|
||||
31
pkg/versia/collection.go
Normal file
31
pkg/versia/collection.go
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
package versia
|
||||
|
||||
import versiautils "github.com/lysand-org/versia-go/pkg/versia/utils"
|
||||
|
||||
// Collection is a paginated group of entities. For more information, see the [Spec].
|
||||
//
|
||||
// [Spec]: https://versia.pub/structures/collection
|
||||
type Collection[T any] struct {
|
||||
// Author represents the author of the collection. `nil` is used to represent the instance.
|
||||
Author *versiautils.URL `json:"author"`
|
||||
|
||||
// First is a URI to the first page of the collection.
|
||||
First *versiautils.URL `json:"first"`
|
||||
|
||||
// Last is a URI to the last page of the collection.
|
||||
// If the collection only has one page, this should be the same as First.
|
||||
Last *versiautils.URL `json:"last"`
|
||||
|
||||
// Total is a count of all entities in the collection across all pages.
|
||||
Total uint64 `json:"total"`
|
||||
|
||||
// Next is a URI to the next page of the collection. If there's no next page, this should be `nil`.
|
||||
Next *versiautils.URL `json:"next"`
|
||||
|
||||
// Previous is a URI to the previous page of the collection. If there's no next page, this should be `nil`.
|
||||
// FIXME(spec): The spec uses `prev` instead of `previous` as the field name.
|
||||
Previous *versiautils.URL `json:"previous"`
|
||||
|
||||
// Items is a list of T for the current page of the collection.
|
||||
Items []T `json:"items"`
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package lysand
|
||||
package versiacrypto
|
||||
|
||||
import (
|
||||
"crypto/ed25519"
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package lysand
|
||||
package versiacrypto
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package lysand
|
||||
package versiacrypto
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
|
@ -1,23 +1,30 @@
|
|||
package lysand
|
||||
package versiacrypto
|
||||
|
||||
import (
|
||||
"crypto"
|
||||
"crypto/ed25519"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
versiacrypto "github.com/lysand-org/versia-go/pkg/lysand/crypto"
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// SignatureData is a combination of HTTP method, URL (only url.URL#Path and url.URL#RawQuery are required),
|
||||
// a nonce and the Base64 encoded SHA256 hash of the request body.
|
||||
// For more information, see the [Spec].
|
||||
//
|
||||
// [Spec]: https://versia.pub/signatures
|
||||
type SignatureData struct {
|
||||
// RequestMethod is the *lowercase* HTTP method of the request
|
||||
RequestMethod string
|
||||
|
||||
// Nonce is a random byte array, used to prevent replay attacks
|
||||
Nonce string
|
||||
|
||||
// RawPath is the path of the request, without the query string
|
||||
URL *url.URL
|
||||
|
||||
// Digest is the SHA-256 hash of the request body
|
||||
Digest []byte
|
||||
}
|
||||
|
|
@ -31,14 +38,16 @@ func NewSignatureData(method, nonce string, u *url.URL, digest []byte) *Signatur
|
|||
}
|
||||
}
|
||||
|
||||
// String returns the payload to sign
|
||||
func (s *SignatureData) String() string {
|
||||
return fmt.Sprintf("%s %s?%s %s %s", strings.ToLower(s.RequestMethod), s.URL.Path, s.URL.RawQuery, s.Nonce, base64.StdEncoding.EncodeToString(s.Digest))
|
||||
}
|
||||
|
||||
// Validate validate that the SignatureData belongs to the provided public key and matches the provided signature.
|
||||
func (s *SignatureData) Validate(pubKey crypto.PublicKey, signature []byte) bool {
|
||||
data := []byte(s.String())
|
||||
|
||||
verify, err := versiacrypto.NewVerify(pubKey)
|
||||
verify, err := NewVerify(pubKey)
|
||||
if err != nil {
|
||||
_, _ = fmt.Fprintf(os.Stderr, "%v\n", err)
|
||||
return false
|
||||
|
|
@ -47,15 +56,21 @@ func (s *SignatureData) Validate(pubKey crypto.PublicKey, signature []byte) bool
|
|||
return verify(data, signature)
|
||||
}
|
||||
|
||||
// Sign signs the SignatureData with the provided private key.
|
||||
func (s *SignatureData) Sign(privKey ed25519.PrivateKey) []byte {
|
||||
return ed25519.Sign(privKey, []byte(s.String()))
|
||||
}
|
||||
|
||||
// Signer is an object, with which requests can be signed with the user's private key.
|
||||
// For more information, see the [Spec].
|
||||
//
|
||||
// [Spec]: https://versia.pub/signatures
|
||||
type Signer struct {
|
||||
PrivateKey ed25519.PrivateKey
|
||||
UserURL *url.URL
|
||||
}
|
||||
|
||||
// Sign signs a signature data and returns the headers to inject into the response.
|
||||
func (s Signer) Sign(signatureData SignatureData) *FederationHeaders {
|
||||
return &FederationHeaders{
|
||||
SignedBy: s.UserURL,
|
||||
|
|
@ -64,11 +79,16 @@ func (s Signer) Sign(signatureData SignatureData) *FederationHeaders {
|
|||
}
|
||||
}
|
||||
|
||||
// Verifier is an object, with which requests can be verified against a user's public key.
|
||||
// For more information, see the [Spec].
|
||||
//
|
||||
// [Spec]: https://versia.pub/signatures
|
||||
type Verifier struct {
|
||||
PublicKey crypto.PublicKey
|
||||
}
|
||||
|
||||
// Verify verifies a request against the public key provided to it duration object creation.
|
||||
func (v Verifier) Verify(method string, u *url.URL, body []byte, fedHeaders *FederationHeaders) bool {
|
||||
return NewSignatureData(method, fedHeaders.Nonce, u, versiacrypto.SHA256(body)).
|
||||
return NewSignatureData(method, fedHeaders.Nonce, u, SHA256(body)).
|
||||
Validate(v.PublicKey, fedHeaders.Signature)
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package lysand
|
||||
package versiacrypto
|
||||
|
||||
import (
|
||||
"crypto"
|
||||
|
|
@ -7,49 +7,6 @@ import (
|
|||
"encoding/json"
|
||||
)
|
||||
|
||||
// UserPublicKey represents a public key for a user. For more information, see the [Spec].
|
||||
//
|
||||
// [Spec]: https://lysand.org/security/keys#public-key-cryptography
|
||||
type UserPublicKey struct {
|
||||
Actor *URL `json:"actor"`
|
||||
|
||||
// Algorithm can only be `ed25519` for now
|
||||
Algorithm string `json:"algorithm"`
|
||||
|
||||
Key *SPKIPublicKey `json:"-"`
|
||||
RawKey json.RawMessage `json:"key"`
|
||||
}
|
||||
|
||||
func (k *UserPublicKey) UnmarshalJSON(raw []byte) error {
|
||||
type t UserPublicKey
|
||||
k2 := (*t)(k)
|
||||
|
||||
if err := json.Unmarshal(raw, k2); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var err error
|
||||
if k2.Key, err = unmarshalSPKIPubKey(k2.Algorithm, k2.RawKey); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*k = UserPublicKey(*k2)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (k UserPublicKey) MarshalJSON() ([]byte, error) {
|
||||
type t UserPublicKey
|
||||
k2 := t(k)
|
||||
|
||||
var err error
|
||||
if k2.RawKey, err = k2.Key.MarshalJSON(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return json.Marshal(k2)
|
||||
}
|
||||
|
||||
// SPKIPublicKey is a type that represents a [ed25519.PublicKey] in the SPKI
|
||||
// format.
|
||||
type SPKIPublicKey struct {
|
||||
|
|
@ -57,7 +14,7 @@ type SPKIPublicKey struct {
|
|||
Algorithm string
|
||||
}
|
||||
|
||||
func unmarshalSPKIPubKey(algorithm string, raw []byte) (*SPKIPublicKey, error) {
|
||||
func UnmarshalSPKIPubKey(algorithm string, raw []byte) (*SPKIPublicKey, error) {
|
||||
rawStr := ""
|
||||
if err := json.Unmarshal(raw, &rawStr); err != nil {
|
||||
return nil, err
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package lysand
|
||||
package versiacrypto
|
||||
|
||||
import (
|
||||
"crypto/ed25519"
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package lysand
|
||||
package versiacrypto
|
||||
|
||||
func must[In any, Out any](fn func(In) (Out, error), v In) Out {
|
||||
out, err := fn(v)
|
||||
|
|
@ -1,7 +1,8 @@
|
|||
package lysand
|
||||
package versia
|
||||
|
||||
import (
|
||||
"github.com/google/uuid"
|
||||
versiautils "github.com/lysand-org/versia-go/pkg/versia/utils"
|
||||
)
|
||||
|
||||
// Entity is the base type for all Lysand entities. For more information, see the [Spec].
|
||||
|
|
@ -15,10 +16,10 @@ type Entity struct {
|
|||
ID uuid.UUID `json:"id"`
|
||||
|
||||
// URI is the URL to the entity
|
||||
URI *URL `json:"uri"`
|
||||
URI *versiautils.URL `json:"uri"`
|
||||
|
||||
// CreatedAt is the time the entity was created
|
||||
CreatedAt Time `json:"created_at"`
|
||||
CreatedAt versiautils.Time `json:"created_at"`
|
||||
|
||||
// Extensions is a map of active extensions
|
||||
// https://lysand.org/objects/server-metadata#extensions
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package lysand
|
||||
package versia
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package lysand
|
||||
package versia
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
|
@ -16,20 +16,14 @@ func ParseInboxObject(raw json.RawMessage) (any, error) {
|
|||
}
|
||||
|
||||
switch i.Type {
|
||||
case "Publication":
|
||||
m := Publication{}
|
||||
if err := json.Unmarshal(raw, &m); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
case "Note":
|
||||
m := Note{}
|
||||
if err := json.Unmarshal(raw, &m); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
case "Patch":
|
||||
m := Patch{}
|
||||
case "Group":
|
||||
m := Group{}
|
||||
if err := json.Unmarshal(raw, &m); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -52,21 +46,21 @@ func ParseInboxObject(raw json.RawMessage) (any, error) {
|
|||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
case "Undo":
|
||||
m := Undo{}
|
||||
case "Unfollow":
|
||||
m := Unfollow{}
|
||||
if err := json.Unmarshal(raw, &m); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
default:
|
||||
return nil, ErrUnknownType{Type: i.Type}
|
||||
return nil, UnknownEntityTypeError{Type: i.Type}
|
||||
}
|
||||
}
|
||||
|
||||
type ErrUnknownType struct {
|
||||
type UnknownEntityTypeError struct {
|
||||
Type string
|
||||
}
|
||||
|
||||
func (e ErrUnknownType) Error() string {
|
||||
return fmt.Sprintf("unknown inbox object type: %s", e.Type)
|
||||
func (e UnknownEntityTypeError) Error() string {
|
||||
return fmt.Sprintf("unknown entity type: %s", e.Type)
|
||||
}
|
||||
|
|
@ -1,7 +1,9 @@
|
|||
package lysand
|
||||
package versia
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
versiacrypto "github.com/lysand-org/versia-go/pkg/versia/crypto"
|
||||
versiautils "github.com/lysand-org/versia-go/pkg/versia/utils"
|
||||
)
|
||||
|
||||
// InstanceMetadata represents the metadata of a Lysand instance. For more information, see the [Spec].
|
||||
|
|
@ -29,19 +31,19 @@ type InstanceMetadata struct {
|
|||
PublicKey InstancePublicKey `json:"public_key"`
|
||||
|
||||
// SharedInbox is the URL to the instance's shared inbox
|
||||
SharedInbox *URL `json:"shared_inbox,omitempty"`
|
||||
SharedInbox *versiautils.URL `json:"shared_inbox,omitempty"`
|
||||
|
||||
// Moderators is a URL to a collection of moderators
|
||||
Moderators *URL `json:"moderators,omitempty"`
|
||||
Moderators *versiautils.URL `json:"moderators,omitempty"`
|
||||
|
||||
// Admins is a URL to a collection of administrators
|
||||
Admins *URL `json:"admins,omitempty"`
|
||||
Admins *versiautils.URL `json:"admins,omitempty"`
|
||||
|
||||
// Logo is the URL to the instance's logo
|
||||
Logo *ImageContentTypeMap `json:"logo,omitempty"`
|
||||
Logo *versiautils.ImageContentTypeMap `json:"logo,omitempty"`
|
||||
|
||||
// Banner is the URL to the instance's banner
|
||||
Banner *ImageContentTypeMap `json:"banner,omitempty"`
|
||||
Banner *versiautils.ImageContentTypeMap `json:"banner,omitempty"`
|
||||
|
||||
// Software is information about the instance software
|
||||
Software InstanceSoftware `json:"software"`
|
||||
|
|
@ -79,8 +81,8 @@ type InstancePublicKey struct {
|
|||
// Algorithm can only be `ed25519` for now
|
||||
Algorithm string `json:"algorithm"`
|
||||
|
||||
Key *SPKIPublicKey `json:"-"`
|
||||
RawKey json.RawMessage `json:"key"`
|
||||
Key *versiacrypto.SPKIPublicKey `json:"-"`
|
||||
RawKey json.RawMessage `json:"key"`
|
||||
}
|
||||
|
||||
func (k *InstancePublicKey) UnmarshalJSON(raw []byte) error {
|
||||
|
|
@ -91,7 +93,7 @@ func (k *InstancePublicKey) UnmarshalJSON(raw []byte) error {
|
|||
}
|
||||
|
||||
var err error
|
||||
if k2.Key, err = unmarshalSPKIPubKey(k2.Algorithm, k2.RawKey); err != nil {
|
||||
if k2.Key, err = versiacrypto.UnmarshalSPKIPubKey(k2.Algorithm, k2.RawKey); err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -1,34 +1,41 @@
|
|||
package lysand
|
||||
package versia
|
||||
|
||||
// PublicationVisibility is the visibility of a publication. For more information, see the [Spec].
|
||||
//
|
||||
// [Spec]: https://lysand.org/objects/publications#visibility
|
||||
type PublicationVisibility string
|
||||
|
||||
const (
|
||||
// PublicationVisiblePublic means that the publication is visible to everyone.
|
||||
PublicationVisiblePublic PublicationVisibility = "public"
|
||||
// PublicationVisibleUnlisted means that the publication is visible everyone, but should not appear in public timelines and search results.
|
||||
PublicationVisibleUnlisted PublicationVisibility = "unlisted"
|
||||
// PublicationVisibleFollowers means that the publication is visible to followers only.
|
||||
PublicationVisibleFollowers PublicationVisibility = "followers"
|
||||
// PublicationVisibleDirect means that the publication is a direct message, and is visible only to the mentioned users.
|
||||
PublicationVisibleDirect PublicationVisibility = "direct"
|
||||
import (
|
||||
"encoding/json"
|
||||
versiautils "github.com/lysand-org/versia-go/pkg/versia/utils"
|
||||
)
|
||||
|
||||
// Publication is a publication object. For more information, see the [Spec].
|
||||
// NoteVisibility is the visibility of a note. For more information, see the [Spec].
|
||||
//
|
||||
// [Spec]: https://lysand.org/objects/publications
|
||||
type Publication struct {
|
||||
// TODO:
|
||||
// [Spec]: https://lysand.org/objects/publications#visibility
|
||||
type NoteVisibility string
|
||||
|
||||
const (
|
||||
// NoteVisiblePublic means that the Note is visible to everyone.
|
||||
NoteVisiblePublic NoteVisibility = "public"
|
||||
// NoteVisibleUnlisted means that the Note is visible everyone, but should not appear in public timelines and search results.
|
||||
NoteVisibleUnlisted NoteVisibility = "unlisted"
|
||||
// NoteVisibleFollowers means that the Note is visible to followers only.
|
||||
NoteVisibleFollowers NoteVisibility = "followers"
|
||||
// NoteVisibleDirect means that the Note is a direct message, and is visible only to the mentioned users.
|
||||
NoteVisibleDirect NoteVisibility = "direct"
|
||||
)
|
||||
|
||||
// Note is a published message, similar to a tweet (from Twitter) or a toot (from Mastodon).
|
||||
// For more information, see the [Spec].
|
||||
//
|
||||
// [Spec]: https://versia.pub/entities/note
|
||||
type Note struct {
|
||||
Entity
|
||||
|
||||
// Author is the URL to the user
|
||||
// https://lysand.org/objects/publications#author
|
||||
Author *URL `json:"author"`
|
||||
Author *versiautils.URL `json:"author"`
|
||||
|
||||
// Content is the content of the publication
|
||||
// https://lysand.org/objects/publications#content
|
||||
Content TextContentTypeMap `json:"content,omitempty"`
|
||||
Content versiautils.TextContentTypeMap `json:"content,omitempty"`
|
||||
|
||||
// Category is the category of the publication
|
||||
// https://lysand.org/objects/publications#category
|
||||
|
|
@ -44,23 +51,23 @@ type Publication struct {
|
|||
|
||||
// Group is the URL to a group
|
||||
// https://lysand.org/objects/publications#group
|
||||
Group *URL `json:"group,omitempty"`
|
||||
Group *versiautils.URL `json:"group,omitempty"`
|
||||
|
||||
// Attachments is a list of attachment objects, keyed by their MIME type
|
||||
// https://lysand.org/objects/publications#attachments
|
||||
Attachments []ContentTypeMap[Attachment] `json:"attachments,omitempty"`
|
||||
Attachments []versiautils.ContentTypeMap[Attachment] `json:"attachments,omitempty"`
|
||||
|
||||
// RepliesTo is the URL to the publication being replied to
|
||||
// https://lysand.org/objects/publications#replies-to
|
||||
RepliesTo *URL `json:"replies_to,omitempty"`
|
||||
RepliesTo *versiautils.URL `json:"replies_to,omitempty"`
|
||||
|
||||
// Quoting is the URL to the publication being quoted
|
||||
// https://lysand.org/objects/publications#quotes
|
||||
Quoting *URL `json:"quoting,omitempty"`
|
||||
Quoting *versiautils.URL `json:"quoting,omitempty"`
|
||||
|
||||
// Mentions is a list of URLs to users
|
||||
// https://lysand.org/objects/publications#mentionshttps://lysand.org/objects/publications#mentions
|
||||
Mentions []URL `json:"mentions,omitempty"`
|
||||
Mentions []versiautils.URL `json:"mentions,omitempty"`
|
||||
|
||||
// Subject is the subject of the publication
|
||||
// https://lysand.org/objects/publications#subject
|
||||
|
|
@ -72,27 +79,34 @@ type Publication struct {
|
|||
|
||||
// Visibility is the visibility of the publication
|
||||
// https://lysand.org/objects/publications#visibility
|
||||
Visibility PublicationVisibility `json:"visibility"`
|
||||
Visibility NoteVisibility `json:"visibility"`
|
||||
}
|
||||
|
||||
func (p Note) MarshalJSON() ([]byte, error) {
|
||||
type a Note
|
||||
n2 := a(p)
|
||||
n2.Type = "Note"
|
||||
return json.Marshal(n2)
|
||||
}
|
||||
|
||||
// LinkPreview is a preview of a link. For more information, see the [Spec].
|
||||
//
|
||||
// [Spec]: https://lysand.org/objects/publications#types
|
||||
type LinkPreview struct {
|
||||
Link URL `json:"link"`
|
||||
Title string `json:"title"`
|
||||
Description *string `json:"description"`
|
||||
Image *URL `json:"image"`
|
||||
Icon *URL `json:"icon"`
|
||||
Link *versiautils.URL `json:"link"`
|
||||
Title string `json:"title"`
|
||||
Description *string `json:"description"`
|
||||
Image *versiautils.URL `json:"image"`
|
||||
Icon *versiautils.URL `json:"icon"`
|
||||
}
|
||||
|
||||
// Device is the device that creates publications. For more information, see the [Spec].
|
||||
//
|
||||
// [Spec]: https://lysand.org/objects/publications#types
|
||||
type Device struct {
|
||||
Name string `json:"name"`
|
||||
Version string `json:"version,omitempty"`
|
||||
URL *URL `json:"url,omitempty"`
|
||||
Name string `json:"name"`
|
||||
Version string `json:"version,omitempty"`
|
||||
URL *versiautils.URL `json:"url,omitempty"`
|
||||
}
|
||||
|
||||
// CategoryType is the type of publication. For more information, see the [Spec].
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package lysand
|
||||
package versiautils
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package lysand
|
||||
package versiautils
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package lysand
|
||||
package versiautils
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
Loading…
Reference in a new issue