You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
jellyfin/MediaBrowser.Api/Plugin.cs

113 lines
4.0 KiB

12 years ago
using System;
using System.ComponentModel.Composition;
using System.Net;
12 years ago
using System.Reactive.Linq;
using MediaBrowser.Api.HttpHandlers;
using MediaBrowser.Common.Net.Handlers;
12 years ago
using MediaBrowser.Common.Plugins;
using MediaBrowser.Controller;
using MediaBrowser.Model.Plugins;
12 years ago
namespace MediaBrowser.Api
{
[Export(typeof(BasePlugin))]
public class Plugin : BaseGenericPlugin<BasePluginConfiguration>
12 years ago
{
public override string Name
{
get { return "WebAPI"; }
}
public override void Init()
12 years ago
{
var httpServer = Kernel.Instance.HttpServer;
12 years ago
httpServer.Where(ctx => ctx.Request.Url.LocalPath.IndexOf("/api/", StringComparison.OrdinalIgnoreCase) != -1).Subscribe((ctx) =>
{
BaseHandler handler = GetHandler(ctx);
if (handler != null)
{
handler.ProcessRequest(ctx);
}
});
}
12 years ago
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();
}
else if (localPath.EndsWith("/api/users", StringComparison.OrdinalIgnoreCase))
{
return new UsersHandler();
}
else if (localPath.EndsWith("/api/itemlist", StringComparison.OrdinalIgnoreCase))
{
return new ItemListHandler();
}
else if (localPath.EndsWith("/api/genres", StringComparison.OrdinalIgnoreCase))
{
return new GenresHandler();
}
else if (localPath.EndsWith("/api/years", StringComparison.OrdinalIgnoreCase))
{
return new YearsHandler();
}
else if (localPath.EndsWith("/api/studios", StringComparison.OrdinalIgnoreCase))
{
return new StudiosHandler();
}
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();
}
else if (localPath.EndsWith("/api/audio", StringComparison.OrdinalIgnoreCase))
{
return new AudioHandler();
}
else if (localPath.EndsWith("/api/video", StringComparison.OrdinalIgnoreCase))
{
return new VideoHandler();
}
else if (localPath.EndsWith("/api/person", StringComparison.OrdinalIgnoreCase))
{
return new PersonHandler();
}
else if (localPath.EndsWith("/api/genre", StringComparison.OrdinalIgnoreCase))
{
return new GenreHandler();
}
else if (localPath.EndsWith("/api/year", StringComparison.OrdinalIgnoreCase))
{
return new YearHandler();
}
else if (localPath.EndsWith("/api/studio", StringComparison.OrdinalIgnoreCase))
{
return new StudioHandler();
}
else if (localPath.EndsWith("/api/weather", StringComparison.OrdinalIgnoreCase))
{
return new WeatherHandler();
}
return null;
12 years ago
}
}
}