2023-02-18 08:52:17 +01:00
|
|
|
|
using Markdig;
|
|
|
|
|
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
2023-02-19 00:43:43 +01:00
|
|
|
|
using PrivaPub.ClientModels.Resources;
|
|
|
|
|
using PrivaPub.Extensions;
|
|
|
|
|
using PrivaPub.Models.ActivityPub;
|
|
|
|
|
using PrivaPub.Services;
|
2023-02-18 08:52:17 +01:00
|
|
|
|
|
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
|
using System.Text.Json;
|
|
|
|
|
|
2023-02-19 00:43:43 +01:00
|
|
|
|
namespace PrivaPub.Controllers.ServerToServer
|
2023-02-18 08:52:17 +01:00
|
|
|
|
{
|
|
|
|
|
[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<IActionResult> 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<IActionResult> 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<IActionResult> Month(
|
|
|
|
|
[Required(ErrorMessageResourceName = "Required",
|
|
|
|
|
ErrorMessageResourceType = typeof(FieldsNameResource))] string actor,
|
|
|
|
|
[FromBody] JsonDocument json)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
return Ok();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost, Route("{actor}/human-centipede")]
|
|
|
|
|
public async Task<IActionResult> HumanCentipede(
|
|
|
|
|
[Required(ErrorMessageResourceName = "Required",
|
|
|
|
|
ErrorMessageResourceType = typeof(FieldsNameResource))] string actor,
|
|
|
|
|
[FromBody] JsonDocument json)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
return Ok();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost, Route("/human-centipede")]
|
|
|
|
|
public async Task<IActionResult> PublicHumanCentipede(
|
|
|
|
|
[FromBody] JsonDocument json)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
return Ok();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|