From 9f7c47b78e0408193dd8eae1cbccddd03614fbcb Mon Sep 17 00:00:00 2001 From: spiral Date: Wed, 19 Jan 2022 19:29:51 -0500 Subject: [PATCH] feat(api): separate private endpoints from public API versioning --- .../Controllers/PrivateController.cs | 35 +++++++++++++++++++ .../Controllers/v1/MetaController.cs | 34 ------------------ .../Controllers/v2/PrivateControllerV2.cs | 25 ------------- 3 files changed, 35 insertions(+), 59 deletions(-) create mode 100644 PluralKit.API/Controllers/PrivateController.cs delete mode 100644 PluralKit.API/Controllers/v1/MetaController.cs delete mode 100644 PluralKit.API/Controllers/v2/PrivateControllerV2.cs diff --git a/PluralKit.API/Controllers/PrivateController.cs b/PluralKit.API/Controllers/PrivateController.cs new file mode 100644 index 00000000..1dacbc7c --- /dev/null +++ b/PluralKit.API/Controllers/PrivateController.cs @@ -0,0 +1,35 @@ +using Microsoft.AspNetCore.Mvc; + +using Newtonsoft.Json.Linq; + +using PluralKit.Core; + +namespace PluralKit.API; + +// Internal API definitions +// I would prefer if you do not use any of these APIs in your own integrations. +// It is unstable and subject to change at any time (which is why it's not versioned) + +// If for some reason you do need access to something defined here, +// let us know in #api-support on the support server (https://discord.com/invite/PczBt78) and I'll see if it can be made public + +[ApiController] +[Route("private")] +public class PrivateController: PKControllerBase +{ + public PrivateController(IServiceProvider svc) : base(svc) { } + + [HttpGet("meta")] + public async Task> Meta() + { + var shards = await _repo.GetShards(); + var stats = await _repo.GetStats(); + + var o = new JObject(); + o.Add("shards", shards.ToJSON()); + o.Add("stats", stats.ToJson()); + o.Add("version", BuildInfoService.Version); + + return Ok(o); + } +} \ No newline at end of file diff --git a/PluralKit.API/Controllers/v1/MetaController.cs b/PluralKit.API/Controllers/v1/MetaController.cs deleted file mode 100644 index edd0544b..00000000 --- a/PluralKit.API/Controllers/v1/MetaController.cs +++ /dev/null @@ -1,34 +0,0 @@ -using Microsoft.AspNetCore.Mvc; - -using Newtonsoft.Json.Linq; - -using PluralKit.Core; - -namespace PluralKit.API; - -[ApiController] -[Route("v1")] -public class MetaController: ControllerBase -{ - private readonly IDatabase _db; - private readonly ModelRepository _repo; - - public MetaController(IDatabase db, ModelRepository repo) - { - _db = db; - _repo = repo; - } - - [HttpGet("meta")] - public async Task> GetMeta() - { - await using var conn = await _db.Obtain(); - var shards = await _repo.GetShards(); - - var o = new JObject(); - o.Add("shards", shards.ToJSON()); - o.Add("version", BuildInfoService.Version); - - return Ok(o); - } -} \ No newline at end of file diff --git a/PluralKit.API/Controllers/v2/PrivateControllerV2.cs b/PluralKit.API/Controllers/v2/PrivateControllerV2.cs deleted file mode 100644 index 073b67e2..00000000 --- a/PluralKit.API/Controllers/v2/PrivateControllerV2.cs +++ /dev/null @@ -1,25 +0,0 @@ -using Microsoft.AspNetCore.Mvc; - -using Newtonsoft.Json.Linq; - -namespace PluralKit.API; - -[ApiController] -[Route("v2")] -public class PrivateControllerV2: PKControllerBase -{ - public PrivateControllerV2(IServiceProvider svc) : base(svc) { } - - [HttpGet("meta")] - public async Task> Meta() - { - var shards = await _repo.GetShards(); - var stats = await _repo.GetStats(); - - var o = new JObject(); - o.Add("shards", shards.ToJSON()); - o.Add("stats", stats.ToJson()); - - return Ok(o); - } -} \ No newline at end of file