added nodeinfo 2.1

This commit is contained in:
Nicolas Constant 2020-07-07 18:30:52 -04:00
parent 4cb185569b
commit 5cd6279da8
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
12 changed files with 168 additions and 84 deletions

View File

@ -4,6 +4,7 @@ using System.Linq;
using System.Threading.Tasks;
using BirdsiteLive.Common.Settings;
using BirdsiteLive.Models;
using BirdsiteLive.Models.WellKnownModels;
using BirdsiteLive.Twitter;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
@ -35,44 +36,85 @@ namespace BirdsiteLive.Controllers
{
rel = "http://nodeinfo.diaspora.software/ns/schema/2.0",
href = $"https://{_settings.Domain}/nodeinfo/2.0.json"
},
new Link()
{
rel = "http://nodeinfo.diaspora.software/ns/schema/2.1",
href = $"https://{_settings.Domain}/nodeinfo/2.1.json"
}
}
};
return new JsonResult(nodeInfo);
}
[Route("/nodeinfo/2.0.json")]
public IActionResult NodeInfo()
[Route("/nodeinfo/{id}.json")]
public IActionResult NodeInfo(string id)
{
var nodeInfo = new NodeInfo
if (id == "2.0")
{
version = "2.0",
usage = new Usage()
var nodeInfo = new NodeInfoV20
{
localPosts = 0,
users = new Users()
version = "2.0",
usage = new Usage()
{
total = 0
localPosts = 0,
users = new Users()
{
total = 0
}
},
software = new Software()
{
name = "birdsitelive",
version = "0.1.0"
},
protocols = new[]
{
"activitypub"
},
openRegistrations = false,
services = new Models.WellKnownModels.Services()
{
inbound = new object[0],
outbound = new object[0]
}
},
software = new Software()
};
return new JsonResult(nodeInfo);
}
if (id == "2.1")
{
var nodeInfo = new NodeInfoV21
{
name = "birdsitelive",
version = "0.1.0"
},
protocols = new []
{
"activitypub"
},
openRegistrations = false,
services = new Services()
{
inbound = new object[0],
outbound = new object[0]
}
};
version = "2.1",
usage = new Usage()
{
localPosts = 0,
users = new Users()
{
total = 0
}
},
software = new SoftwareV21()
{
name = "birdsitelive",
version = "0.1.0",
repository = "https://github.com/NicolasConstant/BirdsiteLive"
},
protocols = new[]
{
"activitypub"
},
openRegistrations = false,
services = new Models.WellKnownModels.Services()
{
inbound = new object[0],
outbound = new object[0]
}
};
return new JsonResult(nodeInfo);
}
return new JsonResult(nodeInfo);
return NotFound();
}
[Route("/.well-known/webfinger")]
@ -135,63 +177,4 @@ namespace BirdsiteLive.Controllers
return new JsonResult(result);
}
}
public class WebFingerResult
{
public string subject { get; set; }
public string[] aliases { get; set; }
public List<WebFingerLink> links { get; set; } = new List<WebFingerLink>();
}
public class WebFingerLink
{
public string rel { get; set; }
public string type { get; set; }
public string href { get; set; }
}
public class WellKnownNodeInfo
{
public Link[] links { get; set; }
}
public class Link
{
public string href { get; set; }
public string rel { get; set; }
}
public class NodeInfo
{
public string version { get; set; }
public string[] protocols { get; set; }
public Software software { get; set; }
public Usage usage { get; set; }
public bool openRegistrations { get; set; }
public Services services { get; set; }
//public object metadata { get; set; }
}
public class Services
{
public object[] inbound { get; set; }
public object[] outbound { get; set; }
}
public class Software
{
public string name { get; set; }
public string version { get; set; }
}
public class Usage
{
public int localPosts { get; set; }
public Users users { get; set; }
}
public class Users
{
public int total { get; set; }
}
}

View File

@ -0,0 +1,8 @@
namespace BirdsiteLive.Models.WellKnownModels
{
public class Link
{
public string href { get; set; }
public string rel { get; set; }
}
}

View File

@ -0,0 +1,13 @@
namespace BirdsiteLive.Models.WellKnownModels
{
public class NodeInfoV20
{
public string version { get; set; }
public string[] protocols { get; set; }
public Software software { get; set; }
public Usage usage { get; set; }
public bool openRegistrations { get; set; }
public Services services { get; set; }
//public object metadata { get; set; }
}
}

View File

@ -0,0 +1,13 @@
namespace BirdsiteLive.Models.WellKnownModels
{
public class NodeInfoV21
{
public string version { get; set; }
public string[] protocols { get; set; }
public Usage usage { get; set; }
public bool openRegistrations { get; set; }
public SoftwareV21 software { get; set; }
public Services services { get; set; }
//public object metadata { get; set; }
}
}

View File

@ -0,0 +1,8 @@
namespace BirdsiteLive.Models.WellKnownModels
{
public class Services
{
public object[] inbound { get; set; }
public object[] outbound { get; set; }
}
}

View File

@ -0,0 +1,8 @@
namespace BirdsiteLive.Models.WellKnownModels
{
public class Software
{
public string name { get; set; }
public string version { get; set; }
}
}

View File

@ -0,0 +1,9 @@
namespace BirdsiteLive.Models.WellKnownModels
{
public class SoftwareV21
{
public string name { get; set; }
public string repository { get; set; }
public string version { get; set; }
}
}

View File

@ -0,0 +1,8 @@
namespace BirdsiteLive.Models.WellKnownModels
{
public class Usage
{
public int localPosts { get; set; }
public Users users { get; set; }
}
}

View File

@ -0,0 +1,7 @@
namespace BirdsiteLive.Models.WellKnownModels
{
public class Users
{
public int total { get; set; }
}
}

View File

@ -0,0 +1,9 @@
namespace BirdsiteLive.Models.WellKnownModels
{
public class WebFingerLink
{
public string rel { get; set; }
public string type { get; set; }
public string href { get; set; }
}
}

View File

@ -0,0 +1,11 @@
using System.Collections.Generic;
namespace BirdsiteLive.Models.WellKnownModels
{
public class WebFingerResult
{
public string subject { get; set; }
public string[] aliases { get; set; }
public List<WebFingerLink> links { get; set; } = new List<WebFingerLink>();
}
}

View File

@ -0,0 +1,7 @@
namespace BirdsiteLive.Models.WellKnownModels
{
public class WellKnownNodeInfo
{
public Link[] links { get; set; }
}
}