From 19d095ce27dd1c5c59fe11102c13577a7ee56e3a Mon Sep 17 00:00:00 2001 From: Michael Jerger Date: Tue, 7 Nov 2023 09:30:32 +0100 Subject: [PATCH] add star activity & bind to swagger --- modules/forgefed/star.go | 42 ++++++++++++++++++++++++++++++++++++++++ routers/api/v1/api.go | 4 +++- 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 modules/forgefed/star.go diff --git a/modules/forgefed/star.go b/modules/forgefed/star.go new file mode 100644 index 0000000000..17bcd57aea --- /dev/null +++ b/modules/forgefed/star.go @@ -0,0 +1,42 @@ +// Copyright 2023 The Forgejo Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package forgefed + +import ( + ap "github.com/go-ap/activitypub" +) + +type ( + SourceType string +) + +type SourceTypes []SourceType + +const ( + StarType ap.ActivityVocabularyType = "Star" +) + +const ( + ForgejoSourceType SourceType = "frogejo" +) + +var KnownSourceTypes = SourceTypes{ + ForgejoSourceType, +} + +type Star struct { + ap.Activity + // Source identifies the system generated this Activity. Exact one value has to be specified. + Source SourceType `jsonld:"source,omitempty"` +} + +// RepositoryNew initializes a Repository type actor +func StarNew(id ap.ID, ob ap.ID) *Star { + a := ap.ActivityNew(id, StarType, ob) + // TODO: is this not handeld by ActivityNew?? + a.Type = StarType + o := Star{Activity: *a} + o.Source = ForgejoSourceType + return &o +} diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index 8a15fb458c..27b864b6cf 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -78,6 +78,7 @@ import ( "code.gitea.io/gitea/models/unit" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/context" + "code.gitea.io/gitea/modules/forgefed" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" api "code.gitea.io/gitea/modules/structs" @@ -836,7 +837,8 @@ func Routes() *web.Route { m.Group("/repository-id/{repository-id}", func() { m.Get("", activitypub.Repository) m.Post("/inbox", - bind(api.CreateRepoOption{}), + // TODO: bind ativities here + bind(forgefed.Star{}), //activitypub.ReqHTTPSignature(), activitypub.RepositoryInbox) }, context_service.RepositoryIDAssignmentAPI())