commit
6b511e9f54
7 changed files with 51 additions and 36 deletions
17
src/BirdsiteLive.ActivityPub/Converters/UrlFactory.cs
Normal file
17
src/BirdsiteLive.ActivityPub/Converters/UrlFactory.cs
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
|
namespace BirdsiteLive.ActivityPub.Converters
|
||||||
|
{
|
||||||
|
public class UrlFactory
|
||||||
|
{
|
||||||
|
public static string GetActorUrl(string domain, string username)
|
||||||
|
{
|
||||||
|
return $"https://{domain.ToLowerInvariant()}/users/{username.ToLowerInvariant()}";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string GetNoteUrl(string domain, string username, string noteId)
|
||||||
|
{
|
||||||
|
return $"https://{domain.ToLowerInvariant()}/users/{username.ToLowerInvariant()}/statuses/{noteId}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,6 +6,7 @@ using System.Security.Cryptography;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using BirdsiteLive.ActivityPub;
|
using BirdsiteLive.ActivityPub;
|
||||||
|
using BirdsiteLive.ActivityPub.Converters;
|
||||||
using BirdsiteLive.ActivityPub.Models;
|
using BirdsiteLive.ActivityPub.Models;
|
||||||
using BirdsiteLive.Common.Settings;
|
using BirdsiteLive.Common.Settings;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
@ -47,18 +48,8 @@ namespace BirdsiteLive.Domain
|
||||||
|
|
||||||
public async Task<HttpStatusCode> PostNewNoteActivity(Note note, string username, string noteId, string targetHost, string targetInbox)
|
public async Task<HttpStatusCode> PostNewNoteActivity(Note note, string username, string noteId, string targetHost, string targetInbox)
|
||||||
{
|
{
|
||||||
//var username = "gra";
|
var actor = UrlFactory.GetActorUrl(_instanceSettings.Domain, username);
|
||||||
var actor = $"https://{_instanceSettings.Domain}/users/{username}";
|
var noteUri = UrlFactory.GetNoteUrl(_instanceSettings.Domain, username, noteId);
|
||||||
//var targetHost = "mastodon.technology";
|
|
||||||
//var target = $"{targetHost}/users/testtest";
|
|
||||||
//var inbox = $"/users/testtest/inbox";
|
|
||||||
|
|
||||||
//var noteGuid = Guid.NewGuid();
|
|
||||||
var noteUri = $"https://{_instanceSettings.Domain}/users/{username}/statuses/{noteId}";
|
|
||||||
|
|
||||||
//var noteUrl = $"https://{_instanceSettings.Domain}/@{username}/{noteId}";
|
|
||||||
//var to = $"{actor}/followers";
|
|
||||||
//var apPublic = "https://www.w3.org/ns/activitystreams#Public";
|
|
||||||
|
|
||||||
var now = DateTime.UtcNow;
|
var now = DateTime.UtcNow;
|
||||||
var nowString = now.ToString("s") + "Z";
|
var nowString = now.ToString("s") + "Z";
|
||||||
|
|
|
@ -4,6 +4,7 @@ using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using BirdsiteLive.ActivityPub;
|
using BirdsiteLive.ActivityPub;
|
||||||
|
using BirdsiteLive.ActivityPub.Converters;
|
||||||
using BirdsiteLive.ActivityPub.Models;
|
using BirdsiteLive.ActivityPub.Models;
|
||||||
using BirdsiteLive.Common.Settings;
|
using BirdsiteLive.Common.Settings;
|
||||||
using BirdsiteLive.Domain.Tools;
|
using BirdsiteLive.Domain.Tools;
|
||||||
|
@ -33,9 +34,8 @@ namespace BirdsiteLive.Domain
|
||||||
|
|
||||||
public Note GetStatus(string username, ExtractedTweet tweet)
|
public Note GetStatus(string username, ExtractedTweet tweet)
|
||||||
{
|
{
|
||||||
var actorUrl = $"https://{_instanceSettings.Domain}/users/{username}";
|
var actorUrl = UrlFactory.GetActorUrl(_instanceSettings.Domain, username);
|
||||||
var noteId = $"https://{_instanceSettings.Domain}/users/{username}/statuses/{tweet.Id}";
|
var noteUrl = UrlFactory.GetNoteUrl(_instanceSettings.Domain, username, tweet.Id.ToString());
|
||||||
var noteUrl = $"https://{_instanceSettings.Domain}/@{username}/{tweet.Id}";
|
|
||||||
|
|
||||||
var to = $"{actorUrl}/followers";
|
var to = $"{actorUrl}/followers";
|
||||||
var apPublic = "https://www.w3.org/ns/activitystreams#Public";
|
var apPublic = "https://www.w3.org/ns/activitystreams#Public";
|
||||||
|
@ -44,12 +44,11 @@ namespace BirdsiteLive.Domain
|
||||||
|
|
||||||
string inReplyTo = null;
|
string inReplyTo = null;
|
||||||
if (tweet.InReplyToStatusId != default)
|
if (tweet.InReplyToStatusId != default)
|
||||||
inReplyTo = $"https://{_instanceSettings.Domain}/users/{tweet.InReplyToAccount}/statuses/{tweet.InReplyToStatusId}";
|
inReplyTo = $"https://{_instanceSettings.Domain}/users/{tweet.InReplyToAccount.ToLowerInvariant()}/statuses/{tweet.InReplyToStatusId}";
|
||||||
|
|
||||||
var note = new Note
|
var note = new Note
|
||||||
{
|
{
|
||||||
//id = $"{noteId}/activity",
|
id = noteUrl,
|
||||||
id = $"{noteId}",
|
|
||||||
|
|
||||||
published = tweet.CreatedAt.ToString("s") + "Z",
|
published = tweet.CreatedAt.ToString("s") + "Z",
|
||||||
url = noteUrl,
|
url = noteUrl,
|
||||||
|
@ -69,7 +68,6 @@ namespace BirdsiteLive.Domain
|
||||||
tag = extractedTags.tags
|
tag = extractedTags.tags
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
return note;
|
return note;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ using System.Security.Cryptography;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using BirdsiteLive.ActivityPub;
|
using BirdsiteLive.ActivityPub;
|
||||||
|
using BirdsiteLive.ActivityPub.Converters;
|
||||||
using BirdsiteLive.Common.Settings;
|
using BirdsiteLive.Common.Settings;
|
||||||
using BirdsiteLive.Cryptography;
|
using BirdsiteLive.Cryptography;
|
||||||
using BirdsiteLive.Domain.BusinessUseCases;
|
using BirdsiteLive.Domain.BusinessUseCases;
|
||||||
|
@ -45,21 +46,24 @@ namespace BirdsiteLive.Domain
|
||||||
|
|
||||||
public Actor GetUser(TwitterUser twitterUser)
|
public Actor GetUser(TwitterUser twitterUser)
|
||||||
{
|
{
|
||||||
|
var actorUrl = UrlFactory.GetActorUrl(_instanceSettings.Domain, twitterUser.Acct);
|
||||||
|
var acct = twitterUser.Acct.ToLowerInvariant();
|
||||||
|
|
||||||
var user = new Actor
|
var user = new Actor
|
||||||
{
|
{
|
||||||
id = $"https://{_instanceSettings.Domain}/users/{twitterUser.Acct}",
|
id = actorUrl,
|
||||||
type = "Service", //Person Service
|
type = "Service",
|
||||||
followers = $"https://{_instanceSettings.Domain}/users/{twitterUser.Acct}/followers",
|
followers = $"{actorUrl}/followers",
|
||||||
preferredUsername = twitterUser.Acct,
|
preferredUsername = acct,
|
||||||
name = twitterUser.Name,
|
name = twitterUser.Name,
|
||||||
inbox = $"https://{_instanceSettings.Domain}/users/{twitterUser.Acct}/inbox",
|
inbox = $"{actorUrl}/inbox",
|
||||||
summary = twitterUser.Description,
|
summary = twitterUser.Description,
|
||||||
url = $"https://{_instanceSettings.Domain}/@{twitterUser.Acct}",
|
url = actorUrl,
|
||||||
publicKey = new PublicKey()
|
publicKey = new PublicKey()
|
||||||
{
|
{
|
||||||
id = $"https://{_instanceSettings.Domain}/users/{twitterUser.Acct}#main-key",
|
id = $"{actorUrl}#main-key",
|
||||||
owner = $"https://{_instanceSettings.Domain}/users/{twitterUser.Acct}",
|
owner = actorUrl,
|
||||||
publicKeyPem = _cryptoService.GetUserPem(twitterUser.Acct)
|
publicKeyPem = _cryptoService.GetUserPem(acct)
|
||||||
},
|
},
|
||||||
icon = new Image
|
icon = new Image
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||||
<UserSecretsId>d21486de-a812-47eb-a419-05682bb68856</UserSecretsId>
|
<UserSecretsId>d21486de-a812-47eb-a419-05682bb68856</UserSecretsId>
|
||||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||||
<Version>0.3.2</Version>
|
<Version>0.3.3</Version>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
@ -48,7 +48,7 @@ namespace BirdsiteLive.Controllers
|
||||||
[Route("/users/{id}")]
|
[Route("/users/{id}")]
|
||||||
public IActionResult Index(string id)
|
public IActionResult Index(string id)
|
||||||
{
|
{
|
||||||
id = id.Trim(new[] {' ', '@'});
|
id = id.Trim(new[] {' ', '@'}).ToLowerInvariant();
|
||||||
var user = _twitterService.GetUser(id);
|
var user = _twitterService.GetUser(id);
|
||||||
|
|
||||||
var r = Request.Headers["Accept"].First();
|
var r = Request.Headers["Accept"].First();
|
||||||
|
@ -66,11 +66,11 @@ namespace BirdsiteLive.Controllers
|
||||||
{
|
{
|
||||||
Name = user.Name,
|
Name = user.Name,
|
||||||
Description = user.Description,
|
Description = user.Description,
|
||||||
Acct = user.Acct,
|
Acct = user.Acct.ToLowerInvariant(),
|
||||||
Url = user.Url,
|
Url = user.Url,
|
||||||
ProfileImageUrl = user.ProfileImageUrl,
|
ProfileImageUrl = user.ProfileImageUrl,
|
||||||
|
|
||||||
InstanceHandle = $"@{user.Acct}@{_instanceSettings.Domain}"
|
InstanceHandle = $"@{user.Acct.ToLowerInvariant()}@{_instanceSettings.Domain}"
|
||||||
};
|
};
|
||||||
return View(displayableUser);
|
return View(displayableUser);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using BirdsiteLive.ActivityPub.Converters;
|
||||||
using BirdsiteLive.Common.Settings;
|
using BirdsiteLive.Common.Settings;
|
||||||
using BirdsiteLive.DAL.Contracts;
|
using BirdsiteLive.DAL.Contracts;
|
||||||
using BirdsiteLive.Models;
|
using BirdsiteLive.Models;
|
||||||
|
@ -156,6 +157,9 @@ namespace BirdsiteLive.Controllers
|
||||||
return BadRequest();
|
return BadRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ensure lowercase
|
||||||
|
name = name.ToLowerInvariant();
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(domain) && domain != _settings.Domain)
|
if (!string.IsNullOrWhiteSpace(domain) && domain != _settings.Domain)
|
||||||
return NotFound();
|
return NotFound();
|
||||||
|
|
||||||
|
@ -163,13 +167,14 @@ namespace BirdsiteLive.Controllers
|
||||||
if (user == null)
|
if (user == null)
|
||||||
return NotFound();
|
return NotFound();
|
||||||
|
|
||||||
|
var actorUrl = UrlFactory.GetActorUrl(_settings.Domain, name);
|
||||||
|
|
||||||
var result = new WebFingerResult()
|
var result = new WebFingerResult()
|
||||||
{
|
{
|
||||||
subject = $"acct:{name}@{_settings.Domain}",
|
subject = $"acct:{name}@{_settings.Domain}",
|
||||||
aliases = new[]
|
aliases = new[]
|
||||||
{
|
{
|
||||||
$"https://{_settings.Domain}/@{name}",
|
actorUrl
|
||||||
$"https://{_settings.Domain}/users/{name}"
|
|
||||||
},
|
},
|
||||||
links = new List<WebFingerLink>
|
links = new List<WebFingerLink>
|
||||||
{
|
{
|
||||||
|
@ -177,13 +182,13 @@ namespace BirdsiteLive.Controllers
|
||||||
{
|
{
|
||||||
rel = "http://webfinger.net/rel/profile-page",
|
rel = "http://webfinger.net/rel/profile-page",
|
||||||
type = "text/html",
|
type = "text/html",
|
||||||
href = $"https://{_settings.Domain}/@{name}"
|
href = actorUrl
|
||||||
},
|
},
|
||||||
new WebFingerLink()
|
new WebFingerLink()
|
||||||
{
|
{
|
||||||
rel = "self",
|
rel = "self",
|
||||||
type = "application/activity+json",
|
type = "application/activity+json",
|
||||||
href = $"https://{_settings.Domain}/users/{name}"
|
href = actorUrl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue