diff --git a/PluralKit.API/Controllers/v2/AutoproxyControllerV2.cs b/PluralKit.API/Controllers/v2/AutoproxyControllerV2.cs index d72c6d78..ac057d66 100644 --- a/PluralKit.API/Controllers/v2/AutoproxyControllerV2.cs +++ b/PluralKit.API/Controllers/v2/AutoproxyControllerV2.cs @@ -22,6 +22,10 @@ public class AutoproxyControllerV2: PKControllerBase public Task 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 PostWrapper([FromRoute] string systemRef, [FromQuery] ulong? guild_id, [FromQuery] ulong? channel_id) + => Entrypoint(systemRef, guild_id, channel_id, null); + public async Task 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 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(); + } } \ No newline at end of file diff --git a/docs/content/api/endpoints.md b/docs/content/api/endpoints.md index 0f64f111..932d4e61 100644 --- a/docs/content/api/endpoints.md +++ b/docs/content/api/endpoints.md @@ -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 diff --git a/services/api/src/main.rs b/services/api/src/main.rs index 1d9aed28..3b5aae78 100644 --- a/services/api/src/main.rs +++ b/services/api/src/main.rs @@ -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))