Plugin.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. using System;
  2. using System.ComponentModel.Composition;
  3. using System.Reactive.Linq;
  4. using MediaBrowser.Api.HttpHandlers;
  5. using MediaBrowser.Common.Net;
  6. using MediaBrowser.Common.Net.Handlers;
  7. using MediaBrowser.Common.Plugins;
  8. using MediaBrowser.Controller;
  9. using MediaBrowser.Model.Plugins;
  10. namespace MediaBrowser.Api
  11. {
  12. [Export(typeof(BasePlugin))]
  13. public class Plugin : BaseGenericPlugin<BasePluginConfiguration>
  14. {
  15. public override string Name
  16. {
  17. get { return "WebAPI"; }
  18. }
  19. public override void Init()
  20. {
  21. var httpServer = Kernel.Instance.HttpServer;
  22. httpServer.Where(ctx => ctx.LocalPath.IndexOf("/api/", StringComparison.OrdinalIgnoreCase) != -1).Subscribe(ctx =>
  23. {
  24. BaseHandler handler = GetHandler(ctx);
  25. if (handler != null)
  26. {
  27. ctx.Respond(handler);
  28. }
  29. });
  30. }
  31. private BaseHandler GetHandler(RequestContext ctx)
  32. {
  33. BaseHandler handler = null;
  34. string localPath = ctx.LocalPath;
  35. if (localPath.EndsWith("/api/item", StringComparison.OrdinalIgnoreCase))
  36. {
  37. handler = new ItemHandler();
  38. }
  39. else if (localPath.EndsWith("/api/image", StringComparison.OrdinalIgnoreCase))
  40. {
  41. handler = new ImageHandler();
  42. }
  43. else if (localPath.EndsWith("/api/users", StringComparison.OrdinalIgnoreCase))
  44. {
  45. handler = new UsersHandler();
  46. }
  47. else if (localPath.EndsWith("/api/genre", StringComparison.OrdinalIgnoreCase))
  48. {
  49. handler = new GenreHandler();
  50. }
  51. else if (localPath.EndsWith("/api/genres", StringComparison.OrdinalIgnoreCase))
  52. {
  53. handler = new GenresHandler();
  54. }
  55. else if (localPath.EndsWith("/api/studio", StringComparison.OrdinalIgnoreCase))
  56. {
  57. handler = new StudioHandler();
  58. }
  59. else if (localPath.EndsWith("/api/studios", StringComparison.OrdinalIgnoreCase))
  60. {
  61. handler = new StudiosHandler();
  62. }
  63. else if (localPath.EndsWith("/api/recentlyaddeditems", StringComparison.OrdinalIgnoreCase))
  64. {
  65. handler = new RecentlyAddedItemsHandler();
  66. }
  67. else if (localPath.EndsWith("/api/inprogressitems", StringComparison.OrdinalIgnoreCase))
  68. {
  69. handler = new InProgressItemsHandler();
  70. }
  71. else if (localPath.EndsWith("/api/userconfiguration", StringComparison.OrdinalIgnoreCase))
  72. {
  73. handler = new UserConfigurationHandler();
  74. }
  75. else if (localPath.EndsWith("/api/plugins", StringComparison.OrdinalIgnoreCase))
  76. {
  77. handler = new PluginsHandler();
  78. }
  79. else if (localPath.EndsWith("/api/pluginconfiguration", StringComparison.OrdinalIgnoreCase))
  80. {
  81. handler = new PluginConfigurationHandler();
  82. }
  83. if (handler != null)
  84. {
  85. handler.RequestContext = ctx;
  86. }
  87. return handler;
  88. }
  89. }
  90. }