feat(api): add endpoint for latch clear

This commit is contained in:
Ashelyn Violet 2024-01-18 00:56:57 -07:00
parent 29382b252f
commit 6e0458e288
No known key found for this signature in database
GPG key ID: D1980B8C6F349BC1
3 changed files with 38 additions and 0 deletions

View file

@ -22,6 +22,10 @@ public class AutoproxyControllerV2: PKControllerBase
public Task<IActionResult> PatchWrapper([FromRoute] string systemRef, [FromQuery] ulong? guild_id, [FromQuery] ulong? channel_id, [FromBody] JObject? data)
=> Entrypoint(systemRef, guild_id, channel_id, data);
[HttpPost("systems/{systemRef}/autoproxy/unlatch")]
public Task<IActionResult> PostWrapper([FromRoute] string systemRef, [FromQuery] ulong? guild_id, [FromQuery] ulong? channel_id)
=> Entrypoint(systemRef, guild_id, channel_id, null);
public async Task<IActionResult> Entrypoint(string systemRef, ulong? guild_id, ulong? channel_id, JObject? data)
{
var system = await ResolveSystem(systemRef);
@ -39,6 +43,8 @@ public class AutoproxyControllerV2: PKControllerBase
return await Get(settings);
else if (HttpContext.Request.Method == "PATCH")
return await Patch(system, guild_id, channel_id, data, settings);
else if (HttpContext.Request.Method == "POST")
return await Post(system, guild_id, channel_id, settings);
else return StatusCode(415);
}
@ -81,4 +87,17 @@ public class AutoproxyControllerV2: PKControllerBase
member = await _repo.GetMember(oldData.AutoproxyMember.Value);
return Ok(res.ToJson(member?.Hid));
}
private async Task<IActionResult> Post(PKSystem system, ulong? guildId, ulong? channelId, AutoproxySettings settings)
{
if (settings.AutoproxyMode == AutoproxyMode.Latch)
{
await _repo.UpdateAutoproxy(system.Id, guildId, channelId, new()
{
AutoproxyMember = null
});
}
return NoContent();
}
}

View file

@ -94,6 +94,24 @@ Returns an [autoproxy settings](/api/models/#autoproxy-settings-model) object on
Currently, only autoproxy with `guild_id` is supported. The API will return an error message if you specify `channel_id`, or do not specify a `guild_id`.
:::
### Clear System Autoproxy Latch
POST `/systems/@me/autoproxy/unlatch`
Query String Parameters
|name|type|
|---|---|
|guild_id?|snowflake|
|channel_id?|snowflake|
If autoproxy latch is enabled: clear latch status, without disabling autoproxy. If autoproxy latch is not enabled, this endpoint is a no-op.
Returns 204 No Content on success.
::: warning
Currently, only autoproxy with `guild_id` is supported. The API will return an error message if you specify `channel_id`, or do not specify a `guild_id`.
:::
---
## Members

View file

@ -61,6 +61,7 @@ async fn main() -> anyhow::Result<()> {
.route("/v2/systems/:system_id/autoproxy", get(util::rproxy))
.route("/v2/systems/:system_id/autoproxy", patch(util::rproxy))
.route("/v2/systems/:system_id/autoproxy/unlatch", post(util::rproxy))
.route("/v2/messages/:message_id", get(util::rproxy))