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

130 lines
4.1 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 "Media Browser API"; }
}
protected override void InitializeOnServer()
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 (IsUrlMatch("/api/item", localPath))
{
return new ItemHandler();
}
else if (IsUrlMatch("/api/image", localPath))
{
return new ImageHandler();
}
else if (IsUrlMatch("/api/users", localPath))
{
return new UsersHandler();
}
else if (IsUrlMatch("/api/itemlist", localPath))
{
return new ItemListHandler();
}
else if (IsUrlMatch("/api/genres", localPath))
{
return new GenresHandler();
}
else if (IsUrlMatch("/api/years", localPath))
{
return new YearsHandler();
}
else if (IsUrlMatch("/api/studios", localPath))
{
return new StudiosHandler();
}
else if (IsUrlMatch("/api/plugins", localPath))
{
return new PluginsHandler();
}
else if (IsUrlMatch("/api/pluginconfiguration", localPath))
{
return new PluginConfigurationHandler();
}
else if (IsUrlMatch("/api/static", localPath))
{
return new StaticFileHandler();
}
else if (IsUrlMatch("/api/audio", localPath))
{
return new AudioHandler();
}
else if (IsUrlMatch("/api/video", localPath))
{
return new VideoHandler();
}
else if (IsUrlMatch("/api/person", localPath))
{
return new PersonHandler();
}
else if (IsUrlMatch("/api/genre", localPath))
{
return new GenreHandler();
}
else if (IsUrlMatch("/api/year", localPath))
{
return new YearHandler();
}
else if (IsUrlMatch("/api/studio", localPath))
{
return new StudioHandler();
}
else if (IsUrlMatch("/api/weather", localPath))
{
return new WeatherHandler();
}
else if (IsUrlMatch("/api/serverconfiguration", localPath))
{
return new ServerConfigurationHandler();
}
else if (IsUrlMatch("/api/defaultuser", localPath))
{
return new DefaultUserHandler();
}
else if (IsUrlMatch("/api/pluginassembly", localPath))
{
return new PluginAssemblyHandler();
}
return null;
12 years ago
}
private bool IsUrlMatch(string url, string localPath)
{
return localPath.EndsWith(url, StringComparison.OrdinalIgnoreCase);
}
12 years ago
}
}