From 5454d176ddd44a9da73bf5aa64686a81a99977cd Mon Sep 17 00:00:00 2001 From: Nicolas Constant Date: Mon, 11 Jan 2021 01:08:23 -0500 Subject: [PATCH 1/3] make endpoints more resilient to missing accept header --- .../Controllers/UsersController.cs | 54 +++++++++++-------- 1 file changed, 33 insertions(+), 21 deletions(-) diff --git a/src/BirdsiteLive/Controllers/UsersController.cs b/src/BirdsiteLive/Controllers/UsersController.cs index 78941d5..ca222ae 100644 --- a/src/BirdsiteLive/Controllers/UsersController.cs +++ b/src/BirdsiteLive/Controllers/UsersController.cs @@ -39,8 +39,12 @@ namespace BirdsiteLive.Controllers [Route("/users")] public IActionResult Index() { - var r = Request.Headers["Accept"].First(); - if (r.Contains("application/activity+json")) return NotFound(); + var acceptHeaders = Request.Headers["Accept"]; + if (acceptHeaders.Any()) + { + var r = acceptHeaders.First(); + if (r.Contains("application/activity+json")) return NotFound(); + } return View("UserNotFound"); } @@ -48,16 +52,20 @@ namespace BirdsiteLive.Controllers [Route("/users/{id}")] public IActionResult Index(string id) { - id = id.Trim(new[] {' ', '@'}).ToLowerInvariant(); + id = id.Trim(new[] { ' ', '@' }).ToLowerInvariant(); var user = _twitterService.GetUser(id); - var r = Request.Headers["Accept"].First(); - if (r.Contains("application/activity+json")) + var acceptHeaders = Request.Headers["Accept"]; + if (acceptHeaders.Any()) { - if (user == null) return NotFound(); - var apUser = _userService.GetUser(user); - var jsonApUser = JsonConvert.SerializeObject(apUser); - return Content(jsonApUser, "application/activity+json; charset=utf-8"); + var r = acceptHeaders.First(); + if (r.Contains("application/activity+json")) + { + if (user == null) return NotFound(); + var apUser = _userService.GetUser(user); + var jsonApUser = JsonConvert.SerializeObject(apUser); + return Content(jsonApUser, "application/activity+json; charset=utf-8"); + } } if (user == null) return View("UserNotFound"); @@ -79,22 +87,26 @@ namespace BirdsiteLive.Controllers [Route("/users/{id}/statuses/{statusId}")] public IActionResult Tweet(string id, string statusId) { - var r = Request.Headers["Accept"].First(); - if (r.Contains("application/activity+json")) + var acceptHeaders = Request.Headers["Accept"]; + if (acceptHeaders.Any()) { - if (!long.TryParse(statusId, out var parsedStatusId)) - return NotFound(); + var r = acceptHeaders.First(); + if (r.Contains("application/activity+json")) + { + if (!long.TryParse(statusId, out var parsedStatusId)) + return NotFound(); - var tweet = _twitterService.GetTweet(parsedStatusId); - if (tweet == null) - return NotFound(); + var tweet = _twitterService.GetTweet(parsedStatusId); + if (tweet == null) + return NotFound(); - //var user = _twitterService.GetUser(id); - //if (user == null) return NotFound(); + //var user = _twitterService.GetUser(id); + //if (user == null) return NotFound(); - var status = _statusService.GetStatus(id, tweet); - var jsonApUser = JsonConvert.SerializeObject(status); - return Content(jsonApUser, "application/activity+json; charset=utf-8"); + var status = _statusService.GetStatus(id, tweet); + var jsonApUser = JsonConvert.SerializeObject(status); + return Content(jsonApUser, "application/activity+json; charset=utf-8"); + } } return View("Tweet", statusId); From d3aac062f93254f962aba65c3c5b0ad9c47a97a2 Mon Sep 17 00:00:00 2001 From: Nicolas Constant Date: Mon, 11 Jan 2021 01:34:19 -0500 Subject: [PATCH 2/3] Added official link to profile, fix #33 --- src/BirdsiteLive.ActivityPub/Models/Actor.cs | 1 + src/BirdsiteLive.ActivityPub/Models/UserAttachment.cs | 9 +++++++++ src/BirdsiteLive.Domain/UserService.cs | 9 +++++++++ 3 files changed, 19 insertions(+) create mode 100644 src/BirdsiteLive.ActivityPub/Models/UserAttachment.cs diff --git a/src/BirdsiteLive.ActivityPub/Models/Actor.cs b/src/BirdsiteLive.ActivityPub/Models/Actor.cs index 0552f25..886b862 100644 --- a/src/BirdsiteLive.ActivityPub/Models/Actor.cs +++ b/src/BirdsiteLive.ActivityPub/Models/Actor.cs @@ -23,5 +23,6 @@ namespace BirdsiteLive.ActivityPub public Image icon { get; set; } public Image image { get; set; } public EndPoints endpoints { get; set; } + public UserAttachment[] attachment { get; set; } } } diff --git a/src/BirdsiteLive.ActivityPub/Models/UserAttachment.cs b/src/BirdsiteLive.ActivityPub/Models/UserAttachment.cs new file mode 100644 index 0000000..1b7df37 --- /dev/null +++ b/src/BirdsiteLive.ActivityPub/Models/UserAttachment.cs @@ -0,0 +1,9 @@ +namespace BirdsiteLive.ActivityPub +{ + public class UserAttachment + { + public string type { get; set; } + public string name { get; set; } + public string value { get; set; } + } +} \ No newline at end of file diff --git a/src/BirdsiteLive.Domain/UserService.cs b/src/BirdsiteLive.Domain/UserService.cs index c203977..549e0ea 100644 --- a/src/BirdsiteLive.Domain/UserService.cs +++ b/src/BirdsiteLive.Domain/UserService.cs @@ -75,6 +75,15 @@ namespace BirdsiteLive.Domain mediaType = "image/jpeg", url = twitterUser.ProfileBannerURL }, + attachment = new [] + { + new UserAttachment + { + type = "PropertyValue", + name = "Official", + value = $"https://twitter.com/{acct}" + } + }, endpoints = new EndPoints { sharedInbox = $"https://{_instanceSettings.Domain}/inbox" From 7ccd619af18829fa5eefe8729f028c6155daf1ea Mon Sep 17 00:00:00 2001 From: Nicolas Constant Date: Mon, 11 Jan 2021 01:36:03 -0500 Subject: [PATCH 3/3] road to 0.4.0 --- src/BirdsiteLive/BirdsiteLive.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BirdsiteLive/BirdsiteLive.csproj b/src/BirdsiteLive/BirdsiteLive.csproj index b20520f..d6851c5 100644 --- a/src/BirdsiteLive/BirdsiteLive.csproj +++ b/src/BirdsiteLive/BirdsiteLive.csproj @@ -4,7 +4,7 @@ netcoreapp3.1 d21486de-a812-47eb-a419-05682bb68856 Linux - 0.3.3 + 0.4.0