mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-24 08:57:03 -05:00
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
This commit is contained in:
parent
0c6c43003c
commit
3e6eb255b3
1 changed files with 30 additions and 0 deletions
|
@ -7,12 +7,16 @@ package user
|
||||||
import (
|
import (
|
||||||
std_context "context"
|
std_context "context"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
|
"code.gitea.io/gitea/models/forgefed"
|
||||||
access_model "code.gitea.io/gitea/models/perm/access"
|
access_model "code.gitea.io/gitea/models/perm/access"
|
||||||
repo_model "code.gitea.io/gitea/models/repo"
|
repo_model "code.gitea.io/gitea/models/repo"
|
||||||
user_model "code.gitea.io/gitea/models/user"
|
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/context"
|
||||||
|
"code.gitea.io/gitea/modules/setting"
|
||||||
api "code.gitea.io/gitea/modules/structs"
|
api "code.gitea.io/gitea/modules/structs"
|
||||||
"code.gitea.io/gitea/routers/api/v1/utils"
|
"code.gitea.io/gitea/routers/api/v1/utils"
|
||||||
"code.gitea.io/gitea/services/convert"
|
"code.gitea.io/gitea/services/convert"
|
||||||
|
@ -160,6 +164,32 @@ func Star(ctx *context.APIContext) {
|
||||||
ctx.Error(http.StatusInternalServerError, "StarRepo", err)
|
ctx.Error(http.StatusInternalServerError, "StarRepo", err)
|
||||||
return
|
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)
|
ctx.Status(http.StatusNoContent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue