jellyfin-server/MediaBrowser.Api/Plugin.cs

100 lines
3.4 KiB
C#
Raw Normal View History

2012-07-12 06:55:27 +00:00
using System;
using System.ComponentModel.Composition;
2012-07-12 06:55:27 +00:00
using System.Reactive.Linq;
using MediaBrowser.Api.HttpHandlers;
using MediaBrowser.Common.Net;
using MediaBrowser.Common.Net.Handlers;
2012-07-12 06:55:27 +00:00
using MediaBrowser.Common.Plugins;
using MediaBrowser.Controller;
using MediaBrowser.Model.Plugins;
2012-07-12 06:55:27 +00:00
namespace MediaBrowser.Api
{
[Export(typeof(BasePlugin))]
public class Plugin : BaseGenericPlugin<BasePluginConfiguration>
2012-07-12 06:55:27 +00:00
{
public override string Name
{
get { return "WebAPI"; }
}
public override void InitInServer()
2012-07-12 06:55:27 +00:00
{
var httpServer = Kernel.Instance.HttpServer;
2012-07-12 06:55:27 +00:00
httpServer.Where(ctx => ctx.LocalPath.IndexOf("/api/", StringComparison.OrdinalIgnoreCase) != -1).Subscribe(ctx =>
{
BaseHandler handler = GetHandler(ctx);
if (handler != null)
{
ctx.Respond(handler);
}
});
}
2012-07-12 06:55:27 +00:00
private BaseHandler GetHandler(RequestContext ctx)
{
BaseHandler handler = null;
2012-07-12 06:55:27 +00:00
string localPath = ctx.LocalPath;
if (localPath.EndsWith("/api/item", StringComparison.OrdinalIgnoreCase))
{
handler = new ItemHandler();
}
else if (localPath.EndsWith("/api/image", StringComparison.OrdinalIgnoreCase))
{
handler = new ImageHandler();
}
else if (localPath.EndsWith("/api/users", StringComparison.OrdinalIgnoreCase))
{
handler = new UsersHandler();
}
else if (localPath.EndsWith("/api/genre", StringComparison.OrdinalIgnoreCase))
{
handler = new GenreHandler();
}
else if (localPath.EndsWith("/api/genres", StringComparison.OrdinalIgnoreCase))
{
handler = new GenresHandler();
}
else if (localPath.EndsWith("/api/studio", StringComparison.OrdinalIgnoreCase))
{
handler = new StudioHandler();
}
else if (localPath.EndsWith("/api/studios", StringComparison.OrdinalIgnoreCase))
{
handler = new StudiosHandler();
}
else if (localPath.EndsWith("/api/recentlyaddeditems", StringComparison.OrdinalIgnoreCase))
{
handler = new RecentlyAddedItemsHandler();
}
else if (localPath.EndsWith("/api/inprogressitems", StringComparison.OrdinalIgnoreCase))
{
handler = new InProgressItemsHandler();
}
else if (localPath.EndsWith("/api/userconfiguration", StringComparison.OrdinalIgnoreCase))
{
handler = new UserConfigurationHandler();
}
else if (localPath.EndsWith("/api/plugins", StringComparison.OrdinalIgnoreCase))
{
handler = new PluginsHandler();
}
else if (localPath.EndsWith("/api/pluginconfiguration", StringComparison.OrdinalIgnoreCase))
{
handler = new PluginConfigurationHandler();
}
if (handler != null)
{
handler.RequestContext = ctx;
}
return handler;
2012-07-12 06:55:27 +00:00
}
}
}