added user is gone exception
This commit is contained in:
parent
e78bc262ed
commit
0e9938b712
3 changed files with 35 additions and 14 deletions
|
@ -11,7 +11,6 @@ using BirdsiteLive.ActivityPub.Models;
|
||||||
using BirdsiteLive.Common.Settings;
|
using BirdsiteLive.Common.Settings;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Org.BouncyCastle.Bcpg;
|
|
||||||
|
|
||||||
namespace BirdsiteLive.Domain
|
namespace BirdsiteLive.Domain
|
||||||
{
|
{
|
||||||
|
@ -45,6 +44,12 @@ namespace BirdsiteLive.Domain
|
||||||
var httpClient = _httpClientFactory.CreateClient();
|
var httpClient = _httpClientFactory.CreateClient();
|
||||||
httpClient.DefaultRequestHeaders.Add("Accept", "application/activity+json");
|
httpClient.DefaultRequestHeaders.Add("Accept", "application/activity+json");
|
||||||
var result = await httpClient.GetAsync(objectId);
|
var result = await httpClient.GetAsync(objectId);
|
||||||
|
|
||||||
|
if (result.StatusCode == HttpStatusCode.Gone)
|
||||||
|
throw new UserIsGoneException();
|
||||||
|
|
||||||
|
result.EnsureSuccessStatusCode();
|
||||||
|
|
||||||
var content = await result.Content.ReadAsStringAsync();
|
var content = await result.Content.ReadAsStringAsync();
|
||||||
|
|
||||||
var actor = JsonConvert.DeserializeObject<Actor>(content);
|
var actor = JsonConvert.DeserializeObject<Actor>(content);
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace BirdsiteLive.Domain
|
||||||
|
{
|
||||||
|
public class UserIsGoneException : Exception
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
|
@ -183,33 +183,41 @@ namespace BirdsiteLive.Controllers
|
||||||
switch (activity?.type)
|
switch (activity?.type)
|
||||||
{
|
{
|
||||||
case "Follow":
|
case "Follow":
|
||||||
{
|
{
|
||||||
var succeeded = await _userService.FollowRequestedAsync(signature, r.Method, r.Path,
|
var succeeded = await _userService.FollowRequestedAsync(signature, r.Method, r.Path,
|
||||||
r.QueryString.ToString(), HeaderHandler.RequestHeaders(r.Headers), activity as ActivityFollow, body);
|
r.QueryString.ToString(), HeaderHandler.RequestHeaders(r.Headers),
|
||||||
if (succeeded) return Accepted();
|
activity as ActivityFollow, body);
|
||||||
else return Unauthorized();
|
if (succeeded) return Accepted();
|
||||||
}
|
else return Unauthorized();
|
||||||
|
}
|
||||||
case "Undo":
|
case "Undo":
|
||||||
if (activity is ActivityUndoFollow)
|
if (activity is ActivityUndoFollow)
|
||||||
{
|
{
|
||||||
var succeeded = await _userService.UndoFollowRequestedAsync(signature, r.Method, r.Path,
|
var succeeded = await _userService.UndoFollowRequestedAsync(signature, r.Method, r.Path,
|
||||||
r.QueryString.ToString(), HeaderHandler.RequestHeaders(r.Headers), activity as ActivityUndoFollow, body);
|
r.QueryString.ToString(), HeaderHandler.RequestHeaders(r.Headers),
|
||||||
|
activity as ActivityUndoFollow, body);
|
||||||
if (succeeded) return Accepted();
|
if (succeeded) return Accepted();
|
||||||
else return Unauthorized();
|
else return Unauthorized();
|
||||||
}
|
}
|
||||||
|
|
||||||
return Accepted();
|
return Accepted();
|
||||||
case "Delete":
|
case "Delete":
|
||||||
{
|
{
|
||||||
var succeeded = await _userService.DeleteRequestedAsync(signature, r.Method, r.Path,
|
var succeeded = await _userService.DeleteRequestedAsync(signature, r.Method, r.Path,
|
||||||
r.QueryString.ToString(), HeaderHandler.RequestHeaders(r.Headers), activity as ActivityDelete, body);
|
r.QueryString.ToString(), HeaderHandler.RequestHeaders(r.Headers),
|
||||||
if (succeeded) return Accepted();
|
activity as ActivityDelete, body);
|
||||||
else return Unauthorized();
|
if (succeeded) return Accepted();
|
||||||
}
|
else return Unauthorized();
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return Accepted();
|
return Accepted();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (UserIsGoneException)
|
||||||
|
{
|
||||||
|
return Accepted();
|
||||||
|
}
|
||||||
catch (UserNotFoundException)
|
catch (UserNotFoundException)
|
||||||
{
|
{
|
||||||
return NotFound();
|
return NotFound();
|
||||||
|
|
Loading…
Add table
Reference in a new issue