mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-27 04:07:08 +00:00
Fix error handling & add timestamp check
This commit is contained in:
parent
40ec049013
commit
dabd773f6b
5 changed files with 56 additions and 27 deletions
|
@ -4,6 +4,8 @@
|
|||
package forgefed
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/modules/validation"
|
||||
ap "github.com/go-ap/activitypub"
|
||||
)
|
||||
|
@ -15,22 +17,26 @@ type ForgeLike struct {
|
|||
ap.Activity
|
||||
}
|
||||
|
||||
func (s ForgeLike) MarshalJSON() ([]byte, error) {
|
||||
return s.Activity.MarshalJSON()
|
||||
func (like ForgeLike) MarshalJSON() ([]byte, error) {
|
||||
return like.Activity.MarshalJSON()
|
||||
}
|
||||
|
||||
func (s *ForgeLike) UnmarshalJSON(data []byte) error {
|
||||
return s.Activity.UnmarshalJSON(data)
|
||||
func (like *ForgeLike) UnmarshalJSON(data []byte) error {
|
||||
return like.Activity.UnmarshalJSON(data)
|
||||
}
|
||||
|
||||
func (s ForgeLike) Validate() []string {
|
||||
func (like ForgeLike) IsNewer(compareTo time.Time) bool {
|
||||
return like.StartTime.After(compareTo)
|
||||
}
|
||||
|
||||
func (like ForgeLike) Validate() []string {
|
||||
var result []string
|
||||
result = append(result, validation.ValidateNotEmpty(string(s.Type), "type")...)
|
||||
result = append(result, validation.ValidateOneOf(string(s.Type), []any{"Like"})...)
|
||||
result = append(result, validation.ValidateNotEmpty(s.Actor.GetID().String(), "actor")...)
|
||||
result = append(result, validation.ValidateNotEmpty(s.Object.GetID().String(), "object")...)
|
||||
result = append(result, validation.ValidateNotEmpty(s.StartTime.String(), "startTime")...)
|
||||
if s.StartTime.IsZero() {
|
||||
result = append(result, validation.ValidateNotEmpty(string(like.Type), "type")...)
|
||||
result = append(result, validation.ValidateOneOf(string(like.Type), []any{"Like"})...)
|
||||
result = append(result, validation.ValidateNotEmpty(like.Actor.GetID().String(), "actor")...)
|
||||
result = append(result, validation.ValidateNotEmpty(like.Object.GetID().String(), "object")...)
|
||||
result = append(result, validation.ValidateNotEmpty(like.StartTime.String(), "startTime")...)
|
||||
if like.StartTime.IsZero() {
|
||||
result = append(result, "StartTime was invalid.")
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue