Saving
This commit is contained in:
111
PrivaPub/Controllers/ServerToServer/PeasantsController.cs
Normal file
111
PrivaPub/Controllers/ServerToServer/PeasantsController.cs
Normal file
@ -0,0 +1,111 @@
|
||||
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;
|
||||
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<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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
69
PrivaPub/Controllers/ServerToServer/UsersController.cs
Normal file
69
PrivaPub/Controllers/ServerToServer/UsersController.cs
Normal file
@ -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