forked from jellyfin/jellyfin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e2ed63e
commit 0386d41
Showing
7 changed files
with
234 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
MediaBrowser.Providers/Plugins/RequestsAddon/Api/APIController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
MediaBrowser.Providers/Plugins/RequestsAddon/Configuration/PluginConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} |
55 changes: 55 additions & 0 deletions
55
MediaBrowser.Providers/Plugins/RequestsAddon/Configuration/configPage.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
29 changes: 29 additions & 0 deletions
29
MediaBrowser.Providers/Plugins/RequestsAddon/Jellyfin.Plugin.RequestsAddon.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!); | ||
} | ||
} | ||
} |