Skip to content

Commit

Permalink
added requests addon
Browse files Browse the repository at this point in the history
  • Loading branch information
soultaco83 committed Oct 20, 2024
1 parent e2ed63e commit 0386d41
Show file tree
Hide file tree
Showing 7 changed files with 234 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Jellyfin.Api/Helpers/FileStreamResponseHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ public static ActionResult GetStaticFileResult(
string path,
string contentType)
{
return new PhysicalFileResult(path, contentType) { EnableRangeProcessing = true };
FileStream fs = File.OpenRead(path);
return new FileStreamResult(fs, contentType) { EnableRangeProcessing = true };
}

/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions MediaBrowser.Providers/MediaBrowser.Providers.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,7 @@
<EmbeddedResource Include="Plugins\StudioImages\Configuration\config.html" />
<None Remove="Plugins\Tmdb\Configuration\config.html" />
<EmbeddedResource Include="Plugins\Tmdb\Configuration\config.html" />
<None Remove="Plugins\RequestsAddon\Configuration\config.html" />
<EmbeddedResource Include="Plugins\RequestsAddon\Configuration\config.html" />
</ItemGroup>
</Project>
62 changes: 62 additions & 0 deletions MediaBrowser.Providers/Plugins/RequestsAddon/Api/APIController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System;
using System.Net.Mime;
using Jellyfin.Plugin.RequestsAddon.Configuration;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;

