[backend/controllers] Return local user & note counts in nodeinfo endpoints
This commit is contained in:
parent
81e9c7e635
commit
bc12e7fbcb
1 changed files with 10 additions and 4 deletions
|
@ -1,7 +1,9 @@
|
||||||
using Iceshrimp.Backend.Core.Configuration;
|
using Iceshrimp.Backend.Core.Configuration;
|
||||||
|
using Iceshrimp.Backend.Core.Database;
|
||||||
using Iceshrimp.Backend.Core.Federation.WebFinger;
|
using Iceshrimp.Backend.Core.Federation.WebFinger;
|
||||||
using Microsoft.AspNetCore.Cors;
|
using Microsoft.AspNetCore.Cors;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
namespace Iceshrimp.Backend.Controllers;
|
namespace Iceshrimp.Backend.Controllers;
|
||||||
|
@ -10,13 +12,17 @@ namespace Iceshrimp.Backend.Controllers;
|
||||||
[Tags("Federation")]
|
[Tags("Federation")]
|
||||||
[Route("/nodeinfo")]
|
[Route("/nodeinfo")]
|
||||||
[EnableCors("well-known")]
|
[EnableCors("well-known")]
|
||||||
public class NodeInfoController(IOptions<Config.InstanceSection> config) : Controller {
|
public class NodeInfoController(IOptions<Config.InstanceSection> config, DatabaseContext db) : Controller {
|
||||||
[HttpGet("2.1")]
|
[HttpGet("2.1")]
|
||||||
[HttpGet("2.0")]
|
[HttpGet("2.0")]
|
||||||
[Produces("application/json")]
|
[Produces("application/json")]
|
||||||
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(WebFingerResponse))]
|
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(WebFingerResponse))]
|
||||||
public IActionResult GetNodeInfo() {
|
public async Task<IActionResult> GetNodeInfo() {
|
||||||
var instance = config.Value;
|
var instance = config.Value;
|
||||||
|
var totalUsers =
|
||||||
|
await db.Users.LongCountAsync(p => p.Host == null && !Constants.SystemUsers.Contains(p.UsernameLower));
|
||||||
|
var localPosts = await db.Notes.LongCountAsync(p => p.UserHost == null);
|
||||||
|
|
||||||
var result = new NodeInfoResponse {
|
var result = new NodeInfoResponse {
|
||||||
Version = instance.Version,
|
Version = instance.Version,
|
||||||
Software = new NodeInfoResponse.NodeInfoSoftware {
|
Software = new NodeInfoResponse.NodeInfoSoftware {
|
||||||
|
@ -35,11 +41,11 @@ public class NodeInfoController(IOptions<Config.InstanceSection> config) : Contr
|
||||||
Usage = new NodeInfoResponse.NodeInfoUsage {
|
Usage = new NodeInfoResponse.NodeInfoUsage {
|
||||||
//FIXME Implement members
|
//FIXME Implement members
|
||||||
Users = new NodeInfoResponse.NodeInfoUsers {
|
Users = new NodeInfoResponse.NodeInfoUsers {
|
||||||
Total = 0,
|
Total = totalUsers,
|
||||||
ActiveMonth = 0,
|
ActiveMonth = 0,
|
||||||
ActiveHalfYear = 0
|
ActiveHalfYear = 0
|
||||||
},
|
},
|
||||||
LocalComments = 0,
|
LocalComments = localPosts,
|
||||||
LocalPosts = 0
|
LocalPosts = 0
|
||||||
},
|
},
|
||||||
Metadata = new NodeInfoResponse.NodeInfoMetadata {
|
Metadata = new NodeInfoResponse.NodeInfoMetadata {
|
||||||
|
|
Loading…
Add table
Reference in a new issue