Skip to content

Commit

Permalink
Fix MetadataViewer - again
Browse files Browse the repository at this point in the history
  • Loading branch information
softworkz committed Nov 24, 2016
1 parent 8978d94 commit b5d85e3
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 51 deletions.
78 changes: 78 additions & 0 deletions MetadataViewer/Html/StaticFileServer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Net;
using MediaBrowser.Model.Logging;
using MetadataViewer.DTO;
using MetadataViewer.Service;
using System.Threading;
using MediaBrowser.Model.Services;
using System.IO;
using System;
using System.Threading.Tasks;
using MediaBrowser.Model.Net;

namespace MetadataViewer.Html
{
[Route("/web/components/metadataviewer/metadataviewer.js", "GET")]
[Route("/web/components/metadataviewer/metadataviewer.template.html", "GET")]
[Route("/web/bower_components/emby-webcomponents/itemcontextmenu.js", "GET")]
public class GetStaticResource
{
}

public class StaticFileServer : IService, IRequiresRequest
{
private readonly ILogger _logger;

/// <summary>
/// Gets or sets the HTTP result factory.
/// </summary>
/// <value>The HTTP result factory.</value>
private readonly IHttpResultFactory _resultFactory;

/// <summary>
/// Gets or sets the request context.
/// </summary>
/// <value>The request context.</value>
public IRequest Request { get; set; }

public StaticFileServer(ILogManager logManager, IHttpResultFactory resultFactory)
{
_logger = logManager.GetLogger(GetType().Name);
_resultFactory = resultFactory;
}

/// <summary>
/// Gets the specified request.
/// </summary>
/// <param name="request">The request.</param>
/// <returns>System.Object.</returns>
public async Task<object> Get(GetStaticResource request)
{
var path = Request.PathInfo;

var contentType = MimeTypes.GetMimeType(path);

MemoryStream resultStream = null;

if (path.Contains("/components/metadataviewer/metadataviewer.js"))
{
resultStream = HtmlHelper.ViewerScript;
}
else if (path.Contains("/components/metadataviewer/metadataviewer.template.html"))
{
resultStream = HtmlHelper.ViewerTemplate;
}
else if (path.Contains("/bower_components/emby-webcomponents/itemcontextmenu.js"))
{
resultStream = HtmlHelper.ModifiedContextMenu;
}

if (resultStream != null)
{
resultStream = new MemoryStream(resultStream.GetBuffer());
}

return _resultFactory.GetResult(resultStream, contentType);
}
}
}
2 changes: 1 addition & 1 deletion MetadataViewer/Html/metadataviewer.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ <h2>Lookup Criteria:</h2>
<tr>
<td style="width: 7em; vertical-align: top;"><label for="selectLanguage" class="selectLabel">Language:</label></td>
<td>
<select id="selectLanguage" style="max-width: 20em; color: #fff !important;">
<select id="selectLanguage" style="max-width: 20em;">
<option value=""></option>
<option value="en">English</option>
<option value="de">German</option>
Expand Down
1 change: 1 addition & 0 deletions MetadataViewer/MetadataViewer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
<Compile Include="DTO\MetadataRawTable.cs" />
<Compile Include="DTO\MetadataResultProxy.cs" />
<Compile Include="HtmlHelper.cs" />
<Compile Include="Html\StaticFileServer.cs" />
<Compile Include="Plugin.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ServerEntryPoint.cs" />
Expand Down
10 changes: 8 additions & 2 deletions MetadataViewer/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ public class Plugin : BasePlugin<PluginConfiguration>
public Plugin(IApplicationPaths appPaths, IXmlSerializer xmlSerializer)
: base(appPaths, xmlSerializer)
{
//_logger.Info("[MetadataViewer] ServerEntryPoint");

Instance = this;
_appPaths = appPaths;
HtmlHelper.InstallFiles(_appPaths, PluginConfiguration);
}

public override string Name
Expand Down Expand Up @@ -42,7 +43,12 @@ public override void OnUninstalling()
}

public static Plugin Instance { get; private set; }


public IApplicationPaths AppPaths
{
get { return _appPaths; }
}

