From cb0a9de3302fd27189e9b714eeadbfa16eaa80b4 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Wed, 6 Apr 2022 09:05:42 -0500 Subject: [PATCH] Add API endpoints for inbox/outbox --- routers/api/v1/activitypub/person.go | 77 +++++++++++++++++++++++++-- routers/api/v1/api.go | 5 +- templates/swagger/v1_json.tmpl | 78 +++++++++++++++++++++++++++- 3 files changed, 152 insertions(+), 8 deletions(-) diff --git a/routers/api/v1/activitypub/person.go b/routers/api/v1/activitypub/person.go index 4be076a9c..8d3119590 100644 --- a/routers/api/v1/activitypub/person.go +++ b/routers/api/v1/activitypub/person.go @@ -94,8 +94,30 @@ func Person(ctx *context.APIContext) { ctx.JSON(http.StatusOK, jsonmap) } -// PersonInbox function -func PersonInbox(ctx *context.APIContext) { +// PersonInboxGet function +func PersonInboxGet(ctx *context.APIContext) { + // swagger:operation GET /activitypub/user/{username}/outbox activitypub activitypubPersonInbox + // --- + // summary: Returns the inbox + // produces: + // - application/json + // parameters: + // - name: username + // in: path + // description: username of the user + // type: string + // required: true + // responses: + // responses: + // "200": + // "$ref": "#/responses/ActivityPub" + + ctx.Status(http.StatusOK) + activitypub.GetUserActor().GetInbox(ctx, ctx.Resp, ctx.Req) +} + +// PersonInboxPost function +func PersonInboxPost(ctx *context.APIContext) { // swagger:operation POST /activitypub/user/{username}/inbox activitypub activitypubPersonInbox // --- // summary: Send to the inbox @@ -109,8 +131,53 @@ func PersonInbox(ctx *context.APIContext) { // required: true // responses: // responses: - // "204": - // "$ref": "#/responses/empty" + // "200": + // "$ref": "#/responses/ActivityPub" - ctx.Status(http.StatusNoContent) + ctx.Status(http.StatusOK) + activitypub.GetUserActor().PostInbox(ctx, ctx.Resp, ctx.Req) } + +// PersonOutboxGet function +func PersonOutboxGet(ctx *context.APIContext) { + // swagger:operation GET /activitypub/user/{username}/outbox activitypub activitypubPersonOutbox + // --- + // summary: Returns the outbox + // produces: + // - application/json + // parameters: + // - name: username + // in: path + // description: username of the user + // type: string + // required: true + // responses: + // responses: + // "200": + // "$ref": "#/responses/ActivityPub" + + ctx.Status(http.StatusOK) + activitypub.GetUserActor().GetOutbox(ctx, ctx.Resp, ctx.Req) +} + +// PersonOutboxPost function +func PersonOutboxPost(ctx *context.APIContext) { + // swagger:operation POST /activitypub/user/{username}/outbox activitypub activitypubPersonOutbox + // --- + // summary: Send to the outbox + // produces: + // - application/json + // parameters: + // - name: username + // in: path + // description: username of the user + // type: string + // required: true + // responses: + // responses: + // "200": + // "$ref": "#/responses/ActivityPub" + + ctx.Status(http.StatusOK) + activitypub.GetUserActor().PostOutbox(ctx, ctx.Resp, ctx.Req) +} \ No newline at end of file diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index fb1af75ec..614134014 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -600,7 +600,10 @@ func Routes(sessioner func(http.Handler) http.Handler) *web.Route { m.Get("/nodeinfo", misc.NodeInfo) m.Group("/activitypub", func() { m.Get("/user/{username}", activitypub.Person) - m.Post("/user/{username}/inbox", activitypub.ReqSignature(), activitypub.PersonInbox) + m.Get("/user/{username}/inbox", activitypub.ReqSignature(), activitypub.PersonInboxGet) + m.Post("/user/{username}/inbox", activitypub.ReqSignature(), activitypub.PersonInboxPost) + m.Get("/user/{username}/outbox", activitypub.ReqSignature(), activitypub.PersonOutboxGet) + m.Post("/user/{username}/outbox", activitypub.ReqSignature(), activitypub.PersonOutboxPost) }) } m.Get("/signing-key.gpg", misc.SigningKey) diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index c068612f5..154eba5ae 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -50,6 +50,30 @@ } }, "/activitypub/user/{username}/inbox": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "activitypub" + ], + "summary": "Returns the inbox", + "operationId": "activitypubPersonInbox", + "parameters": [ + { + "type": "string", + "description": "username of the user", + "name": "username", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "$ref": "#/responses/ActivityPub" + } + } + }, "post": { "produces": [ "application/json" @@ -69,8 +93,58 @@ } ], "responses": { - "204": { - "$ref": "#/responses/empty" + "200": { + "$ref": "#/responses/ActivityPub" + } + } + } + }, + "/activitypub/user/{username}/outbox": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "activitypub" + ], + "summary": "Returns the outbox", + "operationId": "activitypubPersonOutbox", + "parameters": [ + { + "type": "string", + "description": "username of the user", + "name": "username", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "$ref": "#/responses/ActivityPub" + } + } + }, + "post": { + "produces": [ + "application/json" + ], + "tags": [ + "activitypub" + ], + "summary": "Send to the outbox", + "operationId": "activitypubPersonOutbox", + "parameters": [ + { + "type": "string", + "description": "username of the user", + "name": "username", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "$ref": "#/responses/ActivityPub" } } }