jellyfin-server/MediaBrowser.Api/Plugin.cs

117 lines
4.3 KiB
C#
Raw Normal View History

2012-07-12 06:55:27 +00:00
using System;
using System.ComponentModel.Composition;
using System.Net;
2012-07-12 06:55:27 +00:00
using System.Reactive.Linq;
using MediaBrowser.Api.HttpHandlers;
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 Init()
2012-07-12 06:55:27 +00:00
{
var httpServer = Kernel.Instance.HttpServer;
2012-07-12 06:55:27 +00:00
2012-08-16 02:42:45 +00:00
httpServer.Where(ctx => ctx.Request.Url.LocalPath.IndexOf("/api/", StringComparison.OrdinalIgnoreCase) != -1).Subscribe(async (ctx) =>
{
BaseHandler handler = GetHandler(ctx);
if (handler != null)
{
2012-08-16 02:42:45 +00:00
await handler.ProcessRequest(ctx);
}
});
}
2012-07-12 06:55:27 +00:00
private BaseHandler GetHandler(HttpListenerContext ctx)
{
string localPath = ctx.Request.Url.LocalPath;
if (localPath.EndsWith("/api/item", StringComparison.OrdinalIgnoreCase))
{
return new ItemHandler();
}
else if (localPath.EndsWith("/api/image", StringComparison.OrdinalIgnoreCase))
{
return new ImageHandler();
2012-08-10 13:18:30 +00:00
}
else if (localPath.EndsWith("/api/users", StringComparison.OrdinalIgnoreCase))
{
return new UsersHandler();
}
else if (localPath.EndsWith("/api/itemswithgenre", StringComparison.OrdinalIgnoreCase))
{
return new ItemsWithGenreHandler();
}
else if (localPath.EndsWith("/api/genres", StringComparison.OrdinalIgnoreCase))
{
return new GenresHandler();
}
else if (localPath.EndsWith("/api/itemswithyear", StringComparison.OrdinalIgnoreCase))
{
return new ItemsWithYearHandler();
}
2012-08-14 19:06:25 +00:00
else if (localPath.EndsWith("/api/itemswithperson", StringComparison.OrdinalIgnoreCase))
{
return new ItemsWithPersonHandler();
}
else if (localPath.EndsWith("/api/years", StringComparison.OrdinalIgnoreCase))
{
return new YearsHandler();
}
else if (localPath.EndsWith("/api/itemswithstudio", StringComparison.OrdinalIgnoreCase))
{
return new ItemsWithStudioHandler();
}
else if (localPath.EndsWith("/api/studios", StringComparison.OrdinalIgnoreCase))
{
return new StudiosHandler();
}
else if (localPath.EndsWith("/api/recentlyaddeditems", StringComparison.OrdinalIgnoreCase))
{
return new RecentlyAddedItemsHandler();
}
else if (localPath.EndsWith("/api/inprogressitems", StringComparison.OrdinalIgnoreCase))
{
return new InProgressItemsHandler();
}
else if (localPath.EndsWith("/api/userconfiguration", StringComparison.OrdinalIgnoreCase))
{
return new UserConfigurationHandler();
}
else if (localPath.EndsWith("/api/plugins", StringComparison.OrdinalIgnoreCase))
{
return new PluginsHandler();
}
else if (localPath.EndsWith("/api/pluginconfiguration", StringComparison.OrdinalIgnoreCase))
{
return new PluginConfigurationHandler();
}
else if (localPath.EndsWith("/api/static", StringComparison.OrdinalIgnoreCase))
{
return new StaticFileHandler();
}
2012-08-10 13:18:30 +00:00
else if (localPath.EndsWith("/api/audio", StringComparison.OrdinalIgnoreCase))
{
return new AudioHandler();
}
else if (localPath.EndsWith("/api/video", StringComparison.OrdinalIgnoreCase))
{
return new VideoHandler();
}
return null;
2012-07-12 06:55:27 +00:00
}
}
}