introduce FI Factory
This commit is contained in:
parent
dabd773f6b
commit
ca5eaa8c6b
2 changed files with 16 additions and 9 deletions
|
@ -21,6 +21,18 @@ type FederationInfo struct {
|
||||||
Updated timeutil.TimeStamp `xorm:"updated"`
|
Updated timeutil.TimeStamp `xorm:"updated"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Factory function for PersonID. Created struct is asserted to be valid
|
||||||
|
func NewFederationInfo(nodeInfo NodeInfo, hostFqdn string) (FederationInfo, error) {
|
||||||
|
result := FederationInfo{
|
||||||
|
HostFqdn: hostFqdn,
|
||||||
|
NodeInfo: nodeInfo,
|
||||||
|
}
|
||||||
|
if valid, err := validation.IsValid(result); !valid {
|
||||||
|
return FederationInfo{}, err
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
// Validate collects error strings in a slice and returns this
|
// Validate collects error strings in a slice and returns this
|
||||||
func (info FederationInfo) Validate() []string {
|
func (info FederationInfo) Validate() []string {
|
||||||
var result []string
|
var result []string
|
||||||
|
|
|
@ -1,11 +1,8 @@
|
||||||
// Copyright 2023 The forgejo Authors. All rights reserved.
|
// Copyright 2023, 2024 The forgejo Authors. All rights reserved.
|
||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
package activitypub
|
package activitypub
|
||||||
|
|
||||||
// ToDo: Fix linting
|
|
||||||
// ToDo: Maybe do a request for the node info
|
|
||||||
// Then maybe save the node info in a DB table - this could be useful for validation
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -231,11 +228,9 @@ func createFederationInfo(ctx *context.APIContext, actorID forgefed.ActorID) (fo
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return forgefed.FederationInfo{}, err
|
return forgefed.FederationInfo{}, err
|
||||||
}
|
}
|
||||||
// TODO: introduce a NewFederationInfo factory method here.
|
result, err := forgefed.NewFederationInfo(nodeInfo, actorID.Host)
|
||||||
// it should convert host to lower-case.
|
if err != nil {
|
||||||
result := forgefed.FederationInfo{
|
return forgefed.FederationInfo{}, err
|
||||||
HostFqdn: actorID.Host,
|
|
||||||
NodeInfo: nodeInfo,
|
|
||||||
}
|
}
|
||||||
err = forgefed.CreateFederationInfo(ctx, result)
|
err = forgefed.CreateFederationInfo(ctx, result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Add table
Reference in a new issue