Files
daniel-c-harvey 77c6c42c94 remediate: replace eval cookie writes with safe JS helper + add tests (18.6 Track A)
Both SettingsCookieService and DarkModeCookieService now call window.DeepDrftSettings.setCookie (new Interop/settings/settings.ts) instead of eval. New tests cover SettingsServiceBase parse/format round-trip and the PreferenceAwareStreamingPlayerService invariant (Lossless skips probe; LowData inherits base).
2026-06-23 14:17:34 -04:00

33 lines
1.3 KiB
C#

using DeepDrftPublic.Client.Common;
using Microsoft.JSInterop;
namespace DeepDrftPublic.Client.Services;
/// <summary>
/// Client-side runtime writer for public-site settings (Phase 18 wave 18.6), the analogue of
/// <see cref="DarkModeCookieService"/>. Reads the current preference off the in-memory
/// <see cref="PublicSiteSettings"/> (already seeded at prerender and bridged into WASM), and writes a
/// 365-day cookie via <c>document.cookie</c> interop when the listener changes it in the Settings menu —
/// the same durable-truth seam dark mode uses, so the choice survives the session and seeds the next visit's
/// prerender (no flash).
/// </summary>
public class SettingsCookieService(PublicSiteSettings settings, IJSRuntime js) : SettingsServiceBase
{
private const int ExpiryDays = 365;
public StreamQuality GetStreamQuality() => settings.StreamQuality;
public async ValueTask SetStreamQualityAsync(StreamQuality quality)
{
if (settings.StreamQuality == quality) return;
await WriteCookieAsync(StreamQualityCookieName, FormatStreamQuality(quality));
settings.StreamQuality = quality;
}
private async ValueTask WriteCookieAsync(string name, string value)
{
await js.InvokeVoidAsync("DeepDrftSettings.setCookie", name, value, ExpiryDays);
}
}