added mastodon API for posts
This commit is contained in:
parent
a662302e71
commit
01acc03dca
3 changed files with 87 additions and 2 deletions
|
@ -5,7 +5,6 @@ using System.Linq;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Net.Mime;
|
using System.Net.Mime;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using BirdsiteLive.ActivityPub;
|
using BirdsiteLive.ActivityPub;
|
||||||
using BirdsiteLive.ActivityPub.Models;
|
using BirdsiteLive.ActivityPub.Models;
|
||||||
|
@ -185,6 +184,44 @@ namespace BirdsiteLive.Controllers
|
||||||
return View(displayTweet);
|
return View(displayTweet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Mastodon API for QT in some apps
|
||||||
|
[Route("/api/v1/statuses/{statusId}")]
|
||||||
|
public async Task<IActionResult> mastoApi(string id, string statusId)
|
||||||
|
{
|
||||||
|
if (!long.TryParse(statusId, out var parsedStatusId))
|
||||||
|
return NotFound();
|
||||||
|
|
||||||
|
var tweet = await _twitterTweetService.GetTweetAsync(parsedStatusId);
|
||||||
|
if (tweet == null)
|
||||||
|
return NotFound();
|
||||||
|
|
||||||
|
var user = await _twitterUserService.GetUserAsync(tweet.Author.Acct);
|
||||||
|
var status = _statusService.GetActivity(tweet.Author.Acct, tweet);
|
||||||
|
var res = new MastodonPostApi()
|
||||||
|
{
|
||||||
|
id = parsedStatusId,
|
||||||
|
content = status.apObject.content,
|
||||||
|
created_at = status.published,
|
||||||
|
uri = $"https://{_instanceSettings.Domain}/users/{tweet.Author.Acct}/statuses/{tweet.Id}",
|
||||||
|
url = $"https://{_instanceSettings.Domain}/@{tweet.Author.Acct}/{tweet.Id}",
|
||||||
|
account = new MastodonUserApi()
|
||||||
|
{
|
||||||
|
Id = user.Id,
|
||||||
|
username = user.Acct,
|
||||||
|
acct = user.Acct,
|
||||||
|
display_name = user.Name,
|
||||||
|
Note = user.Description,
|
||||||
|
avatar = user.ProfileImageUrl,
|
||||||
|
avatar_static = user.ProfileImageUrl,
|
||||||
|
header = user.ProfileBannerURL,
|
||||||
|
header_static = user.ProfileBannerURL,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
var jsonApUser = JsonSerializer.Serialize(res);
|
||||||
|
return Content(jsonApUser, "application/activity+json; charset=utf-8");
|
||||||
|
}
|
||||||
[Route("/users/{id}/statuses/{statusId}/activity")]
|
[Route("/users/{id}/statuses/{statusId}/activity")]
|
||||||
public async Task<IActionResult> Activity(string id, string statusId)
|
public async Task<IActionResult> Activity(string id, string statusId)
|
||||||
{
|
{
|
||||||
|
|
48
src/BirdsiteLive/Models/MastodonPostApi.cs
Normal file
48
src/BirdsiteLive/Models/MastodonPostApi.cs
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace BirdsiteLive.Models;
|
||||||
|
|
||||||
|
public class MastodonPostApi
|
||||||
|
{
|
||||||
|
public long id { get; set; }
|
||||||
|
public string created_at { get; set; }
|
||||||
|
public long? in_reply_to_id { get; set; } = null;
|
||||||
|
public long? in_reply_to_account_id { get; set; } = null;
|
||||||
|
public bool sensitive { get; set; } = false;
|
||||||
|
public string spoiler_text { get; set; } = "";
|
||||||
|
public string visibility { get; set; } = "public";
|
||||||
|
public string language { get; set; } = "en";
|
||||||
|
public string uri { get; set; }
|
||||||
|
public string url { get; set; }
|
||||||
|
public int replies_count { get; set; } = 0;
|
||||||
|
public int reblogs_count { get; set; } = 0;
|
||||||
|
public int favorite_count { get; set; } = 0;
|
||||||
|
public string content { get; set; }
|
||||||
|
public MastodonUserApi account { get; set; }
|
||||||
|
public MastodonAppApi application { get; } = new MastodonAppApi();
|
||||||
|
}
|
||||||
|
public class MastodonUserApi
|
||||||
|
{
|
||||||
|
public long Id { get; set; }
|
||||||
|
public string username { get; set; }
|
||||||
|
public string acct { get; set; }
|
||||||
|
public string display_name { get; set; }
|
||||||
|
public bool locked { get; set; } = false;
|
||||||
|
public bool bot { get; set; } = true;
|
||||||
|
public bool group { get; set; } = false;
|
||||||
|
public string Note { get; set; }
|
||||||
|
public string Url { get; set; }
|
||||||
|
public string avatar { get; set; }
|
||||||
|
public string avatar_static { get; set; }
|
||||||
|
public string header { get; set; }
|
||||||
|
public string header_static { get; set; }
|
||||||
|
public int followers_count { get; set; } = 0;
|
||||||
|
public int following_count { get; set; } = 0;
|
||||||
|
public int statuses_count { get; set; } = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class MastodonAppApi
|
||||||
|
{
|
||||||
|
public string name { get; set; } = "bird.makeup";
|
||||||
|
public string url { get; set; } = "https://bird.makeup/";
|
||||||
|
}
|
|
@ -90,7 +90,7 @@ namespace BirdsiteLive.DAL.Postgres.DataAccessLayers
|
||||||
|
|
||||||
using (var dbConnection = Connection)
|
using (var dbConnection = Connection)
|
||||||
{
|
{
|
||||||
var result = (await dbConnection.QueryAsync<TimeSpan>(query)).FirstOrDefault();
|
var result = (await dbConnection.QueryAsync<TimeSpan?>(query)).FirstOrDefault() ?? TimeSpan.Zero;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue