summaryrefslogtreecommitdiff
path: root/Api/JCoverStaticProvider.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Api/JCoverStaticProvider.cs')
-rw-r--r--Api/JCoverStaticProvider.cs40
1 files changed, 40 insertions, 0 deletions
diff --git a/Api/JCoverStaticProvider.cs b/Api/JCoverStaticProvider.cs
new file mode 100644
index 0000000..e4587ba
--- /dev/null
+++ b/Api/JCoverStaticProvider.cs
@@ -0,0 +1,40 @@
+using Microsoft.Extensions.Logging;
+
+namespace Jellyfin.Plugin.JCoverXtremePro.Api;
+
+using System.Reflection;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+
+/// <summary>
+/// Static file server for the JavaScript snippet injected by <see cref="ScriptInjector"/>
+/// </summary>
+[ApiController]
+[Route("JCoverXtremeProStatic")]
+public class JCoverStaticProvider : ControllerBase
+{
+ private readonly Assembly assembly;
+ private readonly string scriptPath;
+
+ public JCoverStaticProvider()
+ {
+ assembly = Assembly.GetExecutingAssembly();
+ scriptPath = GetType().Namespace + ".coverscript.js";
+ }
+
+ [HttpGet("ClientScript")]
+ [ProducesResponseType(StatusCodes.Status200OK)]
+ [ProducesResponseType(StatusCodes.Status404NotFound)]
+ [Produces("application/javascript")]
+ public ActionResult GetClientScript()
+ {
+ Plugin.Logger.LogInformation($"Requesting ClientScript {scriptPath}");
+ var scriptStream = assembly.GetManifestResourceStream(scriptPath);
+ if (scriptStream == null)
+ {
+ return NotFound();
+ }
+
+ return File(scriptStream, "application/javascript");
+ }
+} \ No newline at end of file