2012-07-12 08:55:27 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Reactive.Linq;
|
2012-07-13 05:50:50 +02:00
|
|
|
|
using MediaBrowser.Api.HttpHandlers;
|
2012-07-12 08:55:27 +02:00
|
|
|
|
using MediaBrowser.Common.Plugins;
|
|
|
|
|
using MediaBrowser.Controller;
|
2012-07-20 04:22:44 +02:00
|
|
|
|
using MediaBrowser.Net;
|
|
|
|
|
using MediaBrowser.Net.Handlers;
|
2012-07-12 08:55:27 +02:00
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Api
|
|
|
|
|
{
|
|
|
|
|
public class Plugin : BasePlugin<BasePluginConfiguration>
|
|
|
|
|
{
|
|
|
|
|
protected override void InitInternal()
|
|
|
|
|
{
|
2012-07-13 05:50:50 +02:00
|
|
|
|
var httpServer = Kernel.Instance.HttpServer;
|
2012-07-12 08:55:27 +02:00
|
|
|
|
|
2012-07-20 04:22:44 +02:00
|
|
|
|
httpServer.Where(ctx => ctx.LocalPath.IndexOf("/api/", StringComparison.OrdinalIgnoreCase) != -1).Subscribe(ctx =>
|
|
|
|
|
{
|
|
|
|
|
BaseHandler handler = GetHandler(ctx);
|
2012-07-16 18:50:44 +02:00
|
|
|
|
|
2012-07-20 04:22:44 +02:00
|
|
|
|
if (handler != null)
|
|
|
|
|
{
|
|
|
|
|
ctx.Respond(handler);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2012-07-12 08:55:27 +02:00
|
|
|
|
|
2012-07-20 04:22:44 +02:00
|
|
|
|
private BaseHandler GetHandler(RequestContext ctx)
|
|
|
|
|
{
|
|
|
|
|
BaseHandler handler = null;
|
2012-07-12 08:55:27 +02:00
|
|
|
|
|
2012-07-20 04:22:44 +02:00
|
|
|
|
string localPath = ctx.LocalPath;
|
2012-07-16 18:50:44 +02:00
|
|
|
|
|
2012-07-20 04:22:44 +02:00
|
|
|
|
if (localPath.EndsWith("/api/item", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
handler = new ItemHandler();
|
|
|
|
|
}
|
|
|
|
|
else if (localPath.EndsWith("/api/image", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
handler = new ImageHandler();
|
|
|
|
|
}
|
|
|
|
|
else if (localPath.EndsWith("/api/users", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
handler = new UsersHandler();
|
|
|
|
|
}
|
|
|
|
|
else if (localPath.EndsWith("/api/media", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
handler = new MediaHandler();
|
|
|
|
|
}
|
|
|
|
|
else if (localPath.EndsWith("/api/genre", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
handler = new GenreHandler();
|
|
|
|
|
}
|
|
|
|
|
else if (localPath.EndsWith("/api/genres", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
handler = new GenresHandler();
|
|
|
|
|
}
|
|
|
|
|
else if (localPath.EndsWith("/api/studio", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
handler = new StudioHandler();
|
|
|
|
|
}
|
|
|
|
|
else if (localPath.EndsWith("/api/studios", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
handler = new StudiosHandler();
|
|
|
|
|
}
|
|
|
|
|
else if (localPath.EndsWith("/api/recentlyaddeditems", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
handler = new RecentlyAddedItemsHandler();
|
|
|
|
|
}
|
|
|
|
|
else if (localPath.EndsWith("/api/inprogressitems", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
handler = new InProgressItemsHandler();
|
|
|
|
|
}
|
2012-07-16 18:50:44 +02:00
|
|
|
|
|
2012-07-20 04:22:44 +02:00
|
|
|
|
if (handler != null)
|
|
|
|
|
{
|
|
|
|
|
handler.RequestContext = ctx;
|
|
|
|
|
}
|
2012-07-14 22:45:11 +02:00
|
|
|
|
|
2012-07-20 04:22:44 +02:00
|
|
|
|
return handler;
|
2012-07-12 08:55:27 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|