From 1f989f2ecd523084fd49b04a9ba9db5387c35fdb Mon Sep 17 00:00:00 2001 From: Clemens Date: Fri, 12 Jan 2024 17:27:52 +0100 Subject: [PATCH] Added FederationInfo Create function --- models/forgefed/federationinfo_repository.go | 8 ++++++++ routers/api/v1/activitypub/repository.go | 6 +++++- templates/swagger/v1_json.tmpl | 21 ++++++-------------- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/models/forgefed/federationinfo_repository.go b/models/forgefed/federationinfo_repository.go index d568d7aecc..ab13810072 100644 --- a/models/forgefed/federationinfo_repository.go +++ b/models/forgefed/federationinfo_repository.go @@ -42,3 +42,11 @@ func FindFederationInfoByHostFqdn(ctx context.Context, fqdn string) (*Federation } return info, nil } + +func CreateFederationInfo(ctx context.Context, info FederationInfo) error { + if res, err := validation.IsValid(info); !res { + return fmt.Errorf("FederationInfo is not valid: %v", err) + } + _, err := db.GetEngine(ctx).Insert(info) + return err +} diff --git a/routers/api/v1/activitypub/repository.go b/routers/api/v1/activitypub/repository.go index 1c7bababba..c09d093084 100644 --- a/routers/api/v1/activitypub/repository.go +++ b/routers/api/v1/activitypub/repository.go @@ -106,7 +106,7 @@ func RepositoryInbox(ctx *context.APIContext) { return } federationInfo = &result - log.Info("RepositoryInbox: nodeInfo validated: %v", federationInfo) + log.Info("RepositoryInbox: federationInfo validated: %v", federationInfo) } actorID, err := forgefed.NewPersonID(actorUri, string(federationInfo.NodeInfo.Source)) @@ -222,6 +222,10 @@ func createFederationInfo(ctx *context.APIContext, actorID forgefed.ActorID) (fo HostFqdn: actorID.Host, NodeInfo: nodeInfo, } + err = forgefed.CreateFederationInfo(ctx, result) + if err != nil { + return forgefed.FederationInfo{}, err + } return result, nil } diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index f268929382..12c11f26d3 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -71,7 +71,7 @@ "name": "body", "in": "body", "schema": { - "$ref": "#/definitions/Star" + "$ref": "#/definitions/ForgeLike" } } ], @@ -20480,6 +20480,11 @@ }, "x-go-package": "code.gitea.io/gitea/modules/structs" }, + "ForgeLike": { + "description": "ForgeLike activity data type", + "type": "object", + "x-go-package": "code.gitea.io/gitea/models/forgefed" + }, "GPGKey": { "description": "GPGKey a user GPG key to sign commit and tag in repository", "type": "object", @@ -23178,20 +23183,6 @@ }, "x-go-package": "code.gitea.io/gitea/modules/structs" }, - "SourceType": { - "type": "string", - "x-go-package": "code.gitea.io/gitea/models/forgefed" - }, - "Star": { - "description": "Star activity data type", - "type": "object", - "properties": { - "Source": { - "$ref": "#/definitions/SourceType" - } - }, - "x-go-package": "code.gitea.io/gitea/models/forgefed" - }, "StateType": { "description": "StateType issue state type", "type": "string",