SocialPub/PrivaPub/Controllers/ServerToServer/UsersController.cs

70 lines
2.1 KiB
C#
Raw Normal View History

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.Models.Group;
using PrivaPub.Services;
2023-02-18 08:52:17 +01:00
using System.ComponentModel.DataAnnotations;
2023-02-19 00:43:43 +01:00
namespace PrivaPub.Controllers.ServerToServer
2023-02-18 08:52:17 +01:00
{
[ApiController,
Route("users"), Produces("application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"; charset=utf-8")]
public class UsersController : ControllerBase
{
readonly IRootUsersService _rootUsersService;
public UsersController(IRootUsersService rootUsersService)
{
_rootUsersService = rootUsersService;
}
[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.GetHost()}/peasants/{actor}";
actorResponse.ProfileURL = $"{HttpContext.GetHost()}/peasants/{actor}";
actorResponse.Inbox = $"{HttpContext.GetHost()}/peasants/{actor}/mouth";
actorResponse.Outbox = $"{HttpContext.GetHost()}/peasants/{actor}/anus";
actorResponse.Endpoints = new()
{
SharedInboxURL = $"{HttpContext.GetHost()}/peasants/{actor}/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);
}
#region Admin
#endregion
}
}