[backend/api] Add optional userId query parameter to /admin/fetch & /fetch-raw
This commit is contained in:
parent
744a01d138
commit
09623a94c8
2 changed files with 19 additions and 7 deletions
|
@ -139,9 +139,10 @@ public class AdminController(
|
|||
[HttpGet("activities/fetch")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(ASObject))]
|
||||
[Produces("application/activity+json", "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"")]
|
||||
public async Task<IActionResult> FetchActivityAsync([FromQuery] string uri)
|
||||
public async Task<IActionResult> FetchActivityAsync([FromQuery] string uri, [FromQuery] string? userId)
|
||||
{
|
||||
var activity = await fetchSvc.FetchActivityAsync(uri);
|
||||
var user = userId != null ? await db.Users.FirstOrDefaultAsync(p => p.Id == userId && p.Host == null) : null;
|
||||
var activity = await fetchSvc.FetchActivityAsync(uri, user);
|
||||
if (!activity.Any()) throw GracefulException.UnprocessableEntity("Failed to fetch activity");
|
||||
return Ok(LdHelpers.Compact(activity));
|
||||
}
|
||||
|
@ -151,9 +152,10 @@ public class AdminController(
|
|||
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(ASObject))]
|
||||
[ProducesResponseType(StatusCodes.Status422UnprocessableEntity, Type = typeof(ErrorResponse))]
|
||||
[Produces("application/activity+json", "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"")]
|
||||
public async Task FetchRawActivityAsync([FromQuery] string uri)
|
||||
public async Task FetchRawActivityAsync([FromQuery] string uri, [FromQuery] string? userId)
|
||||
{
|
||||
var activity = await fetchSvc.FetchRawActivityAsync(uri);
|
||||
var user = userId != null ? await db.Users.FirstOrDefaultAsync(p => p.Id == userId && p.Host == null) : null;
|
||||
var activity = await fetchSvc.FetchRawActivityAsync(uri, user);
|
||||
if (activity == null) throw GracefulException.UnprocessableEntity("Failed to fetch activity");
|
||||
|
||||
Response.ContentType = Request.Headers.Accept.Any(p => p != null && p.StartsWith("application/ld+json"))
|
||||
|
|
|
@ -36,9 +36,19 @@ public class ActivityFetcherService(
|
|||
return await FetchActivityAsync(url, actor, keypair);
|
||||
}
|
||||
|
||||
public async Task<string?> FetchRawActivityAsync(string url)
|
||||
public async Task<IEnumerable<ASObject>> FetchActivityAsync(string url, User? actor)
|
||||
{
|
||||
var (actor, keypair) = await systemUserSvc.GetInstanceActorWithKeypairAsync();
|
||||
var keypair = actor != null ? await db.UserKeypairs.FirstOrDefaultAsync(p => p.User == actor) : null;
|
||||
if (actor == null || keypair == null)
|
||||
(actor, keypair) = await systemUserSvc.GetInstanceActorWithKeypairAsync();
|
||||
return await FetchActivityAsync(url, actor, keypair);
|
||||
}
|
||||
|
||||
public async Task<string?> FetchRawActivityAsync(string url, User? actor)
|
||||
{
|
||||
var keypair = actor != null ? await db.UserKeypairs.FirstOrDefaultAsync(p => p.User == actor) : null;
|
||||
if (actor == null || keypair == null)
|
||||
(actor, keypair) = await systemUserSvc.GetInstanceActorWithKeypairAsync();
|
||||
return await FetchRawActivityAsync(url, actor, keypair);
|
||||
}
|
||||
|
||||
|
@ -78,7 +88,7 @@ public class ActivityFetcherService(
|
|||
var requestHost = new Uri(url).Host;
|
||||
if (requestHost == config.Value.WebDomain || requestHost == config.Value.AccountDomain)
|
||||
throw GracefulException.UnprocessableEntity("Refusing to fetch activity from local domain");
|
||||
|
||||
|
||||
if (await fedCtrlSvc.ShouldBlockAsync(requestHost))
|
||||
{
|
||||
logger.LogDebug("Refusing to fetch activity from blocked instance");
|
||||
|
|
Loading…
Add table
Reference in a new issue