27 lines
1.2 KiB
C#
27 lines
1.2 KiB
C#
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Data.SqlClient;
|
|
using PlotLine.Services.Context;
|
|
|
|
namespace PlotLine.Controllers;
|
|
|
|
[Authorize]
|
|
[Route("Writing/Context/Intent")]
|
|
[ResponseCache(NoStore = true, Location = ResponseCacheLocation.None)]
|
|
public sealed class ContextIntentController(ContextIntentPalette palette) : Controller
|
|
{
|
|
// Reusable read endpoint for both Context and the docked Writer component.
|
|
// It takes an explicit held scope and never follows or changes the Word caret.
|
|
[HttpGet("Palette")]
|
|
public async Task<IActionResult> Palette([FromQuery] IntentPaletteQuery query)
|
|
{
|
|
if (!ModelState.IsValid) return BadRequest();
|
|
try { return Json(await palette.Read(query)); }
|
|
catch (ArgumentException e) { return BadRequest(new { message = e.Message }); }
|
|
// This is a JSON data endpoint. Cookie Forbid redirects to an HTML
|
|
// AccessDenied page; callers need a terminal scope denial instead.
|
|
catch (UnauthorizedAccessException) { return StatusCode(StatusCodes.Status403Forbidden); }
|
|
catch (SqlException e) when (e.Number == 51010) { return StatusCode(StatusCodes.Status403Forbidden); }
|
|
}
|
|
}
|