Backend of #197 Bundle A (auth posture). Owner decisions: single API key; Api:RequireKeyForReads defaults true (whole /api surface gated; /iptv streaming + guide unaffected — outside the filter's /api scope). - #280 S1: writes are fail-closed. New IApiKeyProvider resolves the key once (Api:WriteKey config, else persisted /config/api.key, else a generated 256-bit key written 0600). The empty-key open branch is gone; there is no open mode. - #282 S3/S5: reads under /api require the key when Api:RequireKeyForReads (default true) or the endpoint carries the new [RequiresApiKey]. Applied [RequiresApiKey] to Troubleshoot/Logs/Settings/Maintenance so the sensitive tier stays gated even if reads are opened. OPTIONS preflight is exempt. - #281 S2: delete SortController (dead Blazor SortableJS residue; SPA uses PUT /api/collections/{id}/custom-order) and AccountController (dead OIDC logout) — both non-/api persistent surfaces that bypassed the key. - #284 S6: replace CORS AllowAll with an opt-in exact-origin allowlist (Api:CorsAllowedOrigins; permits X-Api-Key/If-Match, exposes ETag). Default is no cross-origin (SPA is same-origin). - #285 S7/S10: gc GET->POST (spec regenerated); ForwardedHeaders trust configurable via ForwardedHeaders:KnownProxies/KnownNetworks (warns when unrestricted); ScannerController gains [LocalhostOnly] (scanner always calls back over localhost). Filter unit tests rewritten for fail-closed + read-gating + tier + OPTIONS; ApiControllerSecurityTests assert the sensitive tier + scanner-loopback reflectively. search/all-items paging deferred (SPA add-all coupling) — exposure closed by read-gating. Refs #197 #280 #281 #282 #284 #285 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
57 lines
1.7 KiB
C#
57 lines
1.7 KiB
C#
using System.Threading.Channels;
|
|
using ErsatzTV.Application;
|
|
using ErsatzTV.Application.Search;
|
|
using ErsatzTV.Core.Interfaces.Metadata;
|
|
using ErsatzTV.Filters;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace ErsatzTV.Controllers.Api;
|
|
|
|
[ApiController]
|
|
[ApiExplorerSettings(IgnoreApi = true)]
|
|
[SkipApiKeyAuthorization]
|
|
[LocalhostOnly]
|
|
[Route("api/scan/{scanId:guid}")]
|
|
public class ScannerController(
|
|
IScannerProxyService scannerProxyService,
|
|
ChannelWriter<ISearchIndexBackgroundServiceRequest> channelWriter)
|
|
{
|
|
[HttpPost("progress")]
|
|
[EndpointSummary("Scanner progress update")]
|
|
public async Task<IActionResult> Progress(Guid scanId, [FromBody] decimal percentComplete)
|
|
{
|
|
await scannerProxyService.Progress(scanId, percentComplete);
|
|
return new OkResult();
|
|
}
|
|
|
|
[HttpPost("items/reindex")]
|
|
[EndpointSummary("Scanner reindex items in search index")]
|
|
public async Task<IActionResult> UpdateItems(
|
|
Guid scanId,
|
|
[FromBody] List<int> itemsToUpdate,
|
|
CancellationToken cancellationToken)
|
|
{
|
|
if (scannerProxyService.IsActive(scanId))
|
|
{
|
|
await channelWriter.WriteAsync(new ReindexMediaItems(itemsToUpdate), cancellationToken);
|
|
}
|
|
|
|
return new OkResult();
|
|
}
|
|
|
|
[HttpPost("items/remove")]
|
|
[EndpointSummary("Scanner remove items from search index")]
|
|
public async Task<IActionResult> RemoveItems(
|
|
Guid scanId,
|
|
[FromBody] List<int> itemsToRemove,
|
|
CancellationToken cancellationToken)
|
|
{
|
|
if (scannerProxyService.IsActive(scanId))
|
|
{
|
|
await channelWriter.WriteAsync(new RemoveMediaItems(itemsToRemove), cancellationToken);
|
|
}
|
|
|
|
return new OkResult();
|
|
}
|
|
}
|