2012-07-12 08:55:27 +02:00
|
|
|
|
using System;
|
2012-07-26 04:33:11 +02:00
|
|
|
|
using System.ComponentModel.Composition;
|
2012-08-10 15:07:58 +02:00
|
|
|
|
using System.Net;
|
2012-07-12 08:55:27 +02:00
|
|
|
|
using System.Reactive.Linq;
|
2012-07-13 05:50:50 +02:00
|
|
|
|
using MediaBrowser.Api.HttpHandlers;
|
2012-07-21 20:39:47 +02:00
|
|
|
|
using MediaBrowser.Common.Net.Handlers;
|
2012-07-12 08:55:27 +02:00
|
|
|
|
using MediaBrowser.Common.Plugins;
|
|
|
|
|
using MediaBrowser.Controller;
|
2012-07-24 16:54:34 +02:00
|
|
|
|
using MediaBrowser.Model.Plugins;
|
2012-07-12 08:55:27 +02:00
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Api
|
|
|
|
|
{
|
2012-07-26 04:33:11 +02:00
|
|
|
|
[Export(typeof(BasePlugin))]
|
2012-07-24 16:54:34 +02:00
|
|
|
|
public class Plugin : BaseGenericPlugin<BasePluginConfiguration>
|
2012-07-12 08:55:27 +02:00
|
|
|
|
{
|
2012-07-24 16:54:34 +02:00
|
|
|
|
public override string Name
|
|
|
|
|
{
|
|
|
|
|
get { return "WebAPI"; }
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-29 17:19:25 +02:00
|
|
|
|
public override void Init()
|
2012-07-12 08:55:27 +02:00
|
|
|
|
{
|
2012-07-13 05:50:50 +02:00
|
|
|
|
var httpServer = Kernel.Instance.HttpServer;
|
2012-07-12 08:55:27 +02:00
|
|
|
|
|
2012-08-16 04:42:45 +02:00
|
|
|
|
httpServer.Where(ctx => ctx.Request.Url.LocalPath.IndexOf("/api/", StringComparison.OrdinalIgnoreCase) != -1).Subscribe(async (ctx) =>
|
2012-07-20 04:22:44 +02:00
|
|
|
|
{
|
|
|
|
|
BaseHandler handler = GetHandler(ctx);
|
2012-07-16 18:50:44 +02:00
|
|
|
|
|
2012-07-20 04:22:44 +02:00
|
|
|
|
if (handler != null)
|
|
|
|
|
{
|
2012-08-16 04:42:45 +02:00
|
|
|
|
await handler.ProcessRequest(ctx);
|
2012-07-20 04:22:44 +02:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2012-07-12 08:55:27 +02:00
|
|
|
|
|
2012-08-10 15:07:58 +02:00
|
|
|
|
private BaseHandler GetHandler(HttpListenerContext ctx)
|
2012-07-20 04:22:44 +02:00
|
|
|
|
{
|
2012-08-10 15:07:58 +02:00
|
|
|
|
string localPath = ctx.Request.Url.LocalPath;
|
2012-07-16 18:50:44 +02:00
|
|
|
|
|
2012-07-20 04:22:44 +02:00
|
|
|
|
if (localPath.EndsWith("/api/item", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2012-08-10 15:07:58 +02:00
|
|
|
|
return new ItemHandler();
|
2012-07-20 04:22:44 +02:00
|
|
|
|
}
|
|
|
|
|
else if (localPath.EndsWith("/api/image", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2012-08-10 15:07:58 +02:00
|
|
|
|
return new ImageHandler();
|
2012-08-10 15:18:30 +02:00
|
|
|
|
}
|
2012-07-20 04:22:44 +02:00
|
|
|
|
else if (localPath.EndsWith("/api/users", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2012-08-10 15:07:58 +02:00
|
|
|
|
return new UsersHandler();
|
2012-07-20 04:22:44 +02:00
|
|
|
|
}
|
2012-08-17 18:47:35 +02:00
|
|
|
|
else if (localPath.EndsWith("/api/itemlist", StringComparison.OrdinalIgnoreCase))
|
2012-07-20 04:22:44 +02:00
|
|
|
|
{
|
2012-08-17 18:47:35 +02:00
|
|
|
|
return new ItemListHandler();
|
2012-07-20 04:22:44 +02:00
|
|
|
|
}
|
|
|
|
|
else if (localPath.EndsWith("/api/genres", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2012-08-10 15:07:58 +02:00
|
|
|
|
return new GenresHandler();
|
2012-07-20 04:22:44 +02:00
|
|
|
|
}
|
2012-08-14 18:06:46 +02:00
|
|
|
|
else if (localPath.EndsWith("/api/years", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
return new YearsHandler();
|
|
|
|
|
}
|
2012-07-20 04:22:44 +02:00
|
|
|
|
else if (localPath.EndsWith("/api/studios", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2012-08-10 15:07:58 +02:00
|
|
|
|
return new StudiosHandler();
|
2012-07-20 04:22:44 +02:00
|
|
|
|
}
|
2012-07-24 16:54:34 +02:00
|
|
|
|
else if (localPath.EndsWith("/api/plugins", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2012-08-10 15:07:58 +02:00
|
|
|
|
return new PluginsHandler();
|
2012-07-24 16:54:34 +02:00
|
|
|
|
}
|
|
|
|
|
else if (localPath.EndsWith("/api/pluginconfiguration", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2012-08-10 15:07:58 +02:00
|
|
|
|
return new PluginConfigurationHandler();
|
2012-07-24 16:54:34 +02:00
|
|
|
|
}
|
2012-08-10 15:07:58 +02:00
|
|
|
|
else if (localPath.EndsWith("/api/static", StringComparison.OrdinalIgnoreCase))
|
2012-07-20 04:22:44 +02:00
|
|
|
|
{
|
2012-08-10 15:07:58 +02:00
|
|
|
|
return new StaticFileHandler();
|
2012-07-20 04:22:44 +02:00
|
|
|
|
}
|
2012-08-10 15:18:30 +02:00
|
|
|
|
else if (localPath.EndsWith("/api/audio", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
return new AudioHandler();
|
|
|
|
|
}
|
2012-08-11 20:07:07 +02:00
|
|
|
|
else if (localPath.EndsWith("/api/video", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
return new VideoHandler();
|
|
|
|
|
}
|
2012-07-14 22:45:11 +02:00
|
|
|
|
|
2012-08-10 15:07:58 +02:00
|
|
|
|
return null;
|
2012-07-12 08:55:27 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|