jellyfin-server/MediaBrowser.Api/Plugin.cs

134 lines
4.2 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
{
2012-09-04 17:43:09 +00:00
get { return "Media Browser API"; }
}
protected override void InitializeOnServer()
2012-07-12 06:55:27 +00:00
{
var httpServer = Kernel.Instance.HttpServer;
2012-07-12 06:55:27 +00:00
2012-08-22 02:50:59 +00:00
httpServer.Where(ctx => ctx.Request.Url.LocalPath.IndexOf("/api/", StringComparison.OrdinalIgnoreCase) != -1).Subscribe((ctx) =>
{
BaseHandler handler = GetHandler(ctx);
if (handler != null)
{
2012-08-22 02:50:59 +00:00
handler.ProcessRequest(ctx);
}
});
}
2012-07-12 06:55:27 +00:00
private BaseHandler GetHandler(HttpListenerContext ctx)
{
string localPath = ctx.Request.Url.LocalPath;
2012-09-04 17:43:09 +00:00
if (IsUrlMatch("/api/item", localPath))
{
return new ItemHandler();
}
2012-09-04 17:43:09 +00:00
else if (IsUrlMatch("/api/image", localPath))
{
return new ImageHandler();
2012-08-10 13:18:30 +00:00
}
2012-09-04 17:43:09 +00:00
else if (IsUrlMatch("/api/users", localPath))
{
return new UsersHandler();
}
2012-09-04 17:43:09 +00:00
else if (IsUrlMatch("/api/itemlist", localPath))
{
return new ItemListHandler();
}
2012-09-04 17:43:09 +00:00
else if (IsUrlMatch("/api/genres", localPath))
{
return new GenresHandler();
}
2012-09-04 17:43:09 +00:00
else if (IsUrlMatch("/api/years", localPath))
{
return new YearsHandler();
}
2012-09-04 17:43:09 +00:00
else if (IsUrlMatch("/api/studios", localPath))
{
return new StudiosHandler();
}
2012-09-04 17:43:09 +00:00
else if (IsUrlMatch("/api/plugins", localPath))
{
return new PluginsHandler();
}
2012-09-04 17:43:09 +00:00
else if (IsUrlMatch("/api/pluginconfiguration", localPath))
{
return new PluginConfigurationHandler();
}
2012-09-04 17:43:09 +00:00
else if (IsUrlMatch("/api/static", localPath))
{
return new StaticFileHandler();
}
2012-09-04 17:43:09 +00:00
else if (IsUrlMatch("/api/audio", localPath))
2012-08-10 13:18:30 +00:00
{
return new AudioHandler();
}
2012-09-04 17:43:09 +00:00
else if (IsUrlMatch("/api/video", localPath))
{
return new VideoHandler();
}
2012-09-04 17:43:09 +00:00
else if (IsUrlMatch("/api/person", localPath))
2012-08-18 16:27:34 +00:00
{
return new PersonHandler();
}
2012-09-04 17:43:09 +00:00
else if (IsUrlMatch("/api/genre", localPath))
2012-08-18 16:27:34 +00:00
{
return new GenreHandler();
}
2012-09-04 17:43:09 +00:00
else if (IsUrlMatch("/api/year", localPath))
2012-08-18 16:27:34 +00:00
{
return new YearHandler();
}
2012-09-04 17:43:09 +00:00
else if (IsUrlMatch("/api/studio", localPath))
2012-08-18 16:27:34 +00:00
{
return new StudioHandler();
}
2012-09-04 17:43:09 +00:00
else if (IsUrlMatch("/api/weather", localPath))
2012-09-02 05:30:25 +00:00
{
return new WeatherHandler();
}
2012-09-04 17:43:09 +00:00
else if (IsUrlMatch("/api/serverconfiguration", localPath))
{
return new ServerConfigurationHandler();
}
2012-09-04 17:43:09 +00:00
else if (IsUrlMatch("/api/defaultuser", localPath))
2012-09-02 14:56:36 +00:00
{
return new DefaultUserHandler();
}
2012-09-04 17:43:09 +00:00
else if (IsUrlMatch("/api/pluginassembly", localPath))
2012-09-03 19:12:02 +00:00
{
return new PluginAssemblyHandler();
}
2012-09-06 18:38:29 +00:00
else if (IsUrlMatch("/api/UserAuthentication", localPath))
{
return new UserAuthenticationHandler();
}
return null;
2012-07-12 06:55:27 +00:00
}
2012-09-04 17:43:09 +00:00
private bool IsUrlMatch(string url, string localPath)
{
return localPath.EndsWith(url, StringComparison.OrdinalIgnoreCase);
}
2012-07-12 06:55:27 +00:00
}
}