namespace Jellyfin.Plugin.RequestsAddon.Api
{
/// <summary>
/// Controller for the RequestsAddon API.
/// </summary>
[ApiController]
[Route("Plugins/RequestsAddon")]
[Produces(MediaTypeNames.Application.Json)]
public class ApiController : ControllerBase
{
private readonly ILogger<ApiController> _logger;
private readonly Plugin _plugin;

/// <summary>
/// Initializes a new instance of the <see cref="ApiController"/> class.
/// </summary>
/// <param name="logger">Instance of the <see cref="ILogger{ApiController}"/> interface.</param>
public ApiController(ILogger<ApiController> logger)
{
_logger = logger;
_plugin = Plugin.Instance!;
}

/// <summary>
/// Get the RequestsUrl.
/// </summary>
/// <response code="200">RequestsUrl retrieved.</response>
/// <response code="500">Internal server error.</response>
/// <returns>The RequestsUrl.</returns>
[HttpGet("PublicRequestsUrl")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
[AllowAnonymous]
public ActionResult<string> GetPublicRequestsUrl()
{
try
{
var requestsUrl = _plugin.Configuration.RequestsUrl;
if (string.IsNullOrEmpty(requestsUrl))
{
_logger.LogWarning("RequestsUrl is null or empty");
return Ok(string.Empty);
}

return Ok(requestsUrl);
}
catch (Exception ex)
{
_logger.LogError(ex, "Error retrieving RequestsUrl");
return StatusCode(500, "An error occurred while retrieving the RequestsUrl");
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using MediaBrowser.Model.Plugins;

namespace Jellyfin.Plugin.RequestsAddon.Configuration;

/// <summary>
/// Plugin configuration.
/// </summary>
public class PluginConfiguration : BasePluginConfiguration
{
/// <summary>
/// Initializes a new instance of the <see cref="PluginConfiguration"/> class.
/// </summary>
public PluginConfiguration()
{
RequestsUrl = "https://www.example.com"; // Set default URL here
}

/// <summary>
/// Gets or sets the Requests URL.
/// </summary>
public string RequestsUrl { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>RequestsAddon</title>
</head>
<body>
<div id="RequestsAddonConfigPage" data-role="page" class="page type-interior pluginConfigurationPage" data-require="emby-input,emby-button,emby-select,emby-checkbox">
<div data-role="content">
<div class="content-primary">
<form id="RequestsAddonConfigForm">
<div class="inputContainer">
<label class="inputLabel inputLabelUnfocused" for="RequestsUrl">Requests URL</label>
<input id="RequestsUrl" name="RequestsUrl" type="text" is="emby-input" />
<div class="fieldDescription">Set the URL for requests tab, supports any site with iFrame support</div>
</div>
<div>
<button is="emby-button" type="submit" class="raised button-submit block emby-button">
<span>Save</span>
</button>
</div>
</form>
</div>
</div>
<script type="text/javascript">
var RequestsAddonConfig = {
pluginUniqueId: 'b0bef419-e5b8-439d-a6a5-9b96949cbe7e'
};

document.querySelector('#RequestsAddonConfigPage')
.addEventListener('pageshow', function() {
Dashboard.showLoadingMsg();
ApiClient.getPluginConfiguration(RequestsAddonConfig.pluginUniqueId).then(function (config) {
document.querySelector('#RequestsUrl').value = config.RequestsUrl || "https://www.example.com";
Dashboard.hideLoadingMsg();
});
});

document.querySelector('#RequestsAddonConfigForm')
.addEventListener('submit', function(e) {
Dashboard.showLoadingMsg();
ApiClient.getPluginConfiguration(RequestsAddonConfig.pluginUniqueId).then(function (config) {
config.RequestsUrl = document.querySelector('#RequestsUrl').value || "https://www.example.com";
ApiClient.updatePluginConfiguration(RequestsAddonConfig.pluginUniqueId, config).then(function (result) {
Dashboard.processPluginConfigurationUpdateResult(result);
});
});

e.preventDefault();
return false;
});
</script>
</div>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Jellyfin.Plugin.RequestsAddon</RootNamespace>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Nullable>enable</Nullable>
<AnalysisMode>AllEnabledByDefault</AnalysisMode>
<CodeAnalysisRuleSet>../jellyfin.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Jellyfin.Controller" Version="10.*" />
<PackageReference Include="Jellyfin.Model" Version="10.*" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="SerilogAnalyzer" Version="0.15.0" PrivateAssets="All" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.507" PrivateAssets="All" />
<PackageReference Include="SmartAnalyzers.MultithreadingAnalyzer" Version="1.1.31" PrivateAssets="All" />
</ItemGroup>

<ItemGroup>
<None Remove="Configuration\configPage.html" />
<EmbeddedResource Include="Configuration\configPage.html" />
</ItemGroup>

</Project>
62 changes: 62 additions & 0 deletions MediaBrowser.Providers/Plugins/RequestsAddon/Plugin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using Jellyfin.Plugin.RequestsAddon.Configuration;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Plugins;
using MediaBrowser.Model.Plugins;
using MediaBrowser.Model.Serialization;
using Microsoft.Extensions.DependencyInjection;

namespace Jellyfin.Plugin.RequestsAddon
{
/// <summary>
/// The main plugin.
/// </summary>
public class Plugin : BasePlugin<PluginConfiguration>, IHasWebPages
{
/// <summary>
/// Initializes a new instance of the <see cref="Plugin"/> class.
/// </summary>
/// <param name="applicationPaths">Instance of the <see cref="IApplicationPaths"/> interface.</param>
/// <param name="xmlSerializer">Instance of the <see cref="IXmlSerializer"/> interface.</param>
public Plugin(IApplicationPaths applicationPaths, IXmlSerializer xmlSerializer)
: base(applicationPaths, xmlSerializer)
{
Instance = this;
}

/// <inheritdoc />
public override string Name => "RequestsAddon";

/// <inheritdoc />
public override Guid Id => Guid.Parse("b0bef419-e5b8-439d-a6a5-9b96949cbe7e");

/// <summary>
/// Gets the current plugin instance.
/// </summary>
public static Plugin? Instance { get; private set; }

/// <inheritdoc />
public IEnumerable<PluginPageInfo> GetPages()
{
return new[]
{
new PluginPageInfo
{
Name = this.Name,
EmbeddedResourcePath = string.Format(CultureInfo.InvariantCulture, "{0}.Configuration.configPage.html", GetType().Namespace)
}
};
}

/// <summary>
/// Registers services for the plugin.
/// </summary>
/// <param name="serviceCollection">The service collection.</param>
public void RegisterServices(IServiceCollection serviceCollection)
{
serviceCollection.AddSingleton(Instance!);
}
}
}

0 comments on commit 0386d41

Please sign in to comment.