1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
using System;
using System.ComponentModel.Composition;
using System.Net;
using System.Reactive.Linq;
using MediaBrowser.Api.HttpHandlers;
using MediaBrowser.Common.Net.Handlers;
using MediaBrowser.Common.Plugins;
using MediaBrowser.Controller;
using MediaBrowser.Model.Plugins;
namespace MediaBrowser.Api
{
[Export(typeof(BasePlugin))]
public class Plugin : BaseGenericPlugin<BasePluginConfiguration>
{
public override string Name
{
get { return "WebAPI"; }
}
protected override void InitializeInternal()
{
var httpServer = Kernel.Instance.HttpServer;
httpServer.Where(ctx => ctx.Request.Url.LocalPath.IndexOf("/api/", StringComparison.OrdinalIgnoreCase) != -1).Subscribe((ctx) =>
{
BaseHandler handler = GetHandler(ctx);
if (handler != null)
{
handler.ProcessRequest(ctx);
}
});
}
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();
}
else if (localPath.EndsWith("/api/serverconfiguration", StringComparison.OrdinalIgnoreCase))
{
return new ServerConfigurationHandler();
}
else if (localPath.EndsWith("/api/defaultuser", StringComparison.OrdinalIgnoreCase))
{
return new DefaultUserHandler();
}
else if (localPath.EndsWith("/api/pluginassembly", StringComparison.OrdinalIgnoreCase))
{
return new PluginAssemblyHandler();
}
return null;
}
}
}
|