From 002a46fed3379adf97f976dd6d4e9023e8699497 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Sat, 18 Jun 2022 17:18:02 -0500 Subject: [PATCH] Move repo endpoints to /api/v1/activitypub/repo --- routers/api/v1/activitypub/person.go | 2 +- routers/api/v1/activitypub/repo.go | 8 +- routers/api/v1/api.go | 12 +- templates/swagger/v1_json.tmpl | 240 +++++++++++++++------------ 4 files changed, 144 insertions(+), 118 deletions(-) diff --git a/routers/api/v1/activitypub/person.go b/routers/api/v1/activitypub/person.go index 4302fe60c..32d1c2a70 100644 --- a/routers/api/v1/activitypub/person.go +++ b/routers/api/v1/activitypub/person.go @@ -270,7 +270,7 @@ func PersonLiked(ctx *context.APIContext) { liked.TotalItems = uint(count) for _, repo := range repos { - repo := forgefed.RepositoryNew(ap.IRI(strings.TrimSuffix(setting.AppURL, "/") + "/api/v1/activitypub/user/" + repo.OwnerName + "/" + repo.Name)) + repo := forgefed.RepositoryNew(ap.IRI(strings.TrimSuffix(setting.AppURL, "/") + "/api/v1/activitypub/repo/" + repo.OwnerName + "/" + repo.Name)) liked.OrderedItems.Append(repo) } diff --git a/routers/api/v1/activitypub/repo.go b/routers/api/v1/activitypub/repo.go index 8a780683d..a766c41ef 100644 --- a/routers/api/v1/activitypub/repo.go +++ b/routers/api/v1/activitypub/repo.go @@ -22,7 +22,7 @@ import ( // Repo function func Repo(ctx *context.APIContext) { - // swagger:operation GET /activitypub/user/{username}/{reponame} activitypub activitypubRepo + // swagger:operation GET /activitypub/repo/{username}/{reponame} activitypub activitypubRepo // --- // summary: Returns the repository // produces: @@ -71,7 +71,7 @@ func Repo(ctx *context.APIContext) { // RepoInbox function func RepoInbox(ctx *context.APIContext) { - // swagger:operation POST /activitypub/user/{username}/{reponame}/inbox activitypub activitypubRepoInbox + // swagger:operation POST /activitypub/repo/{username}/{reponame}/inbox activitypub activitypubRepoInbox // --- // summary: Send to the inbox // produces: @@ -109,7 +109,7 @@ func RepoInbox(ctx *context.APIContext) { // RepoOutbox function func RepoOutbox(ctx *context.APIContext) { - // swagger:operation GET /activitypub/user/{username}/outbox activitypub activitypubPersonOutbox + // swagger:operation GET /activitypub/repo/{username}/outbox activitypub activitypubPersonOutbox // --- // summary: Returns the outbox // produces: @@ -158,7 +158,7 @@ func RepoOutbox(ctx *context.APIContext) { // RepoFollowers function func RepoFollowers(ctx *context.APIContext) { - // swagger:operation GET /activitypub/user/{username}/{reponame}/followers activitypub activitypubRepoFollowers + // swagger:operation GET /activitypub/repo/{username}/{reponame}/followers activitypub activitypubRepoFollowers // --- // summary: Returns the followers collection // produces: diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index 2e976e966..59d5cd231 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -652,13 +652,13 @@ func Routes() *web.Route { m.Get("/following", activitypub.PersonFollowing) m.Get("/followers", activitypub.PersonFollowers) m.Get("/liked", activitypub.PersonLiked) - m.Group("/{reponame}", func() { - m.Get("", activitypub.Repo) - m.Post("/inbox", activitypub.ReqHTTPSignature(), activitypub.RepoInbox) - m.Get("/outbox", activitypub.RepoOutbox) - m.Get("/followers", activitypub.RepoFollowers) - }, repoAssignment()) }, context_service.UserAssignmentAPI()) + m.Group("/repo/{username}/{reponame}", func() { + m.Get("", activitypub.Repo) + m.Post("/inbox", activitypub.ReqHTTPSignature(), activitypub.RepoInbox) + m.Get("/outbox", activitypub.RepoOutbox) + m.Get("/followers", activitypub.RepoFollowers) + }, repoAssignment()) }) } m.Get("/signing-key.gpg", misc.SigningKey) diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 23d700ded..6ad45012e 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -23,6 +23,138 @@ }, "basePath": "{{AppSubUrl | JSEscape | Safe}}/api/v1", "paths": { + "/activitypub/repo/{username}/outbox": { + "get": { + "produces": [ + "application/activity+json" + ], + "tags": [ + "activitypub" + ], + "summary": "Returns the outbox", + "operationId": "activitypubPersonOutbox", + "parameters": [ + { + "type": "string", + "description": "username of the user", + "name": "username", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "name of the repository", + "name": "reponame", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "$ref": "#/responses/ActivityPub" + } + } + } + }, + "/activitypub/repo/{username}/{reponame}": { + "get": { + "produces": [ + "application/activity+json" + ], + "tags": [ + "activitypub" + ], + "summary": "Returns the repository", + "operationId": "activitypubRepo", + "parameters": [ + { + "type": "string", + "description": "username of the user", + "name": "username", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "name of the repository", + "name": "reponame", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "$ref": "#/responses/ActivityPub" + } + } + } + }, + "/activitypub/repo/{username}/{reponame}/followers": { + "get": { + "produces": [ + "application/activity+json" + ], + "tags": [ + "activitypub" + ], + "summary": "Returns the followers collection", + "operationId": "activitypubRepoFollowers", + "parameters": [ + { + "type": "string", + "description": "username of the user", + "name": "username", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "name of the repository", + "name": "reponame", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "$ref": "#/responses/ActivityPub" + } + } + } + }, + "/activitypub/repo/{username}/{reponame}/inbox": { + "post": { + "produces": [ + "application/activity+json" + ], + "tags": [ + "activitypub" + ], + "summary": "Send to the inbox", + "operationId": "activitypubRepoInbox", + "parameters": [ + { + "type": "string", + "description": "username of the user", + "name": "username", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "name of the repository", + "name": "reponame", + "in": "path", + "required": true + } + ], + "responses": { + "204": { + "$ref": "#/responses/empty" + } + } + } + }, "/activitypub/user/{username}": { "get": { "produces": [ @@ -135,7 +267,7 @@ "tags": [ "activitypub" ], - "summary": "Returns the outbox", + "summary": "Returns the Outbox OrderedCollection", "operationId": "activitypubPersonOutbox", "parameters": [ { @@ -144,13 +276,6 @@ "name": "username", "in": "path", "required": true - }, - { - "type": "string", - "description": "name of the repository", - "name": "reponame", - "in": "path", - "required": true } ], "responses": { @@ -160,105 +285,6 @@ } } }, - "/activitypub/user/{username}/{reponame}": { - "get": { - "produces": [ - "application/activity+json" - ], - "tags": [ - "activitypub" - ], - "summary": "Returns the repository", - "operationId": "activitypubRepo", - "parameters": [ - { - "type": "string", - "description": "username of the user", - "name": "username", - "in": "path", - "required": true - }, - { - "type": "string", - "description": "name of the repository", - "name": "reponame", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "$ref": "#/responses/ActivityPub" - } - } - } - }, - "/activitypub/user/{username}/{reponame}/followers": { - "get": { - "produces": [ - "application/activity+json" - ], - "tags": [ - "activitypub" - ], - "summary": "Returns the followers collection", - "operationId": "activitypubRepoFollowers", - "parameters": [ - { - "type": "string", - "description": "username of the user", - "name": "username", - "in": "path", - "required": true - }, - { - "type": "string", - "description": "name of the repository", - "name": "reponame", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "$ref": "#/responses/ActivityPub" - } - } - } - }, - "/activitypub/user/{username}/{reponame}/inbox": { - "post": { - "produces": [ - "application/activity+json" - ], - "tags": [ - "activitypub" - ], - "summary": "Send to the inbox", - "operationId": "activitypubRepoInbox", - "parameters": [ - { - "type": "string", - "description": "username of the user", - "name": "username", - "in": "path", - "required": true - }, - { - "type": "string", - "description": "name of the repository", - "name": "reponame", - "in": "path", - "required": true - } - ], - "responses": { - "204": { - "$ref": "#/responses/empty" - } - } - } - }, "/admin/cron": { "get": { "produces": [