using Markdig; using Microsoft.AspNetCore.Mvc; using PrivaPub.ClientModels.Resources; using PrivaPub.Extensions; using PrivaPub.Models.ActivityPub; using PrivaPub.Services; using System.ComponentModel.DataAnnotations; using System.Text.Json; namespace PrivaPub.Controllers.ServerToServer { [ApiController, Route("peasants"), Produces("application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"; charset=utf-8")] public class PeasantsController : ControllerBase { readonly IGroupUsersService _groupUsersService; public PeasantsController(IGroupUsersService groupUsersService) { _groupUsersService = groupUsersService; } [HttpGet, Route("{actor}")] public async Task GetActor( [Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(FieldsNameResource))] string actor, CancellationToken cancellation) { var getResult = await _groupUsersService.GetGroup(actor, cancellation); if (!getResult.IsValid) return StatusCode(getResult.StatusCode, getResult); var actorResponse = new ActivityPubActor(); actorResponse.Context[1] = string.Format(actorResponse.Context[1].ToString(), HttpContext.Request.PathBase); actorResponse.Id = HttpContext.GetHostWithPath(); actorResponse.ProfileURL = HttpContext.GetHostWithPath(); actorResponse.Inbox = $"{HttpContext.GetHostWithPath()}/mouth"; actorResponse.Outbox = $"{HttpContext.GetHostWithPath()}/anus"; actorResponse.Endpoints = new() { SharedInboxURL = $"{HttpContext.GetHostWithPath()}/human-centipede", OAuthAuthorizationEndpoint = $"{HttpContext.GetHost()}/sniff/again", }; actorResponse.PreferredUsername = actor; actorResponse.Name = actor; if (getResult.Data is DmGroup dmGroup) { actorResponse.Summary = Markdown.ToHtml(dmGroup.Description); actorResponse.Published = dmGroup.CreationDate; } else if (getResult.Data is Group dbGroup) { actorResponse.Summary = Markdown.ToHtml(dbGroup.Description); actorResponse.Published = dbGroup.CreationDate; } return Ok(actorResponse); } [HttpGet, Route("{actor}/anus")] public async Task Anus( [FromQuery] bool? page, [Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(FieldsNameResource))] string actor) { if (!page.HasValue) return Ok(new ActivityPubOrderedCollection { Id = HttpContext.Request.Path, FirstItem = $"{HttpContext.GetHostWithPath()}?page=true", }); return Ok(); } [HttpPost, Route("{actor}/mouth")] public async Task Month( [Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(FieldsNameResource))] string actor, [FromBody] JsonDocument json) { return Ok(); } [HttpPost, Route("{actor}/human-centipede")] public async Task HumanCentipede( [Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(FieldsNameResource))] string actor, [FromBody] JsonDocument json) { return Ok(); } [HttpPost, Route("/human-centipede")] public async Task PublicHumanCentipede( [FromBody] JsonDocument json) { return Ok(); } } }