public PluginConfiguration PluginConfiguration
{
get { return Configuration; }
Expand Down
4 changes: 2 additions & 2 deletions MetadataViewer/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("MetadataViewer Beta 13")]
[assembly: AssemblyDescription("Beta 13")]
[assembly: AssemblyTitle("MetadataViewer Beta 14")]
[assembly: AssemblyDescription("Beta 14")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MetadataViewer")]
Expand Down
58 changes: 12 additions & 46 deletions MetadataViewer/ServerEntryPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
using MetadataViewer.Api;
using MetadataViewer.Service;
using System.IO;
using System.Web;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Services;
using MetadataViewer.Html;

namespace Trakt
{
Expand All @@ -23,10 +23,11 @@ public class ServerEntryPoint : IServerEntryPoint
private readonly ILogger _logger;
private readonly IServerApplicationHost _appHost;
private readonly IFileSystem _fileSystem;
private readonly IHttpServer _httpServer;
private readonly IServerConfigurationManager _configurationManager;
private readonly IHttpResultFactory _resultFactory;
private MetadataViewerApi _api;
private MetadataViewerService _service;
private StaticFileServer _staticFileServer;

public static ServerEntryPoint Instance { get; private set; }

Expand All @@ -41,21 +42,25 @@ public class ServerEntryPoint : IServerEntryPoint
/// <param name="httpClient"></param>
/// <param name="appHost"></param>
/// <param name="fileSystem"></param>
public ServerEntryPoint(IServerConfigurationManager configurationManager, ILibraryManager libraryManager, ILogManager logger, IServerApplicationHost appHost, IHttpServer httpServer, IFileSystem fileSystem)
public ServerEntryPoint(IServerConfigurationManager configurationManager, ILibraryManager libraryManager, ILogManager logger, IServerApplicationHost appHost, IHttpResultFactory resultFactory, IFileSystem fileSystem)
{
_logger = logger.GetLogger("MetadataViewer");
_logger.Info("[MetadataViewer] ServerEntryPoint");

Instance = this;
_libraryManager = libraryManager;
_logger = logger.GetLogger("MetadataViewer");
_appHost = appHost;
_fileSystem = fileSystem;
_configurationManager = configurationManager;
_httpServer = httpServer;
_resultFactory = resultFactory;

var serviceStackHost = (IAppHost)httpServer;
serviceStackHost.RawHttpHandlers.Add(ProcessRequestRaw);
HtmlHelper.InstallFiles(Plugin.Instance.AppPaths, Plugin.Instance.PluginConfiguration);

_service = new MetadataViewerService(_configurationManager, logger, _fileSystem, _appHost);
_api = new MetadataViewerApi(logger, _service, _libraryManager);
_staticFileServer = new StaticFileServer(logger, _resultFactory);

_logger.Info("[MetadataViewer] ServerEntryPoint Exit");
}

/// <summary>
Expand All @@ -71,44 +76,5 @@ public void Run()
public void Dispose()
{
}

public virtual HttpAsyncTaskHandler ProcessRequestRaw(IHttpRequest request)
{
MemoryStream resultStream = null;

if (request.PathInfo.Contains("/components/metadataviewer/metadataviewer.js"))
{
resultStream = HtmlHelper.ViewerScript;
}
else if (request.PathInfo.Contains("/components/metadataviewer/metadataviewer.template.html"))
{
resultStream = HtmlHelper.ViewerTemplate;
}
else if (request.PathInfo.Contains("/bower_components/emby-webcomponents/itemcontextmenu.js"))
{
resultStream = HtmlHelper.ModifiedContextMenu;
}

if (resultStream != null)
{
var handler = new CustomActionHandler((httpReq, httpRes) =>
{
httpRes.ContentType = "text/html";

lock (resultStream)
{
resultStream.Seek(0, SeekOrigin.Begin);
resultStream.WriteTo(httpRes.OutputStream);
httpRes.EndRequest();
}

httpRes.End();
});

return handler;
}

return null;
}
}
}

0 comments on commit b5d85e3

Please sign in to comment.