summaryrefslogtreecommitdiffstats
path: root/routers/api/v1/activitypub/repository.go
diff options
context:
space:
mode:
authorDaniel Baumann <daniel@debian.org>2024-10-18 20:33:49 +0200
committerDaniel Baumann <daniel@debian.org>2024-10-18 20:33:49 +0200
commitdd136858f1ea40ad3c94191d647487fa4f31926c (patch)
tree58fec94a7b2a12510c9664b21793f1ed560c6518 /routers/api/v1/activitypub/repository.go
parentInitial commit. (diff)
downloadforgejo-upstream.tar.xz
forgejo-upstream.zip
Adding upstream version 9.0.0.upstream/9.0.0upstreamdebian
Signed-off-by: Daniel Baumann <daniel@debian.org>
Diffstat (limited to 'routers/api/v1/activitypub/repository.go')
-rw-r--r--routers/api/v1/activitypub/repository.go80
1 files changed, 80 insertions, 0 deletions
diff --git a/routers/api/v1/activitypub/repository.go b/routers/api/v1/activitypub/repository.go
new file mode 100644
index 0000000..bc6e790
--- /dev/null
+++ b/routers/api/v1/activitypub/repository.go
@@ -0,0 +1,80 @@
+// Copyright 2023, 2024 The Forgejo Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package activitypub
+
+import (
+ "fmt"
+ "net/http"
+ "strings"
+
+ "code.gitea.io/gitea/modules/forgefed"
+ "code.gitea.io/gitea/modules/log"
+ "code.gitea.io/gitea/modules/setting"
+ "code.gitea.io/gitea/modules/web"
+ "code.gitea.io/gitea/services/context"
+ "code.gitea.io/gitea/services/federation"
+
+ ap "github.com/go-ap/activitypub"
+)
+
+// Repository function returns the Repository actor for a repo
+func Repository(ctx *context.APIContext) {
+ // swagger:operation GET /activitypub/repository-id/{repository-id} activitypub activitypubRepository
+ // ---
+ // summary: Returns the Repository actor for a repo
+ // produces:
+ // - application/json
+ // parameters:
+ // - name: repository-id
+ // in: path
+ // description: repository ID of the repo
+ // type: integer
+ // required: true
+ // responses:
+ // "200":
+ // "$ref": "#/responses/ActivityPub"
+
+ link := fmt.Sprintf("%s/api/v1/activitypub/repository-id/%d", strings.TrimSuffix(setting.AppURL, "/"), ctx.Repo.Repository.ID)
+ repo := forgefed.RepositoryNew(ap.IRI(link))
+
+ repo.Name = ap.NaturalLanguageValuesNew()
+ err := repo.Name.Set("en", ap.Content(ctx.Repo.Repository.Name))
+ if err != nil {
+ ctx.Error(http.StatusInternalServerError, "Set Name", err)
+ return
+ }
+ response(ctx, repo)
+}
+
+// PersonInbox function handles the incoming data for a repository inbox
+func RepositoryInbox(ctx *context.APIContext) {
+ // swagger:operation POST /activitypub/repository-id/{repository-id}/inbox activitypub activitypubRepositoryInbox
+ // ---
+ // summary: Send to the inbox
+ // produces:
+ // - application/json
+ // parameters:
+ // - name: repository-id
+ // in: path
+ // description: repository ID of the repo
+ // type: integer
+ // required: true
+ // - name: body
+ // in: body
+ // schema:
+ // "$ref": "#/definitions/ForgeLike"
+ // responses:
+ // "204":
+ // "$ref": "#/responses/empty"
+
+ repository := ctx.Repo.Repository
+ log.Info("RepositoryInbox: repo: %v", repository)
+
+ form := web.GetForm(ctx)
+ httpStatus, title, err := federation.ProcessLikeActivity(ctx, form, repository.ID)
+ if err != nil {
+ ctx.Error(httpStatus, title, err)
+ }
+ ctx.Status(http.StatusNoContent)
+}