summaryrefslogtreecommitdiff
path: root/Api/JCoverStaticProvider.cs
blob: e4587ba13b16d00cbc857494fbab92ac7ea47cfb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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");
    }
}