From 3e6eb255b357e25f040e640542e3f5e578c72c44 Mon Sep 17 00:00:00 2001 From: erik Date: Thu, 21 Mar 2024 16:29:13 +0100 Subject: [PATCH] WIP Initial, naive implementation of sending stars to fed repos Currently no rate limits are respected The mechanisms to use the Federated repo table need to be used --- routers/api/v1/user/star.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/routers/api/v1/user/star.go b/routers/api/v1/user/star.go index 2659789ddd..a07407ffc3 100644 --- a/routers/api/v1/user/star.go +++ b/routers/api/v1/user/star.go @@ -7,12 +7,16 @@ package user import ( std_context "context" "net/http" + "strings" "code.gitea.io/gitea/models/db" + "code.gitea.io/gitea/models/forgefed" access_model "code.gitea.io/gitea/models/perm/access" repo_model "code.gitea.io/gitea/models/repo" user_model "code.gitea.io/gitea/models/user" + "code.gitea.io/gitea/modules/activitypub" "code.gitea.io/gitea/modules/context" + "code.gitea.io/gitea/modules/setting" api "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/routers/api/v1/utils" "code.gitea.io/gitea/services/convert" @@ -160,6 +164,32 @@ func Star(ctx *context.APIContext) { ctx.Error(http.StatusInternalServerError, "StarRepo", err) return } + if setting.Federation.Enabled { + + likeActivity, err := forgefed.NewForgeLike(ctx) + if err != nil { + ctx.Error(http.StatusInternalServerError, "StarRepo", err) + return + } + + json, err := likeActivity.MarshalJSON() + if err != nil { + ctx.Error(http.StatusInternalServerError, "StarRepo", err) + return + } + + apclient, err := activitypub.NewClient(ctx, ctx.Doer, ctx.Doer.APAPIURL()) + if err != nil { + ctx.Error(http.StatusInternalServerError, "StarRepo", err) + return + } + // ToDo: Change this to the standalone table of FederatedRepos + for _, target := range strings.Split(ctx.Repo.Repository.FederationRepos, ";") { + apclient.Post([]byte(json), target) + } + + // Send to list of federated repos + } ctx.Status(http.StatusNoContent) }