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/google/uuid"
|
||||||
"github.com/lysand-org/versia-go/ent/attachment"
|
"github.com/lysand-org/versia-go/ent/attachment"
|
||||||
"github.com/lysand-org/versia-go/ent/user"
|
"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.
|
// 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 holds the value of the "uri" field.
|
||||||
URI string `json:"uri,omitempty"`
|
URI string `json:"uri,omitempty"`
|
||||||
// Extensions holds the value of the "extensions" field.
|
// 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 holds the value of the "created_at" field.
|
||||||
CreatedAt time.Time `json:"created_at,omitempty"`
|
CreatedAt time.Time `json:"created_at,omitempty"`
|
||||||
// UpdatedAt holds the value of the "updated_at" field.
|
// UpdatedAt holds the value of the "updated_at" field.
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"entgo.io/ent/dialect/sql"
|
"entgo.io/ent/dialect/sql"
|
||||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
"github.com/lysand-org/versia-go/pkg/versia"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
@ -99,7 +99,7 @@ var (
|
||||||
// URIValidator is a validator for the "uri" field. It is called by the builders before save.
|
// URIValidator is a validator for the "uri" field. It is called by the builders before save.
|
||||||
URIValidator func(string) error
|
URIValidator func(string) error
|
||||||
// DefaultExtensions holds the default value on creation for the "extensions" field.
|
// 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 holds the default value on creation for the "created_at" field.
|
||||||
DefaultCreatedAt func() time.Time
|
DefaultCreatedAt func() time.Time
|
||||||
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
|
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ import (
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/lysand-org/versia-go/ent/attachment"
|
"github.com/lysand-org/versia-go/ent/attachment"
|
||||||
"github.com/lysand-org/versia-go/ent/user"
|
"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.
|
// 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.
|
// SetExtensions sets the "extensions" field.
|
||||||
func (ac *AttachmentCreate) SetExtensions(l lysand.Extensions) *AttachmentCreate {
|
func (ac *AttachmentCreate) SetExtensions(v versia.Extensions) *AttachmentCreate {
|
||||||
ac.mutation.SetExtensions(l)
|
ac.mutation.SetExtensions(v)
|
||||||
return ac
|
return ac
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -454,7 +454,7 @@ func (u *AttachmentUpsert) UpdateURI() *AttachmentUpsert {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetExtensions sets the "extensions" field.
|
// 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)
|
u.Set(attachment.FieldExtensions, v)
|
||||||
return u
|
return u
|
||||||
}
|
}
|
||||||
|
|
@ -701,7 +701,7 @@ func (u *AttachmentUpsertOne) UpdateURI() *AttachmentUpsertOne {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetExtensions sets the "extensions" field.
|
// 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) {
|
return u.Update(func(s *AttachmentUpsert) {
|
||||||
s.SetExtensions(v)
|
s.SetExtensions(v)
|
||||||
})
|
})
|
||||||
|
|
@ -1143,7 +1143,7 @@ func (u *AttachmentUpsertBulk) UpdateURI() *AttachmentUpsertBulk {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetExtensions sets the "extensions" field.
|
// 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) {
|
return u.Update(func(s *AttachmentUpsert) {
|
||||||
s.SetExtensions(v)
|
s.SetExtensions(v)
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ import (
|
||||||
"github.com/lysand-org/versia-go/ent/attachment"
|
"github.com/lysand-org/versia-go/ent/attachment"
|
||||||
"github.com/lysand-org/versia-go/ent/predicate"
|
"github.com/lysand-org/versia-go/ent/predicate"
|
||||||
"github.com/lysand-org/versia-go/ent/user"
|
"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.
|
// AttachmentUpdate is the builder for updating Attachment entities.
|
||||||
|
|
@ -60,8 +60,8 @@ func (au *AttachmentUpdate) SetNillableURI(s *string) *AttachmentUpdate {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetExtensions sets the "extensions" field.
|
// SetExtensions sets the "extensions" field.
|
||||||
func (au *AttachmentUpdate) SetExtensions(l lysand.Extensions) *AttachmentUpdate {
|
func (au *AttachmentUpdate) SetExtensions(v versia.Extensions) *AttachmentUpdate {
|
||||||
au.mutation.SetExtensions(l)
|
au.mutation.SetExtensions(v)
|
||||||
return au
|
return au
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -453,8 +453,8 @@ func (auo *AttachmentUpdateOne) SetNillableURI(s *string) *AttachmentUpdateOne {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetExtensions sets the "extensions" field.
|
// SetExtensions sets the "extensions" field.
|
||||||
func (auo *AttachmentUpdateOne) SetExtensions(l lysand.Extensions) *AttachmentUpdateOne {
|
func (auo *AttachmentUpdateOne) SetExtensions(v versia.Extensions) *AttachmentUpdateOne {
|
||||||
auo.mutation.SetExtensions(l)
|
auo.mutation.SetExtensions(v)
|
||||||
return auo
|
return auo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ import (
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/lysand-org/versia-go/ent/follow"
|
"github.com/lysand-org/versia-go/ent/follow"
|
||||||
"github.com/lysand-org/versia-go/ent/user"
|
"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.
|
// 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 holds the value of the "uri" field.
|
||||||
URI string `json:"uri,omitempty"`
|
URI string `json:"uri,omitempty"`
|
||||||
// Extensions holds the value of the "extensions" field.
|
// 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 holds the value of the "created_at" field.
|
||||||
CreatedAt time.Time `json:"created_at,omitempty"`
|
CreatedAt time.Time `json:"created_at,omitempty"`
|
||||||
// UpdatedAt holds the value of the "updated_at" field.
|
// UpdatedAt holds the value of the "updated_at" field.
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import (
|
||||||
"entgo.io/ent/dialect/sql"
|
"entgo.io/ent/dialect/sql"
|
||||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
"github.com/lysand-org/versia-go/pkg/versia"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
@ -88,7 +88,7 @@ var (
|
||||||
// URIValidator is a validator for the "uri" field. It is called by the builders before save.
|
// URIValidator is a validator for the "uri" field. It is called by the builders before save.
|
||||||
URIValidator func(string) error
|
URIValidator func(string) error
|
||||||
// DefaultExtensions holds the default value on creation for the "extensions" field.
|
// 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 holds the default value on creation for the "created_at" field.
|
||||||
DefaultCreatedAt func() time.Time
|
DefaultCreatedAt func() time.Time
|
||||||
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
|
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ import (
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/lysand-org/versia-go/ent/follow"
|
"github.com/lysand-org/versia-go/ent/follow"
|
||||||
"github.com/lysand-org/versia-go/ent/user"
|
"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.
|
// 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.
|
// SetExtensions sets the "extensions" field.
|
||||||
func (fc *FollowCreate) SetExtensions(l lysand.Extensions) *FollowCreate {
|
func (fc *FollowCreate) SetExtensions(v versia.Extensions) *FollowCreate {
|
||||||
fc.mutation.SetExtensions(l)
|
fc.mutation.SetExtensions(v)
|
||||||
return fc
|
return fc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -386,7 +386,7 @@ func (u *FollowUpsert) UpdateURI() *FollowUpsert {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetExtensions sets the "extensions" field.
|
// 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)
|
u.Set(follow.FieldExtensions, v)
|
||||||
return u
|
return u
|
||||||
}
|
}
|
||||||
|
|
@ -501,7 +501,7 @@ func (u *FollowUpsertOne) UpdateURI() *FollowUpsertOne {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetExtensions sets the "extensions" field.
|
// 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) {
|
return u.Update(func(s *FollowUpsert) {
|
||||||
s.SetExtensions(v)
|
s.SetExtensions(v)
|
||||||
})
|
})
|
||||||
|
|
@ -789,7 +789,7 @@ func (u *FollowUpsertBulk) UpdateURI() *FollowUpsertBulk {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetExtensions sets the "extensions" field.
|
// 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) {
|
return u.Update(func(s *FollowUpsert) {
|
||||||
s.SetExtensions(v)
|
s.SetExtensions(v)
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ import (
|
||||||
"github.com/lysand-org/versia-go/ent/follow"
|
"github.com/lysand-org/versia-go/ent/follow"
|
||||||
"github.com/lysand-org/versia-go/ent/predicate"
|
"github.com/lysand-org/versia-go/ent/predicate"
|
||||||
"github.com/lysand-org/versia-go/ent/user"
|
"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.
|
// FollowUpdate is the builder for updating Follow entities.
|
||||||
|
|
@ -60,8 +60,8 @@ func (fu *FollowUpdate) SetNillableURI(s *string) *FollowUpdate {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetExtensions sets the "extensions" field.
|
// SetExtensions sets the "extensions" field.
|
||||||
func (fu *FollowUpdate) SetExtensions(l lysand.Extensions) *FollowUpdate {
|
func (fu *FollowUpdate) SetExtensions(v versia.Extensions) *FollowUpdate {
|
||||||
fu.mutation.SetExtensions(l)
|
fu.mutation.SetExtensions(v)
|
||||||
return fu
|
return fu
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -315,8 +315,8 @@ func (fuo *FollowUpdateOne) SetNillableURI(s *string) *FollowUpdateOne {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetExtensions sets the "extensions" field.
|
// SetExtensions sets the "extensions" field.
|
||||||
func (fuo *FollowUpdateOne) SetExtensions(l lysand.Extensions) *FollowUpdateOne {
|
func (fuo *FollowUpdateOne) SetExtensions(v versia.Extensions) *FollowUpdateOne {
|
||||||
fuo.mutation.SetExtensions(l)
|
fuo.mutation.SetExtensions(v)
|
||||||
return fuo
|
return fuo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ import (
|
||||||
"entgo.io/ent/dialect/sql"
|
"entgo.io/ent/dialect/sql"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/lysand-org/versia-go/ent/instancemetadata"
|
"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.
|
// 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 holds the value of the "uri" field.
|
||||||
URI string `json:"uri,omitempty"`
|
URI string `json:"uri,omitempty"`
|
||||||
// Extensions holds the value of the "extensions" field.
|
// 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 holds the value of the "created_at" field.
|
||||||
CreatedAt time.Time `json:"created_at,omitempty"`
|
CreatedAt time.Time `json:"created_at,omitempty"`
|
||||||
// UpdatedAt holds the value of the "updated_at" field.
|
// UpdatedAt holds the value of the "updated_at" field.
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"entgo.io/ent/dialect/sql"
|
"entgo.io/ent/dialect/sql"
|
||||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
"github.com/lysand-org/versia-go/pkg/versia"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
@ -138,7 +138,7 @@ var (
|
||||||
// URIValidator is a validator for the "uri" field. It is called by the builders before save.
|
// URIValidator is a validator for the "uri" field. It is called by the builders before save.
|
||||||
URIValidator func(string) error
|
URIValidator func(string) error
|
||||||
// DefaultExtensions holds the default value on creation for the "extensions" field.
|
// 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 holds the default value on creation for the "created_at" field.
|
||||||
DefaultCreatedAt func() time.Time
|
DefaultCreatedAt func() time.Time
|
||||||
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
|
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ import (
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/lysand-org/versia-go/ent/instancemetadata"
|
"github.com/lysand-org/versia-go/ent/instancemetadata"
|
||||||
"github.com/lysand-org/versia-go/ent/user"
|
"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.
|
// 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.
|
// SetExtensions sets the "extensions" field.
|
||||||
func (imc *InstanceMetadataCreate) SetExtensions(l lysand.Extensions) *InstanceMetadataCreate {
|
func (imc *InstanceMetadataCreate) SetExtensions(v versia.Extensions) *InstanceMetadataCreate {
|
||||||
imc.mutation.SetExtensions(l)
|
imc.mutation.SetExtensions(v)
|
||||||
return imc
|
return imc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -703,7 +703,7 @@ func (u *InstanceMetadataUpsert) UpdateURI() *InstanceMetadataUpsert {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetExtensions sets the "extensions" field.
|
// 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)
|
u.Set(instancemetadata.FieldExtensions, v)
|
||||||
return u
|
return u
|
||||||
}
|
}
|
||||||
|
|
@ -1058,7 +1058,7 @@ func (u *InstanceMetadataUpsertOne) UpdateURI() *InstanceMetadataUpsertOne {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetExtensions sets the "extensions" field.
|
// 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) {
|
return u.Update(func(s *InstanceMetadataUpsert) {
|
||||||
s.SetExtensions(v)
|
s.SetExtensions(v)
|
||||||
})
|
})
|
||||||
|
|
@ -1626,7 +1626,7 @@ func (u *InstanceMetadataUpsertBulk) UpdateURI() *InstanceMetadataUpsertBulk {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetExtensions sets the "extensions" field.
|
// 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) {
|
return u.Update(func(s *InstanceMetadataUpsert) {
|
||||||
s.SetExtensions(v)
|
s.SetExtensions(v)
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ import (
|
||||||
"github.com/lysand-org/versia-go/ent/instancemetadata"
|
"github.com/lysand-org/versia-go/ent/instancemetadata"
|
||||||
"github.com/lysand-org/versia-go/ent/predicate"
|
"github.com/lysand-org/versia-go/ent/predicate"
|
||||||
"github.com/lysand-org/versia-go/ent/user"
|
"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.
|
// InstanceMetadataUpdate is the builder for updating InstanceMetadata entities.
|
||||||
|
|
@ -61,8 +61,8 @@ func (imu *InstanceMetadataUpdate) SetNillableURI(s *string) *InstanceMetadataUp
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetExtensions sets the "extensions" field.
|
// SetExtensions sets the "extensions" field.
|
||||||
func (imu *InstanceMetadataUpdate) SetExtensions(l lysand.Extensions) *InstanceMetadataUpdate {
|
func (imu *InstanceMetadataUpdate) SetExtensions(v versia.Extensions) *InstanceMetadataUpdate {
|
||||||
imu.mutation.SetExtensions(l)
|
imu.mutation.SetExtensions(v)
|
||||||
return imu
|
return imu
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -845,8 +845,8 @@ func (imuo *InstanceMetadataUpdateOne) SetNillableURI(s *string) *InstanceMetada
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetExtensions sets the "extensions" field.
|
// SetExtensions sets the "extensions" field.
|
||||||
func (imuo *InstanceMetadataUpdateOne) SetExtensions(l lysand.Extensions) *InstanceMetadataUpdateOne {
|
func (imuo *InstanceMetadataUpdateOne) SetExtensions(v versia.Extensions) *InstanceMetadataUpdateOne {
|
||||||
imuo.mutation.SetExtensions(l)
|
imuo.mutation.SetExtensions(v)
|
||||||
return imuo
|
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/note"
|
||||||
"github.com/lysand-org/versia-go/ent/predicate"
|
"github.com/lysand-org/versia-go/ent/predicate"
|
||||||
"github.com/lysand-org/versia-go/ent/user"
|
"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 (
|
const (
|
||||||
|
|
@ -47,7 +47,7 @@ type AttachmentMutation struct {
|
||||||
id *uuid.UUID
|
id *uuid.UUID
|
||||||
isRemote *bool
|
isRemote *bool
|
||||||
uri *string
|
uri *string
|
||||||
extensions *lysand.Extensions
|
extensions *versia.Extensions
|
||||||
created_at *time.Time
|
created_at *time.Time
|
||||||
updated_at *time.Time
|
updated_at *time.Time
|
||||||
description *string
|
description *string
|
||||||
|
|
@ -247,12 +247,12 @@ func (m *AttachmentMutation) ResetURI() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetExtensions sets the "extensions" field.
|
// SetExtensions sets the "extensions" field.
|
||||||
func (m *AttachmentMutation) SetExtensions(l lysand.Extensions) {
|
func (m *AttachmentMutation) SetExtensions(v versia.Extensions) {
|
||||||
m.extensions = &l
|
m.extensions = &v
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extensions returns the value of the "extensions" field in the mutation.
|
// 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
|
v := m.extensions
|
||||||
if v == nil {
|
if v == nil {
|
||||||
return
|
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.
|
// 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.
|
// 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.
|
// 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) {
|
if !m.op.Is(OpUpdateOne) {
|
||||||
return v, errors.New("OldExtensions is only allowed on UpdateOne operations")
|
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)
|
m.SetURI(v)
|
||||||
return nil
|
return nil
|
||||||
case attachment.FieldExtensions:
|
case attachment.FieldExtensions:
|
||||||
v, ok := value.(lysand.Extensions)
|
v, ok := value.(versia.Extensions)
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||||
}
|
}
|
||||||
|
|
@ -1311,7 +1311,7 @@ type FollowMutation struct {
|
||||||
id *uuid.UUID
|
id *uuid.UUID
|
||||||
isRemote *bool
|
isRemote *bool
|
||||||
uri *string
|
uri *string
|
||||||
extensions *lysand.Extensions
|
extensions *versia.Extensions
|
||||||
created_at *time.Time
|
created_at *time.Time
|
||||||
updated_at *time.Time
|
updated_at *time.Time
|
||||||
status *follow.Status
|
status *follow.Status
|
||||||
|
|
@ -1502,12 +1502,12 @@ func (m *FollowMutation) ResetURI() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetExtensions sets the "extensions" field.
|
// SetExtensions sets the "extensions" field.
|
||||||
func (m *FollowMutation) SetExtensions(l lysand.Extensions) {
|
func (m *FollowMutation) SetExtensions(v versia.Extensions) {
|
||||||
m.extensions = &l
|
m.extensions = &v
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extensions returns the value of the "extensions" field in the mutation.
|
// 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
|
v := m.extensions
|
||||||
if v == nil {
|
if v == nil {
|
||||||
return
|
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.
|
// 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.
|
// 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.
|
// 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) {
|
if !m.op.Is(OpUpdateOne) {
|
||||||
return v, errors.New("OldExtensions is only allowed on UpdateOne operations")
|
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)
|
m.SetURI(v)
|
||||||
return nil
|
return nil
|
||||||
case follow.FieldExtensions:
|
case follow.FieldExtensions:
|
||||||
v, ok := value.(lysand.Extensions)
|
v, ok := value.(versia.Extensions)
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||||
}
|
}
|
||||||
|
|
@ -2419,7 +2419,7 @@ type InstanceMetadataMutation struct {
|
||||||
id *uuid.UUID
|
id *uuid.UUID
|
||||||
isRemote *bool
|
isRemote *bool
|
||||||
uri *string
|
uri *string
|
||||||
extensions *lysand.Extensions
|
extensions *versia.Extensions
|
||||||
created_at *time.Time
|
created_at *time.Time
|
||||||
updated_at *time.Time
|
updated_at *time.Time
|
||||||
name *string
|
name *string
|
||||||
|
|
@ -2633,12 +2633,12 @@ func (m *InstanceMetadataMutation) ResetURI() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetExtensions sets the "extensions" field.
|
// SetExtensions sets the "extensions" field.
|
||||||
func (m *InstanceMetadataMutation) SetExtensions(l lysand.Extensions) {
|
func (m *InstanceMetadataMutation) SetExtensions(v versia.Extensions) {
|
||||||
m.extensions = &l
|
m.extensions = &v
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extensions returns the value of the "extensions" field in the mutation.
|
// 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
|
v := m.extensions
|
||||||
if v == nil {
|
if v == nil {
|
||||||
return
|
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.
|
// 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.
|
// 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.
|
// 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) {
|
if !m.op.Is(OpUpdateOne) {
|
||||||
return v, errors.New("OldExtensions is only allowed on UpdateOne operations")
|
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)
|
m.SetURI(v)
|
||||||
return nil
|
return nil
|
||||||
case instancemetadata.FieldExtensions:
|
case instancemetadata.FieldExtensions:
|
||||||
v, ok := value.(lysand.Extensions)
|
v, ok := value.(versia.Extensions)
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||||
}
|
}
|
||||||
|
|
@ -4331,7 +4331,7 @@ type NoteMutation struct {
|
||||||
id *uuid.UUID
|
id *uuid.UUID
|
||||||
isRemote *bool
|
isRemote *bool
|
||||||
uri *string
|
uri *string
|
||||||
extensions *lysand.Extensions
|
extensions *versia.Extensions
|
||||||
created_at *time.Time
|
created_at *time.Time
|
||||||
updated_at *time.Time
|
updated_at *time.Time
|
||||||
subject *string
|
subject *string
|
||||||
|
|
@ -4529,12 +4529,12 @@ func (m *NoteMutation) ResetURI() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetExtensions sets the "extensions" field.
|
// SetExtensions sets the "extensions" field.
|
||||||
func (m *NoteMutation) SetExtensions(l lysand.Extensions) {
|
func (m *NoteMutation) SetExtensions(v versia.Extensions) {
|
||||||
m.extensions = &l
|
m.extensions = &v
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extensions returns the value of the "extensions" field in the mutation.
|
// 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
|
v := m.extensions
|
||||||
if v == nil {
|
if v == nil {
|
||||||
return
|
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.
|
// 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.
|
// 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.
|
// 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) {
|
if !m.op.Is(OpUpdateOne) {
|
||||||
return v, errors.New("OldExtensions is only allowed on UpdateOne operations")
|
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)
|
m.SetURI(v)
|
||||||
return nil
|
return nil
|
||||||
case note.FieldExtensions:
|
case note.FieldExtensions:
|
||||||
v, ok := value.(lysand.Extensions)
|
v, ok := value.(versia.Extensions)
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||||
}
|
}
|
||||||
|
|
@ -5352,7 +5352,7 @@ type UserMutation struct {
|
||||||
id *uuid.UUID
|
id *uuid.UUID
|
||||||
isRemote *bool
|
isRemote *bool
|
||||||
uri *string
|
uri *string
|
||||||
extensions *lysand.Extensions
|
extensions *versia.Extensions
|
||||||
created_at *time.Time
|
created_at *time.Time
|
||||||
updated_at *time.Time
|
updated_at *time.Time
|
||||||
username *string
|
username *string
|
||||||
|
|
@ -5365,8 +5365,8 @@ type UserMutation struct {
|
||||||
privateKey *[]byte
|
privateKey *[]byte
|
||||||
indexable *bool
|
indexable *bool
|
||||||
privacyLevel *user.PrivacyLevel
|
privacyLevel *user.PrivacyLevel
|
||||||
fields *[]lysand.Field
|
fields *[]versia.UserField
|
||||||
appendfields []lysand.Field
|
appendfields []versia.UserField
|
||||||
inbox *string
|
inbox *string
|
||||||
featured *string
|
featured *string
|
||||||
followers *string
|
followers *string
|
||||||
|
|
@ -5574,12 +5574,12 @@ func (m *UserMutation) ResetURI() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetExtensions sets the "extensions" field.
|
// SetExtensions sets the "extensions" field.
|
||||||
func (m *UserMutation) SetExtensions(l lysand.Extensions) {
|
func (m *UserMutation) SetExtensions(v versia.Extensions) {
|
||||||
m.extensions = &l
|
m.extensions = &v
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extensions returns the value of the "extensions" field in the mutation.
|
// 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
|
v := m.extensions
|
||||||
if v == nil {
|
if v == nil {
|
||||||
return
|
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.
|
// 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.
|
// 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.
|
// 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) {
|
if !m.op.Is(OpUpdateOne) {
|
||||||
return v, errors.New("OldExtensions is only allowed on UpdateOne operations")
|
return v, errors.New("OldExtensions is only allowed on UpdateOne operations")
|
||||||
}
|
}
|
||||||
|
|
@ -6094,13 +6094,13 @@ func (m *UserMutation) ResetPrivacyLevel() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetFields sets the "fields" field.
|
// SetFields sets the "fields" field.
|
||||||
func (m *UserMutation) SetFields(l []lysand.Field) {
|
func (m *UserMutation) SetFields(vf []versia.UserField) {
|
||||||
m.fields = &l
|
m.fields = &vf
|
||||||
m.appendfields = nil
|
m.appendfields = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetFields returns the value of the "fields" field in the mutation.
|
// 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
|
v := m.fields
|
||||||
if v == nil {
|
if v == nil {
|
||||||
return
|
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.
|
// 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.
|
// 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.
|
// 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) {
|
if !m.op.Is(OpUpdateOne) {
|
||||||
return v, errors.New("OldFields is only allowed on UpdateOne operations")
|
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
|
return oldValue.Fields, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// AppendFields adds l to the "fields" field.
|
// AppendFields adds vf to the "fields" field.
|
||||||
func (m *UserMutation) AppendFields(l []lysand.Field) {
|
func (m *UserMutation) AppendFields(vf []versia.UserField) {
|
||||||
m.appendfields = append(m.appendfields, l...)
|
m.appendfields = append(m.appendfields, vf...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// AppendedFields returns the list of values that were appended to the "fields" field in this mutation.
|
// 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 {
|
if len(m.appendfields) == 0 {
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
|
@ -6895,7 +6895,7 @@ func (m *UserMutation) SetField(name string, value ent.Value) error {
|
||||||
m.SetURI(v)
|
m.SetURI(v)
|
||||||
return nil
|
return nil
|
||||||
case user.FieldExtensions:
|
case user.FieldExtensions:
|
||||||
v, ok := value.(lysand.Extensions)
|
v, ok := value.(versia.Extensions)
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
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)
|
m.SetPrivacyLevel(v)
|
||||||
return nil
|
return nil
|
||||||
case user.FieldFields:
|
case user.FieldFields:
|
||||||
v, ok := value.([]lysand.Field)
|
v, ok := value.([]versia.UserField)
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ import (
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/lysand-org/versia-go/ent/note"
|
"github.com/lysand-org/versia-go/ent/note"
|
||||||
"github.com/lysand-org/versia-go/ent/user"
|
"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.
|
// 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 holds the value of the "uri" field.
|
||||||
URI string `json:"uri,omitempty"`
|
URI string `json:"uri,omitempty"`
|
||||||
// Extensions holds the value of the "extensions" field.
|
// 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 holds the value of the "created_at" field.
|
||||||
CreatedAt time.Time `json:"created_at,omitempty"`
|
CreatedAt time.Time `json:"created_at,omitempty"`
|
||||||
// UpdatedAt holds the value of the "updated_at" field.
|
// UpdatedAt holds the value of the "updated_at" field.
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import (
|
||||||
"entgo.io/ent/dialect/sql"
|
"entgo.io/ent/dialect/sql"
|
||||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
"github.com/lysand-org/versia-go/pkg/versia"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
@ -109,7 +109,7 @@ var (
|
||||||
// URIValidator is a validator for the "uri" field. It is called by the builders before save.
|
// URIValidator is a validator for the "uri" field. It is called by the builders before save.
|
||||||
URIValidator func(string) error
|
URIValidator func(string) error
|
||||||
// DefaultExtensions holds the default value on creation for the "extensions" field.
|
// 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 holds the default value on creation for the "created_at" field.
|
||||||
DefaultCreatedAt func() time.Time
|
DefaultCreatedAt func() time.Time
|
||||||
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
|
// 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/attachment"
|
||||||
"github.com/lysand-org/versia-go/ent/note"
|
"github.com/lysand-org/versia-go/ent/note"
|
||||||
"github.com/lysand-org/versia-go/ent/user"
|
"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.
|
// 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.
|
// SetExtensions sets the "extensions" field.
|
||||||
func (nc *NoteCreate) SetExtensions(l lysand.Extensions) *NoteCreate {
|
func (nc *NoteCreate) SetExtensions(v versia.Extensions) *NoteCreate {
|
||||||
nc.mutation.SetExtensions(l)
|
nc.mutation.SetExtensions(v)
|
||||||
return nc
|
return nc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -479,7 +479,7 @@ func (u *NoteUpsert) UpdateURI() *NoteUpsert {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetExtensions sets the "extensions" field.
|
// 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)
|
u.Set(note.FieldExtensions, v)
|
||||||
return u
|
return u
|
||||||
}
|
}
|
||||||
|
|
@ -636,7 +636,7 @@ func (u *NoteUpsertOne) UpdateURI() *NoteUpsertOne {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetExtensions sets the "extensions" field.
|
// 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) {
|
return u.Update(func(s *NoteUpsert) {
|
||||||
s.SetExtensions(v)
|
s.SetExtensions(v)
|
||||||
})
|
})
|
||||||
|
|
@ -973,7 +973,7 @@ func (u *NoteUpsertBulk) UpdateURI() *NoteUpsertBulk {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetExtensions sets the "extensions" field.
|
// 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) {
|
return u.Update(func(s *NoteUpsert) {
|
||||||
s.SetExtensions(v)
|
s.SetExtensions(v)
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ import (
|
||||||
"github.com/lysand-org/versia-go/ent/note"
|
"github.com/lysand-org/versia-go/ent/note"
|
||||||
"github.com/lysand-org/versia-go/ent/predicate"
|
"github.com/lysand-org/versia-go/ent/predicate"
|
||||||
"github.com/lysand-org/versia-go/ent/user"
|
"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.
|
// NoteUpdate is the builder for updating Note entities.
|
||||||
|
|
@ -61,8 +61,8 @@ func (nu *NoteUpdate) SetNillableURI(s *string) *NoteUpdate {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetExtensions sets the "extensions" field.
|
// SetExtensions sets the "extensions" field.
|
||||||
func (nu *NoteUpdate) SetExtensions(l lysand.Extensions) *NoteUpdate {
|
func (nu *NoteUpdate) SetExtensions(v versia.Extensions) *NoteUpdate {
|
||||||
nu.mutation.SetExtensions(l)
|
nu.mutation.SetExtensions(v)
|
||||||
return nu
|
return nu
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -494,8 +494,8 @@ func (nuo *NoteUpdateOne) SetNillableURI(s *string) *NoteUpdateOne {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetExtensions sets the "extensions" field.
|
// SetExtensions sets the "extensions" field.
|
||||||
func (nuo *NoteUpdateOne) SetExtensions(l lysand.Extensions) *NoteUpdateOne {
|
func (nuo *NoteUpdateOne) SetExtensions(v versia.Extensions) *NoteUpdateOne {
|
||||||
nuo.mutation.SetExtensions(l)
|
nuo.mutation.SetExtensions(v)
|
||||||
return nuo
|
return nuo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ import (
|
||||||
"github.com/lysand-org/versia-go/ent/note"
|
"github.com/lysand-org/versia-go/ent/note"
|
||||||
"github.com/lysand-org/versia-go/ent/schema"
|
"github.com/lysand-org/versia-go/ent/schema"
|
||||||
"github.com/lysand-org/versia-go/ent/user"
|
"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
|
// 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 is the schema descriptor for extensions field.
|
||||||
attachmentDescExtensions := attachmentMixinFields0[3].Descriptor()
|
attachmentDescExtensions := attachmentMixinFields0[3].Descriptor()
|
||||||
// attachment.DefaultExtensions holds the default value on creation for the extensions field.
|
// 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 is the schema descriptor for created_at field.
|
||||||
attachmentDescCreatedAt := attachmentMixinFields0[4].Descriptor()
|
attachmentDescCreatedAt := attachmentMixinFields0[4].Descriptor()
|
||||||
// attachment.DefaultCreatedAt holds the default value on creation for the created_at field.
|
// 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 is the schema descriptor for extensions field.
|
||||||
followDescExtensions := followMixinFields0[3].Descriptor()
|
followDescExtensions := followMixinFields0[3].Descriptor()
|
||||||
// follow.DefaultExtensions holds the default value on creation for the extensions field.
|
// 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 is the schema descriptor for created_at field.
|
||||||
followDescCreatedAt := followMixinFields0[4].Descriptor()
|
followDescCreatedAt := followMixinFields0[4].Descriptor()
|
||||||
// follow.DefaultCreatedAt holds the default value on creation for the created_at field.
|
// 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 is the schema descriptor for extensions field.
|
||||||
instancemetadataDescExtensions := instancemetadataMixinFields0[3].Descriptor()
|
instancemetadataDescExtensions := instancemetadataMixinFields0[3].Descriptor()
|
||||||
// instancemetadata.DefaultExtensions holds the default value on creation for the extensions field.
|
// 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 is the schema descriptor for created_at field.
|
||||||
instancemetadataDescCreatedAt := instancemetadataMixinFields0[4].Descriptor()
|
instancemetadataDescCreatedAt := instancemetadataMixinFields0[4].Descriptor()
|
||||||
// instancemetadata.DefaultCreatedAt holds the default value on creation for the created_at field.
|
// 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 is the schema descriptor for extensions field.
|
||||||
noteDescExtensions := noteMixinFields0[3].Descriptor()
|
noteDescExtensions := noteMixinFields0[3].Descriptor()
|
||||||
// note.DefaultExtensions holds the default value on creation for the extensions field.
|
// 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 is the schema descriptor for created_at field.
|
||||||
noteDescCreatedAt := noteMixinFields0[4].Descriptor()
|
noteDescCreatedAt := noteMixinFields0[4].Descriptor()
|
||||||
// note.DefaultCreatedAt holds the default value on creation for the created_at field.
|
// 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 is the schema descriptor for extensions field.
|
||||||
userDescExtensions := userMixinFields0[3].Descriptor()
|
userDescExtensions := userMixinFields0[3].Descriptor()
|
||||||
// user.DefaultExtensions holds the default value on creation for the extensions field.
|
// 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 is the schema descriptor for created_at field.
|
||||||
userDescCreatedAt := userMixinFields0[4].Descriptor()
|
userDescCreatedAt := userMixinFields0[4].Descriptor()
|
||||||
// user.DefaultCreatedAt holds the default value on creation for the created_at field.
|
// 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 is the schema descriptor for fields field.
|
||||||
userDescFields := userFields[10].Descriptor()
|
userDescFields := userFields[10].Descriptor()
|
||||||
// user.DefaultFields holds the default value on creation for the fields field.
|
// 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 is the schema descriptor for inbox field.
|
||||||
userDescInbox := userFields[11].Descriptor()
|
userDescInbox := userFields[11].Descriptor()
|
||||||
// user.InboxValidator is a validator for the "inbox" field. It is called by the builders before save.
|
// user.InboxValidator is a validator for the "inbox" field. It is called by the builders before save.
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,13 @@
|
||||||
package schema
|
package schema
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/url"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"entgo.io/ent"
|
"entgo.io/ent"
|
||||||
"entgo.io/ent/schema/field"
|
"entgo.io/ent/schema/field"
|
||||||
"entgo.io/ent/schema/mixin"
|
"entgo.io/ent/schema/mixin"
|
||||||
"github.com/google/uuid"
|
"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 }
|
type LysandEntityMixin struct{ mixin.Schema }
|
||||||
|
|
@ -23,7 +22,7 @@ func (LysandEntityMixin) Fields() []ent.Field {
|
||||||
field.Bool("isRemote"),
|
field.Bool("isRemote"),
|
||||||
field.String("uri").Validate(ValidateURI),
|
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").
|
field.Time("created_at").
|
||||||
Immutable().
|
Immutable().
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,12 @@
|
||||||
package schema
|
package schema
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"regexp"
|
|
||||||
|
|
||||||
"entgo.io/ent"
|
"entgo.io/ent"
|
||||||
"entgo.io/ent/schema/edge"
|
"entgo.io/ent/schema/edge"
|
||||||
"entgo.io/ent/schema/field"
|
"entgo.io/ent/schema/field"
|
||||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
"errors"
|
||||||
|
"github.com/lysand-org/versia-go/pkg/versia"
|
||||||
|
"regexp"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
@ -45,7 +44,7 @@ func (User) Fields() []ent.Field {
|
||||||
Values("public", "restricted", "private").
|
Values("public", "restricted", "private").
|
||||||
Default("public"),
|
Default("public"),
|
||||||
|
|
||||||
field.JSON("fields", []lysand.Field{}).Default([]lysand.Field{}),
|
field.JSON("fields", []versia.UserField{}).Default([]versia.UserField{}),
|
||||||
|
|
||||||
field.String("inbox").Validate(ValidateURI),
|
field.String("inbox").Validate(ValidateURI),
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ import (
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/lysand-org/versia-go/ent/image"
|
"github.com/lysand-org/versia-go/ent/image"
|
||||||
"github.com/lysand-org/versia-go/ent/user"
|
"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.
|
// 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 holds the value of the "uri" field.
|
||||||
URI string `json:"uri,omitempty"`
|
URI string `json:"uri,omitempty"`
|
||||||
// Extensions holds the value of the "extensions" field.
|
// 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 holds the value of the "created_at" field.
|
||||||
CreatedAt time.Time `json:"created_at,omitempty"`
|
CreatedAt time.Time `json:"created_at,omitempty"`
|
||||||
// UpdatedAt holds the value of the "updated_at" field.
|
// 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 holds the value of the "privacyLevel" field.
|
||||||
PrivacyLevel user.PrivacyLevel `json:"privacyLevel,omitempty"`
|
PrivacyLevel user.PrivacyLevel `json:"privacyLevel,omitempty"`
|
||||||
// Fields holds the value of the "fields" field.
|
// 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 holds the value of the "inbox" field.
|
||||||
Inbox string `json:"inbox,omitempty"`
|
Inbox string `json:"inbox,omitempty"`
|
||||||
// Featured holds the value of the "featured" field.
|
// Featured holds the value of the "featured" field.
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import (
|
||||||
"entgo.io/ent/dialect/sql"
|
"entgo.io/ent/dialect/sql"
|
||||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
"github.com/lysand-org/versia-go/pkg/versia"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
@ -185,7 +185,7 @@ var (
|
||||||
// URIValidator is a validator for the "uri" field. It is called by the builders before save.
|
// URIValidator is a validator for the "uri" field. It is called by the builders before save.
|
||||||
URIValidator func(string) error
|
URIValidator func(string) error
|
||||||
// DefaultExtensions holds the default value on creation for the "extensions" field.
|
// 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 holds the default value on creation for the "created_at" field.
|
||||||
DefaultCreatedAt func() time.Time
|
DefaultCreatedAt func() time.Time
|
||||||
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
|
// 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 holds the default value on creation for the "indexable" field.
|
||||||
DefaultIndexable bool
|
DefaultIndexable bool
|
||||||
// DefaultFields holds the default value on creation for the "fields" field.
|
// 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 is a validator for the "inbox" field. It is called by the builders before save.
|
||||||
InboxValidator func(string) error
|
InboxValidator func(string) error
|
||||||
// FeaturedValidator is a validator for the "featured" field. It is called by the builders before save.
|
// 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/instancemetadata"
|
||||||
"github.com/lysand-org/versia-go/ent/note"
|
"github.com/lysand-org/versia-go/ent/note"
|
||||||
"github.com/lysand-org/versia-go/ent/user"
|
"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.
|
// 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.
|
// SetExtensions sets the "extensions" field.
|
||||||
func (uc *UserCreate) SetExtensions(l lysand.Extensions) *UserCreate {
|
func (uc *UserCreate) SetExtensions(v versia.Extensions) *UserCreate {
|
||||||
uc.mutation.SetExtensions(l)
|
uc.mutation.SetExtensions(v)
|
||||||
return uc
|
return uc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -167,8 +167,8 @@ func (uc *UserCreate) SetNillablePrivacyLevel(ul *user.PrivacyLevel) *UserCreate
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetFields sets the "fields" field.
|
// SetFields sets the "fields" field.
|
||||||
func (uc *UserCreate) SetFields(l []lysand.Field) *UserCreate {
|
func (uc *UserCreate) SetFields(vf []versia.UserField) *UserCreate {
|
||||||
uc.mutation.SetFields(l)
|
uc.mutation.SetFields(vf)
|
||||||
return uc
|
return uc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -803,7 +803,7 @@ func (u *UserUpsert) UpdateURI() *UserUpsert {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetExtensions sets the "extensions" field.
|
// 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)
|
u.Set(user.FieldExtensions, v)
|
||||||
return u
|
return u
|
||||||
}
|
}
|
||||||
|
|
@ -971,7 +971,7 @@ func (u *UserUpsert) UpdatePrivacyLevel() *UserUpsert {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetFields sets the "fields" field.
|
// 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)
|
u.Set(user.FieldFields, v)
|
||||||
return u
|
return u
|
||||||
}
|
}
|
||||||
|
|
@ -1122,7 +1122,7 @@ func (u *UserUpsertOne) UpdateURI() *UserUpsertOne {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetExtensions sets the "extensions" field.
|
// 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) {
|
return u.Update(func(s *UserUpsert) {
|
||||||
s.SetExtensions(v)
|
s.SetExtensions(v)
|
||||||
})
|
})
|
||||||
|
|
@ -1318,7 +1318,7 @@ func (u *UserUpsertOne) UpdatePrivacyLevel() *UserUpsertOne {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetFields sets the "fields" field.
|
// 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) {
|
return u.Update(func(s *UserUpsert) {
|
||||||
s.SetFields(v)
|
s.SetFields(v)
|
||||||
})
|
})
|
||||||
|
|
@ -1648,7 +1648,7 @@ func (u *UserUpsertBulk) UpdateURI() *UserUpsertBulk {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetExtensions sets the "extensions" field.
|
// 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) {
|
return u.Update(func(s *UserUpsert) {
|
||||||
s.SetExtensions(v)
|
s.SetExtensions(v)
|
||||||
})
|
})
|
||||||
|
|
@ -1844,7 +1844,7 @@ func (u *UserUpsertBulk) UpdatePrivacyLevel() *UserUpsertBulk {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetFields sets the "fields" field.
|
// 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) {
|
return u.Update(func(s *UserUpsert) {
|
||||||
s.SetFields(v)
|
s.SetFields(v)
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ import (
|
||||||
"github.com/lysand-org/versia-go/ent/note"
|
"github.com/lysand-org/versia-go/ent/note"
|
||||||
"github.com/lysand-org/versia-go/ent/predicate"
|
"github.com/lysand-org/versia-go/ent/predicate"
|
||||||
"github.com/lysand-org/versia-go/ent/user"
|
"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.
|
// UserUpdate is the builder for updating User entities.
|
||||||
|
|
@ -63,8 +63,8 @@ func (uu *UserUpdate) SetNillableURI(s *string) *UserUpdate {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetExtensions sets the "extensions" field.
|
// SetExtensions sets the "extensions" field.
|
||||||
func (uu *UserUpdate) SetExtensions(l lysand.Extensions) *UserUpdate {
|
func (uu *UserUpdate) SetExtensions(v versia.Extensions) *UserUpdate {
|
||||||
uu.mutation.SetExtensions(l)
|
uu.mutation.SetExtensions(v)
|
||||||
return uu
|
return uu
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -215,14 +215,14 @@ func (uu *UserUpdate) SetNillablePrivacyLevel(ul *user.PrivacyLevel) *UserUpdate
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetFields sets the "fields" field.
|
// SetFields sets the "fields" field.
|
||||||
func (uu *UserUpdate) SetFields(l []lysand.Field) *UserUpdate {
|
func (uu *UserUpdate) SetFields(vf []versia.UserField) *UserUpdate {
|
||||||
uu.mutation.SetFields(l)
|
uu.mutation.SetFields(vf)
|
||||||
return uu
|
return uu
|
||||||
}
|
}
|
||||||
|
|
||||||
// AppendFields appends l to the "fields" field.
|
// AppendFields appends vf to the "fields" field.
|
||||||
func (uu *UserUpdate) AppendFields(l []lysand.Field) *UserUpdate {
|
func (uu *UserUpdate) AppendFields(vf []versia.UserField) *UserUpdate {
|
||||||
uu.mutation.AppendFields(l)
|
uu.mutation.AppendFields(vf)
|
||||||
return uu
|
return uu
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1038,8 +1038,8 @@ func (uuo *UserUpdateOne) SetNillableURI(s *string) *UserUpdateOne {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetExtensions sets the "extensions" field.
|
// SetExtensions sets the "extensions" field.
|
||||||
func (uuo *UserUpdateOne) SetExtensions(l lysand.Extensions) *UserUpdateOne {
|
func (uuo *UserUpdateOne) SetExtensions(v versia.Extensions) *UserUpdateOne {
|
||||||
uuo.mutation.SetExtensions(l)
|
uuo.mutation.SetExtensions(v)
|
||||||
return uuo
|
return uuo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1190,14 +1190,14 @@ func (uuo *UserUpdateOne) SetNillablePrivacyLevel(ul *user.PrivacyLevel) *UserUp
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetFields sets the "fields" field.
|
// SetFields sets the "fields" field.
|
||||||
func (uuo *UserUpdateOne) SetFields(l []lysand.Field) *UserUpdateOne {
|
func (uuo *UserUpdateOne) SetFields(vf []versia.UserField) *UserUpdateOne {
|
||||||
uuo.mutation.SetFields(l)
|
uuo.mutation.SetFields(vf)
|
||||||
return uuo
|
return uuo
|
||||||
}
|
}
|
||||||
|
|
||||||
// AppendFields appends l to the "fields" field.
|
// AppendFields appends vf to the "fields" field.
|
||||||
func (uuo *UserUpdateOne) AppendFields(l []lysand.Field) *UserUpdateOne {
|
func (uuo *UserUpdateOne) AppendFields(vf []versia.UserField) *UserUpdateOne {
|
||||||
uuo.mutation.AppendFields(l)
|
uuo.mutation.AppendFields(vf)
|
||||||
return uuo
|
return uuo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,8 @@ package api_schema
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/google/uuid"
|
"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 {
|
type Note struct {
|
||||||
|
|
@ -12,7 +13,7 @@ type Note struct {
|
||||||
type FetchNoteResponse = APIResponse[Note]
|
type FetchNoteResponse = APIResponse[Note]
|
||||||
|
|
||||||
type CreateNoteRequest struct {
|
type CreateNoteRequest struct {
|
||||||
Content string `json:"content" validate:"required,min=1,max=1024"`
|
Content string `json:"content" validate:"required,min=1,max=1024"`
|
||||||
Visibility lysand.PublicationVisibility `json:"visibility" validate:"required,oneof=public private direct"`
|
Visibility versia.NoteVisibility `json:"visibility" validate:"required,oneof=public unlisted private direct"`
|
||||||
Mentions []lysand.URL `json:"mentions"`
|
Mentions []versiautils.URL `json:"mentions"`
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ package api_schema
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
"github.com/lysand-org/versia-go/pkg/versia"
|
||||||
)
|
)
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
|
|
@ -10,7 +10,7 @@ type User struct {
|
||||||
Username string `json:"username"`
|
Username string `json:"username"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type LysandUser lysand.User
|
type LysandUser versia.User
|
||||||
|
|
||||||
type FetchUserResponse = APIResponse[User]
|
type FetchUserResponse = APIResponse[User]
|
||||||
|
|
||||||
|
|
@ -23,3 +23,32 @@ type SearchUserRequest struct {
|
||||||
Username string `query:"username" validate:"required,username_regex,min=1,max=32"`
|
Username string `query:"username" validate:"required,username_regex,min=1,max=32"`
|
||||||
Domain *string `query:"domain" validate:"domain_regex"`
|
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 (
|
import (
|
||||||
"github.com/lysand-org/versia-go/ent"
|
"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 {
|
type Follow struct {
|
||||||
*ent.Follow
|
*ent.Follow
|
||||||
|
|
||||||
URI *lysand.URL
|
URI *versiautils.URL
|
||||||
FollowerURI *lysand.URL
|
FollowerURI *versiautils.URL
|
||||||
FolloweeURI *lysand.URL
|
FolloweeURI *versiautils.URL
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFollow(dbFollow *ent.Follow) (*Follow, error) {
|
func NewFollow(dbFollow *ent.Follow) (*Follow, error) {
|
||||||
|
|
@ -18,17 +19,17 @@ func NewFollow(dbFollow *ent.Follow) (*Follow, error) {
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
f.URI, err = lysand.ParseURL(dbFollow.URI)
|
f.URI, err = versiautils.ParseURL(dbFollow.URI)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
f.FollowerURI, err = lysand.ParseURL(dbFollow.Edges.Follower.URI)
|
f.FollowerURI, err = versiautils.ParseURL(dbFollow.Edges.Follower.URI)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
f.FolloweeURI, err = lysand.ParseURL(dbFollow.Edges.Followee.URI)
|
f.FolloweeURI, err = versiautils.ParseURL(dbFollow.Edges.Followee.URI)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -36,12 +37,12 @@ func NewFollow(dbFollow *ent.Follow) (*Follow, error) {
|
||||||
return f, nil
|
return f, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f Follow) ToLysand() *lysand.Follow {
|
func (f Follow) ToLysand() *versia.Follow {
|
||||||
return &lysand.Follow{
|
return &versia.Follow{
|
||||||
Entity: lysand.Entity{
|
Entity: versia.Entity{
|
||||||
ID: f.ID,
|
ID: f.ID,
|
||||||
URI: f.URI,
|
URI: f.URI,
|
||||||
CreatedAt: lysand.TimeFromStd(f.CreatedAt),
|
CreatedAt: versiautils.Time(f.CreatedAt),
|
||||||
Extensions: f.Extensions,
|
Extensions: f.Extensions,
|
||||||
},
|
},
|
||||||
Author: f.FollowerURI,
|
Author: f.FollowerURI,
|
||||||
|
|
@ -49,12 +50,12 @@ func (f Follow) ToLysand() *lysand.Follow {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f Follow) ToLysandAccept() *lysand.FollowAccept {
|
func (f Follow) ToLysandAccept() *versia.FollowAccept {
|
||||||
return &lysand.FollowAccept{
|
return &versia.FollowAccept{
|
||||||
Entity: lysand.Entity{
|
Entity: versia.Entity{
|
||||||
ID: f.ID,
|
ID: f.ID,
|
||||||
URI: f.URI,
|
URI: f.URI,
|
||||||
CreatedAt: lysand.TimeFromStd(f.CreatedAt),
|
CreatedAt: versiautils.Time(f.CreatedAt),
|
||||||
Extensions: f.Extensions,
|
Extensions: f.Extensions,
|
||||||
},
|
},
|
||||||
Author: f.FolloweeURI,
|
Author: f.FolloweeURI,
|
||||||
|
|
@ -62,12 +63,12 @@ func (f Follow) ToLysandAccept() *lysand.FollowAccept {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f Follow) ToLysandReject() *lysand.FollowReject {
|
func (f Follow) ToLysandReject() *versia.FollowReject {
|
||||||
return &lysand.FollowReject{
|
return &versia.FollowReject{
|
||||||
Entity: lysand.Entity{
|
Entity: versia.Entity{
|
||||||
ID: f.ID,
|
ID: f.ID,
|
||||||
URI: f.URI,
|
URI: f.URI,
|
||||||
CreatedAt: lysand.TimeFromStd(f.CreatedAt),
|
CreatedAt: versiautils.Time(f.CreatedAt),
|
||||||
Extensions: f.Extensions,
|
Extensions: f.Extensions,
|
||||||
},
|
},
|
||||||
Author: f.FolloweeURI,
|
Author: f.FolloweeURI,
|
||||||
|
|
|
||||||
|
|
@ -2,30 +2,31 @@ package entity
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/lysand-org/versia-go/ent"
|
"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 {
|
type Note struct {
|
||||||
*ent.Note
|
*ent.Note
|
||||||
URI *lysand.URL
|
URI *versiautils.URL
|
||||||
Content lysand.TextContentTypeMap
|
Content versiautils.TextContentTypeMap
|
||||||
Author *User
|
Author *User
|
||||||
Mentions []User
|
Mentions []User
|
||||||
MentionURIs []lysand.URL
|
MentionURIs []versiautils.URL
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewNote(dbNote *ent.Note) (*Note, error) {
|
func NewNote(dbNote *ent.Note) (*Note, error) {
|
||||||
n := &Note{
|
n := &Note{
|
||||||
Note: dbNote,
|
Note: dbNote,
|
||||||
Content: lysand.TextContentTypeMap{
|
Content: versiautils.TextContentTypeMap{
|
||||||
"text/plain": lysand.TextContent{Content: dbNote.Content},
|
"text/plain": versiautils.TextContent{Content: dbNote.Content},
|
||||||
},
|
},
|
||||||
Mentions: make([]User, 0, len(dbNote.Edges.Mentions)),
|
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
|
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
|
return nil, err
|
||||||
}
|
}
|
||||||
if n.Author, err = NewUser(dbNote.Edges.Author); err != nil {
|
if n.Author, err = NewUser(dbNote.Edges.Author); err != nil {
|
||||||
|
|
@ -45,12 +46,12 @@ func NewNote(dbNote *ent.Note) (*Note, error) {
|
||||||
return n, nil
|
return n, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n Note) ToLysand() lysand.Note {
|
func (n Note) ToLysand() versia.Note {
|
||||||
return lysand.Note{
|
return versia.Note{
|
||||||
Entity: lysand.Entity{
|
Entity: versia.Entity{
|
||||||
ID: n.ID,
|
ID: n.ID,
|
||||||
URI: n.URI,
|
URI: n.URI,
|
||||||
CreatedAt: lysand.TimeFromStd(n.CreatedAt),
|
CreatedAt: versiautils.Time(n.CreatedAt),
|
||||||
Extensions: n.Extensions,
|
Extensions: n.Extensions,
|
||||||
},
|
},
|
||||||
Author: n.Author.URI,
|
Author: n.Author.URI,
|
||||||
|
|
@ -65,6 +66,6 @@ func (n Note) ToLysand() lysand.Note {
|
||||||
Mentions: n.MentionURIs,
|
Mentions: n.MentionURIs,
|
||||||
Subject: n.Subject,
|
Subject: n.Subject,
|
||||||
IsSensitive: &n.IsSensitive,
|
IsSensitive: &n.IsSensitive,
|
||||||
Visibility: lysand.PublicationVisibility(n.Visibility),
|
Visibility: versia.NoteVisibility(n.Visibility),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,31 +2,32 @@ package entity
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/lysand-org/versia-go/ent"
|
"github.com/lysand-org/versia-go/ent"
|
||||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
"github.com/lysand-org/versia-go/pkg/versia"
|
||||||
versiacrypto "github.com/lysand-org/versia-go/pkg/lysand/crypto"
|
versiacrypto "github.com/lysand-org/versia-go/pkg/versia/crypto"
|
||||||
|
versiautils "github.com/lysand-org/versia-go/pkg/versia/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type InstanceMetadata struct {
|
type InstanceMetadata struct {
|
||||||
*ent.InstanceMetadata
|
*ent.InstanceMetadata
|
||||||
|
|
||||||
Moderators []User
|
Moderators []User
|
||||||
ModeratorsCollection *lysand.URL
|
ModeratorsCollection *versiautils.URL
|
||||||
|
|
||||||
Admins []User
|
Admins []User
|
||||||
AdminsCollection *lysand.URL
|
AdminsCollection *versiautils.URL
|
||||||
|
|
||||||
SharedInbox *lysand.URL
|
SharedInbox *versiautils.URL
|
||||||
|
|
||||||
PublicKey *lysand.SPKIPublicKey
|
PublicKey *versiacrypto.SPKIPublicKey
|
||||||
|
|
||||||
Logo *lysand.ImageContentTypeMap
|
Logo *versiautils.ImageContentTypeMap
|
||||||
Banner *lysand.ImageContentTypeMap
|
Banner *versiautils.ImageContentTypeMap
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewInstanceMetadata(dbData *ent.InstanceMetadata) (*InstanceMetadata, error) {
|
func NewInstanceMetadata(dbData *ent.InstanceMetadata) (*InstanceMetadata, error) {
|
||||||
n := &InstanceMetadata{
|
n := &InstanceMetadata{
|
||||||
InstanceMetadata: dbData,
|
InstanceMetadata: dbData,
|
||||||
PublicKey: &lysand.SPKIPublicKey{},
|
PublicKey: &versiacrypto.SPKIPublicKey{},
|
||||||
}
|
}
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
|
|
@ -34,16 +35,16 @@ func NewInstanceMetadata(dbData *ent.InstanceMetadata) (*InstanceMetadata, error
|
||||||
return nil, err
|
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
|
return nil, err
|
||||||
}
|
}
|
||||||
if dbData.ModeratorsURI != nil {
|
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
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if dbData.AdminsURI != nil {
|
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
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -69,8 +70,8 @@ func NewInstanceMetadata(dbData *ent.InstanceMetadata) (*InstanceMetadata, error
|
||||||
return n, nil
|
return n, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m InstanceMetadata) ToLysand() lysand.InstanceMetadata {
|
func (m InstanceMetadata) ToLysand() versia.InstanceMetadata {
|
||||||
return lysand.InstanceMetadata{
|
return versia.InstanceMetadata{
|
||||||
Extensions: m.Extensions,
|
Extensions: m.Extensions,
|
||||||
Name: m.Name,
|
Name: m.Name,
|
||||||
Description: m.Description,
|
Description: m.Description,
|
||||||
|
|
@ -80,15 +81,15 @@ func (m InstanceMetadata) ToLysand() lysand.InstanceMetadata {
|
||||||
Admins: m.AdminsCollection,
|
Admins: m.AdminsCollection,
|
||||||
Logo: m.Logo,
|
Logo: m.Logo,
|
||||||
Banner: m.Banner,
|
Banner: m.Banner,
|
||||||
PublicKey: lysand.InstancePublicKey{
|
PublicKey: versia.InstancePublicKey{
|
||||||
Algorithm: m.PublicKeyAlgorithm,
|
Algorithm: m.PublicKeyAlgorithm,
|
||||||
Key: m.PublicKey,
|
Key: m.PublicKey,
|
||||||
},
|
},
|
||||||
Software: lysand.InstanceSoftware{
|
Software: versia.InstanceSoftware{
|
||||||
Name: m.SoftwareName,
|
Name: m.SoftwareName,
|
||||||
Version: m.SoftwareVersion,
|
Version: m.SoftwareVersion,
|
||||||
},
|
},
|
||||||
Compatibility: lysand.InstanceCompatibility{
|
Compatibility: versia.InstanceCompatibility{
|
||||||
Versions: m.SupportedVersions,
|
Versions: m.SupportedVersions,
|
||||||
Extensions: m.SupportedExtensions,
|
Extensions: m.SupportedExtensions,
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -2,36 +2,37 @@ package entity
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/lysand-org/versia-go/internal/helpers"
|
"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"
|
"net/url"
|
||||||
|
|
||||||
"github.com/lysand-org/versia-go/ent"
|
"github.com/lysand-org/versia-go/ent"
|
||||||
"github.com/lysand-org/versia-go/internal/utils"
|
"github.com/lysand-org/versia-go/internal/utils"
|
||||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
*ent.User
|
*ent.User
|
||||||
|
|
||||||
URI *lysand.URL
|
URI *versiautils.URL
|
||||||
PKActorURI *lysand.URL
|
PKActorURI *versiautils.URL
|
||||||
PublicKey *lysand.SPKIPublicKey
|
PublicKey *versiacrypto.SPKIPublicKey
|
||||||
Inbox *lysand.URL
|
Inbox *versiautils.URL
|
||||||
Outbox *lysand.URL
|
Outbox *versiautils.URL
|
||||||
Featured *lysand.URL
|
Featured *versiautils.URL
|
||||||
Followers *lysand.URL
|
Followers *versiautils.URL
|
||||||
Following *lysand.URL
|
Following *versiautils.URL
|
||||||
|
|
||||||
DisplayName string
|
DisplayName string
|
||||||
LysandAvatar lysand.ImageContentTypeMap
|
LysandAvatar versiautils.ImageContentTypeMap
|
||||||
LysandBiography lysand.TextContentTypeMap
|
LysandBiography versiautils.TextContentTypeMap
|
||||||
Signer lysand.Signer
|
Signer versiacrypto.Signer
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewUser(dbData *ent.User) (*User, error) {
|
func NewUser(dbData *ent.User) (*User, error) {
|
||||||
u := &User{
|
u := &User{
|
||||||
User: dbData,
|
User: dbData,
|
||||||
PublicKey: &lysand.SPKIPublicKey{
|
PublicKey: &versiacrypto.SPKIPublicKey{
|
||||||
Key: nil,
|
Key: nil,
|
||||||
Algorithm: dbData.PublicKeyAlgorithm,
|
Algorithm: dbData.PublicKeyAlgorithm,
|
||||||
},
|
},
|
||||||
|
|
@ -50,29 +51,29 @@ func NewUser(dbData *ent.User) (*User, error) {
|
||||||
return nil, err
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
u.Signer = lysand.Signer{
|
u.Signer = versiacrypto.Signer{
|
||||||
PrivateKey: dbData.PrivateKey,
|
PrivateKey: dbData.PrivateKey,
|
||||||
UserURL: u.URI.ToStd(),
|
UserURL: u.URI.ToStd(),
|
||||||
}
|
}
|
||||||
|
|
@ -80,12 +81,12 @@ func NewUser(dbData *ent.User) (*User, error) {
|
||||||
return u, nil
|
return u, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u User) ToLysand() *lysand.User {
|
func (u User) ToLysand() *versia.User {
|
||||||
return &lysand.User{
|
return &versia.User{
|
||||||
Entity: lysand.Entity{
|
Entity: versia.Entity{
|
||||||
ID: u.ID,
|
ID: u.ID,
|
||||||
URI: u.URI,
|
URI: u.URI,
|
||||||
CreatedAt: lysand.TimeFromStd(u.CreatedAt),
|
CreatedAt: versiautils.Time(u.CreatedAt),
|
||||||
Extensions: u.Extensions,
|
Extensions: u.Extensions,
|
||||||
},
|
},
|
||||||
DisplayName: helpers.StringPtr(u.DisplayName),
|
DisplayName: helpers.StringPtr(u.DisplayName),
|
||||||
|
|
@ -93,7 +94,7 @@ func (u User) ToLysand() *lysand.User {
|
||||||
Avatar: u.LysandAvatar,
|
Avatar: u.LysandAvatar,
|
||||||
Header: imageMap(u.Edges.HeaderImage),
|
Header: imageMap(u.Edges.HeaderImage),
|
||||||
Indexable: u.Indexable,
|
Indexable: u.Indexable,
|
||||||
PublicKey: lysand.UserPublicKey{
|
PublicKey: versia.UserPublicKey{
|
||||||
Actor: u.PKActorURI,
|
Actor: u.PKActorURI,
|
||||||
Algorithm: u.PublicKeyAlgorithm,
|
Algorithm: u.PublicKeyAlgorithm,
|
||||||
Key: u.PublicKey,
|
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 {
|
if avatar := imageMap(u.Edges.AvatarImage); avatar != nil {
|
||||||
return avatar
|
return avatar
|
||||||
}
|
}
|
||||||
|
|
||||||
return lysand.ImageContentTypeMap{
|
return versiautils.ImageContentTypeMap{
|
||||||
"image/svg+xml": lysand.ImageContent{
|
"image/svg+xml": versiautils.ImageContent{
|
||||||
Content: utils.DefaultAvatarURL(u.ID),
|
Content: utils.DefaultAvatarURL(u.ID),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func lysandBiography(u *ent.User) lysand.TextContentTypeMap {
|
func lysandBiography(u *ent.User) versiautils.TextContentTypeMap {
|
||||||
if u.Biography == nil {
|
if u.Biography == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Render HTML
|
// TODO: Render HTML
|
||||||
|
|
||||||
return lysand.TextContentTypeMap{
|
return versiautils.TextContentTypeMap{
|
||||||
"text/html": lysand.TextContent{
|
"text/html": versiautils.TextContent{
|
||||||
Content: *u.Biography,
|
Content: *u.Biography,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func imageMap(i *ent.Image) lysand.ImageContentTypeMap {
|
func imageMap(i *ent.Image) versiautils.ImageContentTypeMap {
|
||||||
if i == nil {
|
if i == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -145,9 +146,9 @@ func imageMap(i *ent.Image) lysand.ImageContentTypeMap {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return lysand.ImageContentTypeMap{
|
return versiautils.ImageContentTypeMap{
|
||||||
i.MimeType: {
|
i.MimeType: {
|
||||||
Content: (*lysand.URL)(u),
|
Content: (*versiautils.URL)(u),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,11 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/lysand-org/versia-go/internal/validators/val_impls"
|
"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/gofiber/fiber/v2"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/lysand-org/versia-go/internal/api_schema"
|
"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 {
|
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)
|
return api_schema.ErrBadRequest(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
obj, err := lysand.ParseInboxObject(raw)
|
obj, err := versia.ParseInboxObject(raw)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
i.log.Error(err, "Failed to parse inbox object")
|
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{
|
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/entity"
|
||||||
"github.com/lysand-org/versia-go/internal/repository"
|
"github.com/lysand-org/versia-go/internal/repository"
|
||||||
"github.com/lysand-org/versia-go/internal/service"
|
"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)
|
var _ repository.InstanceMetadataRepository = (*InstanceMetadataRepositoryImpl)(nil)
|
||||||
|
|
@ -50,7 +50,7 @@ func (i *InstanceMetadataRepositoryImpl) GetByHost(ctx context.Context, host str
|
||||||
return entity.NewInstanceMetadata(m)
|
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").
|
s := i.telemetry.StartSpan(ctx, "function", "repo_impls/InstanceMetadataRepositoryImpl.ImportFromLysandByURI").
|
||||||
AddAttribute("uri", uri.String())
|
AddAttribute("uri", uri.String())
|
||||||
defer s.End()
|
defer s.End()
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package repo_impls
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/lysand-org/versia-go/internal/repository"
|
"github.com/lysand-org/versia-go/internal/repository"
|
||||||
|
"github.com/lysand-org/versia-go/pkg/versia"
|
||||||
|
|
||||||
"git.devminer.xyz/devminer/unitel"
|
"git.devminer.xyz/devminer/unitel"
|
||||||
"github.com/go-logr/logr"
|
"github.com/go-logr/logr"
|
||||||
|
|
@ -11,7 +12,6 @@ import (
|
||||||
"github.com/lysand-org/versia-go/ent/note"
|
"github.com/lysand-org/versia-go/ent/note"
|
||||||
"github.com/lysand-org/versia-go/internal/entity"
|
"github.com/lysand-org/versia-go/internal/entity"
|
||||||
"github.com/lysand-org/versia-go/internal/utils"
|
"github.com/lysand-org/versia-go/internal/utils"
|
||||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ repository.NoteRepository = (*NoteRepositoryImpl)(nil)
|
var _ repository.NoteRepository = (*NoteRepositoryImpl)(nil)
|
||||||
|
|
@ -62,7 +62,7 @@ func (i *NoteRepositoryImpl) NewNote(ctx context.Context, author *entity.User, c
|
||||||
return entity.NewNote(n)
|
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")
|
s := i.telemetry.StartSpan(ctx, "function", "repo_impls/NoteRepositoryImpl.ImportLysandNote")
|
||||||
defer s.End()
|
defer s.End()
|
||||||
ctx = s.Context()
|
ctx = s.Context()
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"github.com/lysand-org/versia-go/config"
|
"github.com/lysand-org/versia-go/config"
|
||||||
"github.com/lysand-org/versia-go/internal/repository"
|
"github.com/lysand-org/versia-go/internal/repository"
|
||||||
"github.com/lysand-org/versia-go/internal/service"
|
"github.com/lysand-org/versia-go/internal/service"
|
||||||
|
versiautils "github.com/lysand-org/versia-go/pkg/versia/utils"
|
||||||
"golang.org/x/crypto/bcrypt"
|
"golang.org/x/crypto/bcrypt"
|
||||||
|
|
||||||
"git.devminer.xyz/devminer/unitel"
|
"git.devminer.xyz/devminer/unitel"
|
||||||
|
|
@ -17,7 +18,6 @@ import (
|
||||||
"github.com/lysand-org/versia-go/ent/user"
|
"github.com/lysand-org/versia-go/ent/user"
|
||||||
"github.com/lysand-org/versia-go/internal/entity"
|
"github.com/lysand-org/versia-go/internal/entity"
|
||||||
"github.com/lysand-org/versia-go/internal/utils"
|
"github.com/lysand-org/versia-go/internal/utils"
|
||||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const bcryptCost = 12
|
const bcryptCost = 12
|
||||||
|
|
@ -84,7 +84,7 @@ func (i *UserRepositoryImpl) NewUser(ctx context.Context, username, password str
|
||||||
return entity.NewUser(u)
|
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")
|
s := i.telemetry.StartSpan(ctx, "function", "repo_impls/UserRepositoryImpl.ImportLysandUserByURI")
|
||||||
defer s.End()
|
defer s.End()
|
||||||
ctx = s.Context()
|
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)
|
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 {
|
if err != nil {
|
||||||
l.Error(err, "Failed to resolve user")
|
l.Error(err, "Failed to resolve user")
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
@ -185,7 +185,7 @@ func (i *UserRepositoryImpl) Discover(ctx context.Context, domain, username stri
|
||||||
return u, nil
|
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")
|
s := i.telemetry.StartSpan(ctx, "function", "repo_impls/UserRepositoryImpl.Resolve")
|
||||||
defer s.End()
|
defer s.End()
|
||||||
ctx = s.Context()
|
ctx = s.Context()
|
||||||
|
|
@ -215,7 +215,7 @@ func (i *UserRepositoryImpl) Resolve(ctx context.Context, uri *lysand.URL) (*ent
|
||||||
return u, nil
|
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")
|
s := i.telemetry.StartSpan(ctx, "function", "repo_impls/UserRepositoryImpl.ResolveMultiple")
|
||||||
defer s.End()
|
defer s.End()
|
||||||
ctx = s.Context()
|
ctx = s.Context()
|
||||||
|
|
@ -340,7 +340,7 @@ func (i *UserRepositoryImpl) GetLocalByUsername(ctx context.Context, username st
|
||||||
return entity.NewUser(u)
|
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")
|
s := i.telemetry.StartSpan(ctx, "function", "repo_impls/UserRepositoryImpl.LookupByURI")
|
||||||
defer s.End()
|
defer s.End()
|
||||||
ctx = s.Context()
|
ctx = s.Context()
|
||||||
|
|
@ -367,7 +367,7 @@ func (i *UserRepositoryImpl) LookupByURI(ctx context.Context, uri *lysand.URL) (
|
||||||
return entity.NewUser(u)
|
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")
|
s := i.telemetry.StartSpan(ctx, "function", "repo_impls/UserRepositoryImpl.LookupByURIs")
|
||||||
defer s.End()
|
defer s.End()
|
||||||
ctx = s.Context()
|
ctx = s.Context()
|
||||||
|
|
|
||||||
|
|
@ -3,15 +3,16 @@ package repository
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"crypto/ed25519"
|
"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/google/uuid"
|
||||||
"github.com/lysand-org/versia-go/internal/entity"
|
"github.com/lysand-org/versia-go/internal/entity"
|
||||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type UserRepository interface {
|
type UserRepository interface {
|
||||||
NewUser(ctx context.Context, username, password string, privateKey ed25519.PrivateKey, publicKey ed25519.PublicKey) (*entity.User, error)
|
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)
|
GetByID(ctx context.Context, id uuid.UUID) (*entity.User, error)
|
||||||
GetLocalByID(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)
|
Discover(ctx context.Context, host, username string) (*entity.User, error)
|
||||||
|
|
||||||
Resolve(ctx context.Context, uri *lysand.URL) (*entity.User, error)
|
Resolve(ctx context.Context, uri *versiautils.URL) (*entity.User, error)
|
||||||
ResolveMultiple(ctx context.Context, uris []lysand.URL) ([]*entity.User, error)
|
ResolveMultiple(ctx context.Context, uris []versiautils.URL) ([]*entity.User, error)
|
||||||
|
|
||||||
LookupByURI(ctx context.Context, uri *lysand.URL) (*entity.User, error)
|
LookupByURI(ctx context.Context, uri *versiautils.URL) (*entity.User, error)
|
||||||
LookupByURIs(ctx context.Context, uris []lysand.URL) ([]*entity.User, error)
|
LookupByURIs(ctx context.Context, uris []versiautils.URL) ([]*entity.User, error)
|
||||||
LookupByIDOrUsername(ctx context.Context, idOrUsername string) (*entity.User, error)
|
LookupByIDOrUsername(ctx context.Context, idOrUsername string) (*entity.User, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -38,14 +39,14 @@ type FollowRepository interface {
|
||||||
|
|
||||||
type NoteRepository interface {
|
type NoteRepository interface {
|
||||||
NewNote(ctx context.Context, author *entity.User, content string, mentions []*entity.User) (*entity.Note, error)
|
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)
|
GetByID(ctx context.Context, idOrUsername uuid.UUID) (*entity.Note, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type InstanceMetadataRepository interface {
|
type InstanceMetadataRepository interface {
|
||||||
GetByHost(ctx context.Context, host string) (*entity.InstanceMetadata, error)
|
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 {
|
type Manager interface {
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,13 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
"github.com/lysand-org/versia-go/internal/repository"
|
"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/google/uuid"
|
||||||
"github.com/lysand-org/versia-go/internal/api_schema"
|
"github.com/lysand-org/versia-go/internal/api_schema"
|
||||||
"github.com/lysand-org/versia-go/internal/entity"
|
"github.com/lysand-org/versia-go/internal/entity"
|
||||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
|
||||||
"github.com/lysand-org/versia-go/pkg/webfinger"
|
"github.com/lysand-org/versia-go/pkg/webfinger"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -26,10 +28,10 @@ type UserService interface {
|
||||||
|
|
||||||
type FederationService interface {
|
type FederationService interface {
|
||||||
SendToInbox(ctx context.Context, author *entity.User, target *entity.User, object any) ([]byte, error)
|
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)
|
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 {
|
type InboxService interface {
|
||||||
|
|
@ -40,14 +42,14 @@ type NoteService interface {
|
||||||
CreateNote(ctx context.Context, req api_schema.CreateNoteRequest) (*entity.Note, error)
|
CreateNote(ctx context.Context, req api_schema.CreateNoteRequest) (*entity.Note, error)
|
||||||
GetNote(ctx context.Context, id uuid.UUID) (*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 {
|
type FollowService interface {
|
||||||
NewFollow(ctx context.Context, follower, followee *entity.User) (*entity.Follow, error)
|
NewFollow(ctx context.Context, follower, followee *entity.User) (*entity.Follow, error)
|
||||||
GetFollow(ctx context.Context, id uuid.UUID) (*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 {
|
type InstanceMetadataService interface {
|
||||||
|
|
@ -59,5 +61,5 @@ type TaskService interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
type RequestSigner 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/google/uuid"
|
||||||
"github.com/lysand-org/versia-go/internal/repository"
|
"github.com/lysand-org/versia-go/internal/repository"
|
||||||
"github.com/lysand-org/versia-go/internal/service"
|
"github.com/lysand-org/versia-go/internal/service"
|
||||||
|
"github.com/lysand-org/versia-go/pkg/versia"
|
||||||
|
|
||||||
"git.devminer.xyz/devminer/unitel"
|
"git.devminer.xyz/devminer/unitel"
|
||||||
"github.com/go-logr/logr"
|
"github.com/go-logr/logr"
|
||||||
|
|
@ -12,7 +13,6 @@ import (
|
||||||
"github.com/lysand-org/versia-go/ent/user"
|
"github.com/lysand-org/versia-go/ent/user"
|
||||||
"github.com/lysand-org/versia-go/internal/api_schema"
|
"github.com/lysand-org/versia-go/internal/api_schema"
|
||||||
"github.com/lysand-org/versia-go/internal/entity"
|
"github.com/lysand-org/versia-go/internal/entity"
|
||||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ service.InboxService = (*InboxServiceImpl)(nil)
|
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
|
// TODO: Implement more types
|
||||||
switch o := obj.(type) {
|
switch o := obj.(type) {
|
||||||
case lysand.Note:
|
case versia.Note:
|
||||||
i.log.Info("Received note", "note", o)
|
i.log.Info("Received note", "note", o)
|
||||||
if err := i.handleNote(ctx, o, u); err != nil {
|
if err := i.handleNote(ctx, o, u); err != nil {
|
||||||
i.log.Error(err, "Failed to handle note", "note", o)
|
i.log.Error(err, "Failed to handle note", "note", o)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
case versia.Follow:
|
||||||
case lysand.Patch:
|
|
||||||
i.log.Info("Received patch", "patch", o)
|
|
||||||
case lysand.Follow:
|
|
||||||
if err := i.handleFollow(ctx, o, u); err != nil {
|
if err := i.handleFollow(ctx, o, u); err != nil {
|
||||||
i.log.Error(err, "Failed to handle follow", "follow", o)
|
i.log.Error(err, "Failed to handle follow", "follow", o)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
case lysand.Undo:
|
|
||||||
i.log.Info("Received undo", "undo", o)
|
|
||||||
default:
|
default:
|
||||||
i.log.Info("Unimplemented object type", "object", obj)
|
i.log.Info("Unimplemented object type", "object", obj)
|
||||||
return api_schema.ErrNotImplemented(nil)
|
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")
|
s := i.telemetry.StartSpan(ctx, "function", "svc_impls/InboxServiceImpl.handleFollow")
|
||||||
defer s.End()
|
defer s.End()
|
||||||
ctx = s.Context()
|
ctx = s.Context()
|
||||||
|
|
@ -130,7 +125,7 @@ func (i InboxServiceImpl) handleFollow(ctx context.Context, o lysand.Follow, u *
|
||||||
return nil
|
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")
|
s := i.telemetry.StartSpan(ctx, "function", "svc_impls/InboxServiceImpl.handleNote")
|
||||||
defer s.End()
|
defer s.End()
|
||||||
ctx = s.Context()
|
ctx = s.Context()
|
||||||
|
|
|
||||||
|
|
@ -12,9 +12,10 @@ import (
|
||||||
"github.com/go-logr/logr"
|
"github.com/go-logr/logr"
|
||||||
"github.com/lysand-org/versia-go/internal/entity"
|
"github.com/lysand-org/versia-go/internal/entity"
|
||||||
"github.com/lysand-org/versia-go/internal/service"
|
"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/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"
|
"github.com/lysand-org/versia-go/pkg/webfinger"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
@ -29,14 +30,14 @@ var (
|
||||||
type FederationServiceImpl struct {
|
type FederationServiceImpl struct {
|
||||||
httpC *protoretry.Client
|
httpC *protoretry.Client
|
||||||
|
|
||||||
federationClient *lysand.FederationClient
|
federationClient *versia.FederationClient
|
||||||
|
|
||||||
telemetry *unitel.Telemetry
|
telemetry *unitel.Telemetry
|
||||||
|
|
||||||
log logr.Logger
|
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{
|
return &FederationServiceImpl{
|
||||||
httpC: protoretry.New(httpClient),
|
httpC: protoretry.New(httpClient),
|
||||||
federationClient: federationClient,
|
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").
|
s := i.telemetry.StartSpan(ctx, "function", "svc_impls/FederationServiceImpl.GetUser").
|
||||||
AddAttribute("userURI", uri.String())
|
AddAttribute("userURI", uri.String())
|
||||||
defer s.End()
|
defer s.End()
|
||||||
|
|
@ -57,19 +58,19 @@ func (i *FederationServiceImpl) GetUser(ctx context.Context, uri *lysand.URL) (*
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
u := &lysand.User{}
|
u := &versia.User{}
|
||||||
if err := json.Unmarshal(body, u); err != nil {
|
if err := json.Unmarshal(body, u); err != nil {
|
||||||
s.SetSimpleStatus(unitel.Error, err.Error())
|
s.SetSimpleStatus(unitel.Error, err.Error())
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
fedHeaders, err := lysand.ExtractFederationHeaders(resp.Header)
|
fedHeaders, err := versiacrypto.ExtractFederationHeaders(resp.Header)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.SetSimpleStatus(unitel.Error, err.Error())
|
s.SetSimpleStatus(unitel.Error, err.Error())
|
||||||
return nil, err
|
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) {
|
if !v.Verify("GET", uri.ToStd(), body, fedHeaders) {
|
||||||
s.SetSimpleStatus(unitel.Error, ErrSignatureValidationFailed.Error())
|
s.SetSimpleStatus(unitel.Error, ErrSignatureValidationFailed.Error())
|
||||||
i.log.V(1).Error(ErrSignatureValidationFailed, "signature validation failed", "user", u.URI.String())
|
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
|
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").
|
s := i.telemetry.StartSpan(ctx, "function", "svc_impls/FederationServiceImpl.DiscoverInstance").
|
||||||
AddAttribute("baseURL", baseURL)
|
AddAttribute("baseURL", baseURL)
|
||||||
defer s.End()
|
defer s.End()
|
||||||
|
|
@ -112,10 +113,10 @@ func (i *FederationServiceImpl) DiscoverInstance(ctx context.Context, baseURL st
|
||||||
return nil, err
|
return nil, err
|
||||||
} else if resp.StatusCode >= http.StatusBadRequest {
|
} else if resp.StatusCode >= http.StatusBadRequest {
|
||||||
s.SetSimpleStatus(unitel.Error, fmt.Sprintf("unexpected response code: %d", resp.StatusCode))
|
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 {
|
if err := json.Unmarshal(body, &metadata); err != nil {
|
||||||
s.SetSimpleStatus(unitel.Error, err.Error())
|
s.SetSimpleStatus(unitel.Error, err.Error())
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
@ -150,7 +151,7 @@ func (i *FederationServiceImpl) SendToInbox(ctx context.Context, author *entity.
|
||||||
return nil, err
|
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)
|
sig := author.Signer.Sign(*sigData)
|
||||||
|
|
||||||
req, err := http.NewRequestWithContext(ctx, "POST", uri.String(), bytes.NewReader(body))
|
req, err := http.NewRequestWithContext(ctx, "POST", uri.String(), bytes.NewReader(body))
|
||||||
|
|
|
||||||
|
|
@ -4,12 +4,12 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/lysand-org/versia-go/internal/repository"
|
"github.com/lysand-org/versia-go/internal/repository"
|
||||||
"github.com/lysand-org/versia-go/internal/service"
|
"github.com/lysand-org/versia-go/internal/service"
|
||||||
|
"github.com/lysand-org/versia-go/pkg/versia"
|
||||||
|
|
||||||
"git.devminer.xyz/devminer/unitel"
|
"git.devminer.xyz/devminer/unitel"
|
||||||
"github.com/go-logr/logr"
|
"github.com/go-logr/logr"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/lysand-org/versia-go/internal/entity"
|
"github.com/lysand-org/versia-go/internal/entity"
|
||||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ service.FollowService = (*FollowServiceImpl)(nil)
|
var _ service.FollowService = (*FollowServiceImpl)(nil)
|
||||||
|
|
@ -69,7 +69,7 @@ func (i FollowServiceImpl) GetFollow(ctx context.Context, id uuid.UUID) (*entity
|
||||||
return f, nil
|
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").
|
s := i.telemetry.StartSpan(ctx, "function", "svc_impls/FollowServiceImpl.ImportLysandFollow").
|
||||||
AddAttribute("uri", lFollow.URI.String())
|
AddAttribute("uri", lFollow.URI.String())
|
||||||
defer s.End()
|
defer s.End()
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/lysand-org/versia-go/internal/repository"
|
"github.com/lysand-org/versia-go/internal/repository"
|
||||||
"github.com/lysand-org/versia-go/internal/service"
|
"github.com/lysand-org/versia-go/internal/service"
|
||||||
|
"github.com/lysand-org/versia-go/pkg/versia"
|
||||||
"slices"
|
"slices"
|
||||||
|
|
||||||
"git.devminer.xyz/devminer/unitel"
|
"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/api_schema"
|
||||||
"github.com/lysand-org/versia-go/internal/entity"
|
"github.com/lysand-org/versia-go/internal/entity"
|
||||||
"github.com/lysand-org/versia-go/internal/tasks"
|
"github.com/lysand-org/versia-go/internal/tasks"
|
||||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ service.NoteService = (*NoteServiceImpl)(nil)
|
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)
|
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")
|
s := i.telemetry.StartSpan(ctx, "function", "svc_impls/NoteServiceImpl.ImportLysandNote")
|
||||||
defer s.End()
|
defer s.End()
|
||||||
ctx = s.Context()
|
ctx = s.Context()
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,7 @@ import (
|
||||||
"github.com/go-logr/logr"
|
"github.com/go-logr/logr"
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
"github.com/lysand-org/versia-go/internal/service"
|
"github.com/lysand-org/versia-go/internal/service"
|
||||||
"github.com/lysand-org/versia-go/pkg/lysand"
|
versiacrypto "github.com/lysand-org/versia-go/pkg/versia/crypto"
|
||||||
versiacrypto "github.com/lysand-org/versia-go/pkg/lysand/crypto"
|
|
||||||
"net/url"
|
"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")
|
s := i.telemetry.StartSpan(c.UserContext(), "function", "svc_impls/RequestSignerImpl.Sign")
|
||||||
defer s.End()
|
defer s.End()
|
||||||
|
|
||||||
|
|
@ -50,7 +49,7 @@ func (i *RequestSignerImpl) Sign(c *fiber.Ctx, signer lysand.Signer, body any) e
|
||||||
|
|
||||||
digest := versiacrypto.SHA256(j)
|
digest := versiacrypto.SHA256(j)
|
||||||
|
|
||||||
d := lysand.NewSignatureData(c.Method(), nonce, uri, digest)
|
d := versiacrypto.NewSignatureData(c.Method(), nonce, uri, digest)
|
||||||
|
|
||||||
signed := signer.Sign(*d)
|
signed := signer.Sign(*d)
|
||||||
for k, v := range signed.Headers() {
|
for k, v := range signed.Headers() {
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,10 @@ package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/lysand-org/versia-go/config"
|
"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{
|
var dicebearURL = &url.URL{
|
||||||
|
|
@ -15,81 +14,81 @@ var dicebearURL = &url.URL{
|
||||||
Path: "9.x/adventurer/svg",
|
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())}
|
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{}
|
u := &url.URL{}
|
||||||
q := u.Query()
|
q := u.Query()
|
||||||
q.Set("seed", uuid.String())
|
q.Set("seed", uuid.String())
|
||||||
u.RawQuery = q.Encode()
|
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"}
|
newPath := &url.URL{Path: "./inbox"}
|
||||||
return UserAPIURL(uuid).ResolveReference(newPath)
|
return UserAPIURL(uuid).ResolveReference(newPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
func UserOutboxAPIURL(uuid uuid.UUID) *lysand.URL {
|
func UserOutboxAPIURL(uuid uuid.UUID) *versiautils.URL {
|
||||||
newPath := &url.URL{Path: "./outbox"}
|
newPath := &url.URL{Path: "./outbox"}
|
||||||
return UserAPIURL(uuid).ResolveReference(newPath)
|
return UserAPIURL(uuid).ResolveReference(newPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
func UserFollowersAPIURL(uuid uuid.UUID) *lysand.URL {
|
func UserFollowersAPIURL(uuid uuid.UUID) *versiautils.URL {
|
||||||
newPath := &url.URL{Path: "./followers"}
|
newPath := &url.URL{Path: "./followers"}
|
||||||
return UserAPIURL(uuid).ResolveReference(newPath)
|
return UserAPIURL(uuid).ResolveReference(newPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
func UserFollowingAPIURL(uuid uuid.UUID) *lysand.URL {
|
func UserFollowingAPIURL(uuid uuid.UUID) *versiautils.URL {
|
||||||
newPath := &url.URL{Path: "./following"}
|
newPath := &url.URL{Path: "./following"}
|
||||||
return UserAPIURL(uuid).ResolveReference(newPath)
|
return UserAPIURL(uuid).ResolveReference(newPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
func UserFeaturedAPIURL(uuid uuid.UUID) *lysand.URL {
|
func UserFeaturedAPIURL(uuid uuid.UUID) *versiautils.URL {
|
||||||
newPath := &url.URL{Path: "./featured"}
|
newPath := &url.URL{Path: "./featured"}
|
||||||
return UserAPIURL(uuid).ResolveReference(newPath)
|
return UserAPIURL(uuid).ResolveReference(newPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
func UserLikesAPIURL(uuid uuid.UUID) *lysand.URL {
|
func UserLikesAPIURL(uuid uuid.UUID) *versiautils.URL {
|
||||||
newPath := &url.URL{Path: "./likes"}
|
newPath := &url.URL{Path: "./likes"}
|
||||||
return UserAPIURL(uuid).ResolveReference(newPath)
|
return UserAPIURL(uuid).ResolveReference(newPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
func UserDislikesAPIURL(uuid uuid.UUID) *lysand.URL {
|
func UserDislikesAPIURL(uuid uuid.UUID) *versiautils.URL {
|
||||||
newPath := &url.URL{Path: "./dislikes"}
|
newPath := &url.URL{Path: "./dislikes"}
|
||||||
return UserAPIURL(uuid).ResolveReference(newPath)
|
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())}
|
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())}
|
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/"}
|
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/"}
|
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/"}
|
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/"}
|
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/repository"
|
||||||
"github.com/lysand-org/versia-go/internal/utils"
|
"github.com/lysand-org/versia-go/internal/utils"
|
||||||
"github.com/lysand-org/versia-go/internal/validators"
|
"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"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -42,13 +43,13 @@ func (i RequestValidatorImpl) Validate(ctx context.Context, r *http.Request) err
|
||||||
|
|
||||||
r = r.WithContext(ctx)
|
r = r.WithContext(ctx)
|
||||||
|
|
||||||
fedHeaders, err := lysand.ExtractFederationHeaders(r.Header)
|
fedHeaders, err := versiacrypto.ExtractFederationHeaders(r.Header)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Fetch user from database instead of using the URI
|
// 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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -58,7 +59,7 @@ func (i RequestValidatorImpl) Validate(ctx context.Context, r *http.Request) err
|
||||||
return 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)
|
i.log.WithCallDepth(1).Info("signature verification failed", "user", user.URI, "url", r.URL.Path)
|
||||||
s.CaptureError(ErrInvalidSignature)
|
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/repository/repo_impls"
|
||||||
"github.com/lysand-org/versia-go/internal/service/svc_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/internal/validators/val_impls"
|
||||||
|
"github.com/lysand-org/versia-go/pkg/versia"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
|
@ -37,7 +38,6 @@ import (
|
||||||
"github.com/lysand-org/versia-go/internal/handlers/user_handler"
|
"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/tasks"
|
||||||
"github.com/lysand-org/versia-go/internal/utils"
|
"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/lysand-org/versia-go/pkg/taskqueue"
|
||||||
"github.com/nats-io/nats.go"
|
"github.com/nats-io/nats.go"
|
||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
|
|
@ -73,9 +73,9 @@ func main() {
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
federationClient := lysand.NewClient(
|
federationClient := versia.NewClient(
|
||||||
lysand.WithHTTPClient(httpClient),
|
versia.WithHTTPClient(httpClient),
|
||||||
lysand.WithLogger(zerologr.New(&log.Logger).WithName("federation-client")),
|
versia.WithLogger(zerologr.New(&log.Logger).WithName("federation-client")),
|
||||||
)
|
)
|
||||||
|
|
||||||
log.Debug().Msg("Opening database connection")
|
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 (
|
import (
|
||||||
"encoding/json"
|
"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].
|
// 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.
|
// Avatar is the avatar of the user in different image content types.
|
||||||
// https://lysand.org/objects/user#avatar
|
// 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.
|
// Header is the header image of the user in different image content types.
|
||||||
// https://lysand.org/objects/user#header
|
// 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.
|
// Bio is the biography of the user in different text content types.
|
||||||
// https://lysand.org/objects/user#bio
|
// 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.
|
// Fields is a list of fields that the user has filled out.
|
||||||
// https://lysand.org/objects/user#fields
|
// https://lysand.org/objects/user#fields
|
||||||
Fields []Field `json:"fields,omitempty"`
|
Fields []UserField `json:"fields,omitempty"`
|
||||||
|
|
||||||
// Featured is the featured posts of the user.
|
// Featured is the featured posts of the user.
|
||||||
// https://lysand.org/objects/user#featured
|
// https://lysand.org/objects/user#featured
|
||||||
Featured *URL `json:"featured"`
|
Featured *versiautils.URL `json:"featured"`
|
||||||
|
|
||||||
// Followers is the followers of the user.
|
// Followers is the followers of the user.
|
||||||
// https://lysand.org/objects/user#followers
|
// https://lysand.org/objects/user#followers
|
||||||
Followers *URL `json:"followers"`
|
Followers *versiautils.URL `json:"followers"`
|
||||||
|
|
||||||
// Following is the users that the user is following.
|
// Following is the users that the user is following.
|
||||||
// https://lysand.org/objects/user#following
|
// https://lysand.org/objects/user#following
|
||||||
Following *URL `json:"following"`
|
Following *versiautils.URL `json:"following"`
|
||||||
|
|
||||||
// Inbox is the inbox of the user.
|
// Inbox is the inbox of the user.
|
||||||
// https://lysand.org/objects/user#posts
|
// https://lysand.org/objects/user#posts
|
||||||
Inbox *URL `json:"inbox"`
|
Inbox *versiautils.URL `json:"inbox"`
|
||||||
|
|
||||||
// Outbox is the outbox of the user.
|
// Outbox is the outbox of the user.
|
||||||
// https://lysand.org/objects/user#outbox
|
// https://lysand.org/objects/user#outbox
|
||||||
Outbox *URL `json:"outbox"`
|
Outbox *versiautils.URL `json:"outbox"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u User) MarshalJSON() ([]byte, error) {
|
func (u User) MarshalJSON() ([]byte, error) {
|
||||||
|
|
@ -74,7 +76,50 @@ func (u User) MarshalJSON() ([]byte, error) {
|
||||||
return json.Marshal(u2)
|
return json.Marshal(u2)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Field struct {
|
type UserField struct {
|
||||||
Key TextContentTypeMap `json:"key"`
|
Key versiautils.TextContentTypeMap `json:"key"`
|
||||||
Value TextContentTypeMap `json:"value"`
|
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].
|
// 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 (
|
import (
|
||||||
"crypto/ed25519"
|
"crypto/ed25519"
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package lysand
|
package versiacrypto
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package lysand
|
package versiacrypto
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
@ -1,23 +1,30 @@
|
||||||
package lysand
|
package versiacrypto
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto"
|
"crypto"
|
||||||
"crypto/ed25519"
|
"crypto/ed25519"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
versiacrypto "github.com/lysand-org/versia-go/pkg/lysand/crypto"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"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 {
|
type SignatureData struct {
|
||||||
// RequestMethod is the *lowercase* HTTP method of the request
|
// RequestMethod is the *lowercase* HTTP method of the request
|
||||||
RequestMethod string
|
RequestMethod string
|
||||||
|
|
||||||
// Nonce is a random byte array, used to prevent replay attacks
|
// Nonce is a random byte array, used to prevent replay attacks
|
||||||
Nonce string
|
Nonce string
|
||||||
|
|
||||||
// RawPath is the path of the request, without the query string
|
// RawPath is the path of the request, without the query string
|
||||||
URL *url.URL
|
URL *url.URL
|
||||||
|
|
||||||
// Digest is the SHA-256 hash of the request body
|
// Digest is the SHA-256 hash of the request body
|
||||||
Digest []byte
|
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 {
|
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))
|
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 {
|
func (s *SignatureData) Validate(pubKey crypto.PublicKey, signature []byte) bool {
|
||||||
data := []byte(s.String())
|
data := []byte(s.String())
|
||||||
|
|
||||||
verify, err := versiacrypto.NewVerify(pubKey)
|
verify, err := NewVerify(pubKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_, _ = fmt.Fprintf(os.Stderr, "%v\n", err)
|
_, _ = fmt.Fprintf(os.Stderr, "%v\n", err)
|
||||||
return false
|
return false
|
||||||
|
|
@ -47,15 +56,21 @@ func (s *SignatureData) Validate(pubKey crypto.PublicKey, signature []byte) bool
|
||||||
return verify(data, signature)
|
return verify(data, signature)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sign signs the SignatureData with the provided private key.
|
||||||
func (s *SignatureData) Sign(privKey ed25519.PrivateKey) []byte {
|
func (s *SignatureData) Sign(privKey ed25519.PrivateKey) []byte {
|
||||||
return ed25519.Sign(privKey, []byte(s.String()))
|
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 {
|
type Signer struct {
|
||||||
PrivateKey ed25519.PrivateKey
|
PrivateKey ed25519.PrivateKey
|
||||||
UserURL *url.URL
|
UserURL *url.URL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sign signs a signature data and returns the headers to inject into the response.
|
||||||
func (s Signer) Sign(signatureData SignatureData) *FederationHeaders {
|
func (s Signer) Sign(signatureData SignatureData) *FederationHeaders {
|
||||||
return &FederationHeaders{
|
return &FederationHeaders{
|
||||||
SignedBy: s.UserURL,
|
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 {
|
type Verifier struct {
|
||||||
PublicKey crypto.PublicKey
|
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 {
|
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)
|
Validate(v.PublicKey, fedHeaders.Signature)
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package lysand
|
package versiacrypto
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto"
|
"crypto"
|
||||||
|
|
@ -7,49 +7,6 @@ import (
|
||||||
"encoding/json"
|
"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
|
// SPKIPublicKey is a type that represents a [ed25519.PublicKey] in the SPKI
|
||||||
// format.
|
// format.
|
||||||
type SPKIPublicKey struct {
|
type SPKIPublicKey struct {
|
||||||
|
|
@ -57,7 +14,7 @@ type SPKIPublicKey struct {
|
||||||
Algorithm string
|
Algorithm string
|
||||||
}
|
}
|
||||||
|
|
||||||
func unmarshalSPKIPubKey(algorithm string, raw []byte) (*SPKIPublicKey, error) {
|
func UnmarshalSPKIPubKey(algorithm string, raw []byte) (*SPKIPublicKey, error) {
|
||||||
rawStr := ""
|
rawStr := ""
|
||||||
if err := json.Unmarshal(raw, &rawStr); err != nil {
|
if err := json.Unmarshal(raw, &rawStr); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package lysand
|
package versiacrypto
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/ed25519"
|
"crypto/ed25519"
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package lysand
|
package versiacrypto
|
||||||
|
|
||||||
func must[In any, Out any](fn func(In) (Out, error), v In) Out {
|
func must[In any, Out any](fn func(In) (Out, error), v In) Out {
|
||||||
out, err := fn(v)
|
out, err := fn(v)
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
package lysand
|
package versia
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/google/uuid"
|
"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].
|
// 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"`
|
ID uuid.UUID `json:"id"`
|
||||||
|
|
||||||
// URI is the URL to the entity
|
// 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 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
|
// Extensions is a map of active extensions
|
||||||
// https://lysand.org/objects/server-metadata#extensions
|
// https://lysand.org/objects/server-metadata#extensions
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package lysand
|
package versia
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package lysand
|
package versia
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
@ -16,20 +16,14 @@ func ParseInboxObject(raw json.RawMessage) (any, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
switch i.Type {
|
switch i.Type {
|
||||||
case "Publication":
|
|
||||||
m := Publication{}
|
|
||||||
if err := json.Unmarshal(raw, &m); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return m, nil
|
|
||||||
case "Note":
|
case "Note":
|
||||||
m := Note{}
|
m := Note{}
|
||||||
if err := json.Unmarshal(raw, &m); err != nil {
|
if err := json.Unmarshal(raw, &m); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return m, nil
|
return m, nil
|
||||||
case "Patch":
|
case "Group":
|
||||||
m := Patch{}
|
m := Group{}
|
||||||
if err := json.Unmarshal(raw, &m); err != nil {
|
if err := json.Unmarshal(raw, &m); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -52,21 +46,21 @@ func ParseInboxObject(raw json.RawMessage) (any, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return m, nil
|
return m, nil
|
||||||
case "Undo":
|
case "Unfollow":
|
||||||
m := Undo{}
|
m := Unfollow{}
|
||||||
if err := json.Unmarshal(raw, &m); err != nil {
|
if err := json.Unmarshal(raw, &m); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return m, nil
|
return m, nil
|
||||||
default:
|
default:
|
||||||
return nil, ErrUnknownType{Type: i.Type}
|
return nil, UnknownEntityTypeError{Type: i.Type}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type ErrUnknownType struct {
|
type UnknownEntityTypeError struct {
|
||||||
Type string
|
Type string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e ErrUnknownType) Error() string {
|
func (e UnknownEntityTypeError) Error() string {
|
||||||
return fmt.Sprintf("unknown inbox object type: %s", e.Type)
|
return fmt.Sprintf("unknown entity type: %s", e.Type)
|
||||||
}
|
}
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
package lysand
|
package versia
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"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].
|
// 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"`
|
PublicKey InstancePublicKey `json:"public_key"`
|
||||||
|
|
||||||
// SharedInbox is the URL to the instance's shared inbox
|
// 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 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 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 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 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 is information about the instance software
|
||||||
Software InstanceSoftware `json:"software"`
|
Software InstanceSoftware `json:"software"`
|
||||||
|
|
@ -79,8 +81,8 @@ type InstancePublicKey struct {
|
||||||
// Algorithm can only be `ed25519` for now
|
// Algorithm can only be `ed25519` for now
|
||||||
Algorithm string `json:"algorithm"`
|
Algorithm string `json:"algorithm"`
|
||||||
|
|
||||||
Key *SPKIPublicKey `json:"-"`
|
Key *versiacrypto.SPKIPublicKey `json:"-"`
|
||||||
RawKey json.RawMessage `json:"key"`
|
RawKey json.RawMessage `json:"key"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (k *InstancePublicKey) UnmarshalJSON(raw []byte) error {
|
func (k *InstancePublicKey) UnmarshalJSON(raw []byte) error {
|
||||||
|
|
@ -91,7 +93,7 @@ func (k *InstancePublicKey) UnmarshalJSON(raw []byte) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
var err 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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1,34 +1,41 @@
|
||||||
package lysand
|
package versia
|
||||||
|
|
||||||
// PublicationVisibility is the visibility of a publication. For more information, see the [Spec].
|
import (
|
||||||
//
|
"encoding/json"
|
||||||
// [Spec]: https://lysand.org/objects/publications#visibility
|
versiautils "github.com/lysand-org/versia-go/pkg/versia/utils"
|
||||||
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"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// 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
|
// TODO:
|
||||||
type Publication struct {
|
// [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
|
Entity
|
||||||
|
|
||||||
// Author is the URL to the user
|
// Author is the URL to the user
|
||||||
// https://lysand.org/objects/publications#author
|
// https://lysand.org/objects/publications#author
|
||||||
Author *URL `json:"author"`
|
Author *versiautils.URL `json:"author"`
|
||||||
|
|
||||||
// Content is the content of the publication
|
// Content is the content of the publication
|
||||||
// https://lysand.org/objects/publications#content
|
// https://lysand.org/objects/publications#content
|
||||||
Content TextContentTypeMap `json:"content,omitempty"`
|
Content versiautils.TextContentTypeMap `json:"content,omitempty"`
|
||||||
|
|
||||||
// Category is the category of the publication
|
// Category is the category of the publication
|
||||||
// https://lysand.org/objects/publications#category
|
// https://lysand.org/objects/publications#category
|
||||||
|
|
@ -44,23 +51,23 @@ type Publication struct {
|
||||||
|
|
||||||
// Group is the URL to a group
|
// Group is the URL to a group
|
||||||
// https://lysand.org/objects/publications#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
|
// Attachments is a list of attachment objects, keyed by their MIME type
|
||||||
// https://lysand.org/objects/publications#attachments
|
// 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
|
// RepliesTo is the URL to the publication being replied to
|
||||||
// https://lysand.org/objects/publications#replies-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
|
// Quoting is the URL to the publication being quoted
|
||||||
// https://lysand.org/objects/publications#quotes
|
// 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
|
// Mentions is a list of URLs to users
|
||||||
// https://lysand.org/objects/publications#mentionshttps://lysand.org/objects/publications#mentions
|
// 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
|
// Subject is the subject of the publication
|
||||||
// https://lysand.org/objects/publications#subject
|
// https://lysand.org/objects/publications#subject
|
||||||
|
|
@ -72,27 +79,34 @@ type Publication struct {
|
||||||
|
|
||||||
// Visibility is the visibility of the publication
|
// Visibility is the visibility of the publication
|
||||||
// https://lysand.org/objects/publications#visibility
|
// 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].
|
// LinkPreview is a preview of a link. For more information, see the [Spec].
|
||||||
//
|
//
|
||||||
// [Spec]: https://lysand.org/objects/publications#types
|
// [Spec]: https://lysand.org/objects/publications#types
|
||||||
type LinkPreview struct {
|
type LinkPreview struct {
|
||||||
Link URL `json:"link"`
|
Link *versiautils.URL `json:"link"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Description *string `json:"description"`
|
Description *string `json:"description"`
|
||||||
Image *URL `json:"image"`
|
Image *versiautils.URL `json:"image"`
|
||||||
Icon *URL `json:"icon"`
|
Icon *versiautils.URL `json:"icon"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Device is the device that creates publications. For more information, see the [Spec].
|
// Device is the device that creates publications. For more information, see the [Spec].
|
||||||
//
|
//
|
||||||
// [Spec]: https://lysand.org/objects/publications#types
|
// [Spec]: https://lysand.org/objects/publications#types
|
||||||
type Device struct {
|
type Device struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Version string `json:"version,omitempty"`
|
Version string `json:"version,omitempty"`
|
||||||
URL *URL `json:"url,omitempty"`
|
URL *versiautils.URL `json:"url,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// CategoryType is the type of publication. For more information, see the [Spec].
|
// CategoryType is the type of publication. For more information, see the [Spec].
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package lysand
|
package versiautils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package lysand
|
package versiautils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package lysand
|
package versiautils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
Loading…
Reference in a new issue