Skip to content

Commit

Permalink
Add optional filtering for plugins GET endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
JustArchi committed Dec 25, 2024
1 parent 711cda2 commit ba68d10
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion ArchiSteamFarm/IPC/Controllers/Api/PluginsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,28 @@ namespace ArchiSteamFarm.IPC.Controllers.Api;

[Route("Api/Plugins")]
public sealed class PluginsController : ArchiController {

Check warning on line 39 in ArchiSteamFarm/IPC/Controllers/Api/PluginsController.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

RoslynAnalyzers Consider making public types internal

Because an application's API isn't typically referenced from outside the assembly, types can be made internal
/// <summary>
/// Gets active plugins loaded into the process.
/// </summary>
[HttpGet]
[ProducesResponseType<GenericResponse<IReadOnlyCollection<IPlugin>>>((int) HttpStatusCode.OK)]
public ActionResult<GenericResponse<IReadOnlyCollection<IPlugin>>> PluginsGet() => Ok(new GenericResponse<IReadOnlyCollection<IPlugin>>(PluginsCore.ActivePlugins));
public ActionResult<GenericResponse<IReadOnlyCollection<IPlugin>>> PluginsGet([FromQuery] bool official = true, [FromQuery] bool custom = true) {
HashSet<IPlugin> result = [];

foreach (IPlugin plugin in PluginsCore.ActivePlugins) {
if (plugin is OfficialPlugin) {
if (official) {
result.Add(plugin);
}
} else {
if (custom) {
result.Add(plugin);
}
}
}

return Ok(new GenericResponse<IReadOnlyCollection<IPlugin>>(result));
}

/// <summary>
/// Makes ASF update selected plugins.
Expand Down

0 comments on commit ba68d10

Please sign in to comment.