Saving
This commit is contained in:
1 parent
9719a0c0fd
commit
1e66851113
146 files changed
+738
-382
No files matched your search
@@ -0,0 +1,69 @@
|
||||
using Markdig;
|
||||
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using PrivaPub.ClientModels.Resources;
|
||||
using PrivaPub.Extensions;
|
||||
using PrivaPub.Models.ActivityPub;
|
||||
using PrivaPub.Models.Group;
|
||||
using PrivaPub.Services;
|
||||
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace PrivaPub.Controllers.ServerToServer
|
||||
{
|
||||
[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
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user